Author: kmtracey
Date: 2009-04-05 16:45:07 -0500 (Sun, 05 Apr 2009)
New Revision: 10407
Modified:
django/branches/releases/1.0.X/
django/branches/releases/1.0.X/tests/regressiontests/bug639/models.py
django/branches/releases/1.0.X/tests/regressiontests/bug639/tests.py
django/branches/releases/1.0.X/tests/regressiontests/file_storage/models.py
django/branches/releases/1.0.X/tests/regressiontests/file_uploads/tests.py
Log:
[1.0.X] Made a set of small test changes to avoid leaving temp files hanging
around after running the test suite. First, fixed a couple of places where temp
dirs were (or could be) created without later being deleted. Second, added a
missing close() before unlink() since Windows raises an error on an attempt to
remove an open file. Finally, in the file_uploads tests, avoided
opening-by-name temporary files that we already have a descriptor for. Doing
additional opens seems to run afoul of the Windows issue with deleting open
files, so it generally works better to just seek back to 0 instead of calling
open multiple times.
Backport/merge of r10406. Also updated svnmerge metadata.
Property changes on: django/branches/releases/1.0.X
___________________________________________________________________
Name: svnmerge-integrated
-
/django/trunk:1-9097,9099-9102,9104-9109,9111,9113-9144,9146-9151,9153-9156,9158-9159,9161-9187,9189-9247,9249-9262,9264-9277,9279-9298,9301-9302,9305-9331,9333-9343,9345,9347,9350-9352,9355-9396,9399-9462,9466-9469,9471-9488,9491-9526,9529,9533-9536,9539-9550,9556-9557,9559-9560,9562-9568,9570-9591,9595-9619,9621-9624,9626-9636,9638-9642,9644-9645,9647-9689,9691-9699,9703-9706,9709-9713,9716-9723,9725-9726,9730-9738,9740-9741,9750-9751,9757-9758,9761-9762,9767-9768,9770-9780,9782-9784,9789-9790,9793-9798,9801-9802,9806-9807,9809-9813,9821-9837,9842-9843,9847-9859,9861,9863-9875,9877-9881,9883-9887,9899-9903,9906-9909,9912,9914,9916-9917,9919-9920,9922-9927,9929,9931-9937,9939,9942-9943,9945-9950,9953-9954,9956-9962,9966-9977,9979-9984,9986-9988,9990-10001,10003-10004,10007,10009-10010,10013-10017,10019-10020,10022-10025,10031,10036-10041,10049-10052,10054-10061,10066-10069,10071-10076,10078-10079,10085-10087,10104,10106,10125-10127,10136,10138-10140,10143,10145-10147,10149-10160,10163-10167,10170,10173,10175-10176,10180,10185,10189,10192-10196,10198-10221,10223-10228,10230-10234,10236-10247,10250-10257,10259-10270,10273-10274,10276-10280,10282-10314,10316,10319-10322,10325,10328-10329,10333-10344,10348-10351,10354-10356,10358-10363,10365-10368,10371-10380,10386-10396
+
/django/trunk:1-9097,9099-9102,9104-9109,9111,9113-9144,9146-9151,9153-9156,9158-9159,9161-9187,9189-9247,9249-9262,9264-9277,9279-9298,9301-9302,9305-9331,9333-9343,9345,9347,9350-9352,9355-9396,9399-9462,9466-9469,9471-9488,9491-9526,9529,9533-9536,9539-9550,9556-9557,9559-9560,9562-9568,9570-9591,9595-9619,9621-9624,9626-9636,9638-9642,9644-9645,9647-9689,9691-9699,9703-9706,9709-9713,9716-9723,9725-9726,9730-9738,9740-9741,9750-9751,9757-9758,9761-9762,9767-9768,9770-9780,9782-9784,9789-9790,9793-9798,9801-9802,9806-9807,9809-9813,9821-9837,9842-9843,9847-9859,9861,9863-9875,9877-9881,9883-9887,9899-9903,9906-9909,9912,9914,9916-9917,9919-9920,9922-9927,9929,9931-9937,9939,9942-9943,9945-9950,9953-9954,9956-9962,9966-9977,9979-9984,9986-9988,9990-10001,10003-10004,10007,10009-10010,10013-10017,10019-10020,10022-10025,10031,10036-10041,10049-10052,10054-10061,10066-10069,10071-10076,10078-10079,10085-10087,10104,10106,10125-10127,10136,10138-10140,10143,10145-10147,10149-10160,10163-10167,10170,10173,10175-10176,10180,10185,10189,10192-10196,10198-10221,10223-10228,10230-10234,10236-10247,10250-10257,10259-10270,10273-10274,10276-10280,10282-10314,10316,10319-10322,10325,10328-10329,10333-10344,10348-10351,10354-10356,10358-10363,10365-10368,10371-10380,10386-10406
Modified: django/branches/releases/1.0.X/tests/regressiontests/bug639/models.py
===================================================================
--- django/branches/releases/1.0.X/tests/regressiontests/bug639/models.py
2009-04-05 20:59:20 UTC (rev 10406)
+++ django/branches/releases/1.0.X/tests/regressiontests/bug639/models.py
2009-04-05 21:45:07 UTC (rev 10407)
@@ -4,7 +4,8 @@
from django.core.files.storage import FileSystemStorage
from django.forms import ModelForm
-temp_storage = FileSystemStorage(tempfile.gettempdir())
+temp_storage_dir = tempfile.mkdtemp()
+temp_storage = FileSystemStorage(temp_storage_dir)
class Photo(models.Model):
title = models.CharField(max_length=30)
Modified: django/branches/releases/1.0.X/tests/regressiontests/bug639/tests.py
===================================================================
--- django/branches/releases/1.0.X/tests/regressiontests/bug639/tests.py
2009-04-05 20:59:20 UTC (rev 10406)
+++ django/branches/releases/1.0.X/tests/regressiontests/bug639/tests.py
2009-04-05 21:45:07 UTC (rev 10407)
@@ -5,10 +5,11 @@
"""
import os
+import shutil
import unittest
from django.core.files.uploadedfile import SimpleUploadedFile
-from regressiontests.bug639.models import Photo, PhotoForm
+from regressiontests.bug639.models import Photo, PhotoForm, temp_storage_dir
class Bug639Test(unittest.TestCase):
@@ -37,3 +38,4 @@
"""
p = Photo.objects.get()
p.image.delete(save=False)
+ shutil.rmtree(temp_storage_dir)
Modified:
django/branches/releases/1.0.X/tests/regressiontests/file_storage/models.py
===================================================================
--- django/branches/releases/1.0.X/tests/regressiontests/file_storage/models.py
2009-04-05 20:59:20 UTC (rev 10406)
+++ django/branches/releases/1.0.X/tests/regressiontests/file_storage/models.py
2009-04-05 21:45:07 UTC (rev 10407)
@@ -5,9 +5,6 @@
from django.core.files.storage import FileSystemStorage
from django.core.files.base import ContentFile
-temp_storage_dir = tempfile.mkdtemp()
-temp_storage = FileSystemStorage(temp_storage_dir)
-
# Test for correct behavior of width_field/height_field.
# Of course, we can't run this without PIL.
@@ -20,6 +17,9 @@
# If we have PIL, do these tests
if Image:
+ temp_storage_dir = tempfile.mkdtemp()
+ temp_storage = FileSystemStorage(temp_storage_dir)
+
class Person(models.Model):
name = models.CharField(max_length=50)
mugshot = models.ImageField(storage=temp_storage, upload_to='tests',
Modified:
django/branches/releases/1.0.X/tests/regressiontests/file_uploads/tests.py
===================================================================
--- django/branches/releases/1.0.X/tests/regressiontests/file_uploads/tests.py
2009-04-05 20:59:20 UTC (rev 10406)
+++ django/branches/releases/1.0.X/tests/regressiontests/file_uploads/tests.py
2009-04-05 21:45:07 UTC (rev 10407)
@@ -37,8 +37,8 @@
post_data = {
'name': 'Ringo',
- 'file_field1': open(file1.name),
- 'file_field2': open(file2.name),
+ 'file_field1': file1,
+ 'file_field2': file2,
}
for key in post_data.keys():
@@ -66,6 +66,7 @@
response = self.client.post('/file_uploads/unicode_name/', post_data)
+ file1.close()
try:
os.unlink(file1.name)
except:
@@ -150,51 +151,57 @@
# A small file (under the 5M quota)
smallfile = tempfile.NamedTemporaryFile()
smallfile.write('a' * (2 ** 21))
+ smallfile.seek(0)
# A big file (over the quota)
bigfile = tempfile.NamedTemporaryFile()
bigfile.write('a' * (10 * 2 ** 20))
+ bigfile.seek(0)
# Small file posting should work.
- response = self.client.post('/file_uploads/quota/', {'f':
open(smallfile.name)})
+ response = self.client.post('/file_uploads/quota/', {'f': smallfile})
got = simplejson.loads(response.content)
self.assert_('f' in got)
# Large files don't go through.
- response = self.client.post("/file_uploads/quota/", {'f':
open(bigfile.name)})
+ response = self.client.post("/file_uploads/quota/", {'f': bigfile})
got = simplejson.loads(response.content)
self.assert_('f' not in got)
def test_broken_custom_upload_handler(self):
f = tempfile.NamedTemporaryFile()
f.write('a' * (2 ** 21))
+ f.seek(0)
# AttributeError: You cannot alter upload handlers after the upload
has been processed.
self.assertRaises(
AttributeError,
self.client.post,
'/file_uploads/quota/broken/',
- {'f': open(f.name)}
+ {'f': f}
)
def test_fileupload_getlist(self):
file1 = tempfile.NamedTemporaryFile()
file1.write('a' * (2 ** 23))
+ file1.seek(0)
file2 = tempfile.NamedTemporaryFile()
file2.write('a' * (2 * 2 ** 18))
+ file2.seek(0)
file2a = tempfile.NamedTemporaryFile()
file2a.write('a' * (5 * 2 ** 20))
+ file2a.seek(0)
response = self.client.post('/file_uploads/getlist_count/', {
- 'file1': open(file1.name),
+ 'file1': file1,
'field1': u'test',
'field2': u'test3',
'field3': u'test5',
'field4': u'test6',
'field5': u'test7',
- 'file2': (open(file2.name), open(file2a.name))
+ 'file2': (file2, file2a)
})
got = simplejson.loads(response.content)
@@ -242,6 +249,13 @@
# CustomUploadError is the error that should have been raised
self.assertEqual(err.__class__, uploadhandler.CustomUploadError)
+ def setUp(self):
+ if not os.path.isdir(temp_storage.location):
+ os.makedirs(temp_storage.location)
+
+ def tearDown(self):
+ shutil.rmtree(temp_storage.location)
+
class DirectoryCreationTests(unittest.TestCase):
"""
Tests for error handling during directory creation
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---