diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2008-10-10 22:13:16 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2008-10-10 22:13:16 +0000 |
| commit | d7c829c98ebb709a7c7bc263c6c195d8155ee7fb (patch) | |
| tree | 95fd741b792c7aced5ea37feca6c7fb5f3e22f6e /tests | |
| parent | b21ea0a8363203087e5bcb3004735db0d4143490 (diff) | |
Yet more file storage testing cleanup for the sake of buildbots; this should be the last of it, I hope.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9226 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/model_forms/models.py | 7 | ||||
| -rw-r--r-- | tests/regressiontests/file_storage/models.py | 6 | ||||
| -rw-r--r-- | tests/regressiontests/file_storage/tests.py | 35 |
3 files changed, 34 insertions, 14 deletions
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index e3821de758..0b99a84cda 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -19,7 +19,8 @@ try: except NameError: from django.utils.itercompat import sorted -temp_storage = FileSystemStorage(tempfile.gettempdir()) +temp_storage_dir = tempfile.mkdtemp() +temp_storage = FileSystemStorage(temp_storage_dir) ARTICLE_STATUS = ( (1, 'Draft'), @@ -1251,4 +1252,8 @@ ValidationError: [u'Select a valid choice. z is not one of the available choices >>> core = form.save() >>> core.parent <Inventory: Pear> + +# Clean up +>>> import shutil +>>> shutil.rmtree(temp_storage_dir) """} diff --git a/tests/regressiontests/file_storage/models.py b/tests/regressiontests/file_storage/models.py index 6a62c5252a..2575a15d3a 100644 --- a/tests/regressiontests/file_storage/models.py +++ b/tests/regressiontests/file_storage/models.py @@ -1,10 +1,12 @@ import os import tempfile +import shutil from django.db import models from django.core.files.storage import FileSystemStorage from django.core.files.base import ContentFile -temp_storage = FileSystemStorage(tempfile.gettempdir()) +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. @@ -64,5 +66,7 @@ False >>> _ = p3.mugshot.size >>> hasattr(p3.mugshot, '_file') False + +>>> shutil.rmtree(temp_storage_dir) """}
\ No newline at end of file diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py index 181c551c24..6b219f064e 100644 --- a/tests/regressiontests/file_storage/tests.py +++ b/tests/regressiontests/file_storage/tests.py @@ -88,10 +88,12 @@ u'custom_storage.2' # without threading. import os import time +import shutil +import tempfile from unittest import TestCase from django.conf import settings from django.core.files.base import ContentFile -from models import temp_storage +from django.core.files.storage import FileSystemStorage try: import threading except ImportError: @@ -104,29 +106,38 @@ class SlowFile(ContentFile): class FileSaveRaceConditionTest(TestCase): def setUp(self): + self.storage_dir = tempfile.mkdtemp() + self.storage = FileSystemStorage(self.storage_dir) self.thread = threading.Thread(target=self.save_file, args=['conflict']) + def tearDown(self): + shutil.rmtree(self.storage_dir) + def save_file(self, name): - name = temp_storage.save(name, SlowFile("Data")) + name = self.storage.save(name, SlowFile("Data")) def test_race_condition(self): self.thread.start() name = self.save_file('conflict') self.thread.join() - self.assert_(temp_storage.exists('conflict')) - self.assert_(temp_storage.exists('conflict_')) - temp_storage.delete('conflict') - temp_storage.delete('conflict_') + self.assert_(self.storage.exists('conflict')) + self.assert_(self.storage.exists('conflict_')) + self.storage.delete('conflict') + self.storage.delete('conflict_') class FileStoragePermissions(TestCase): def setUp(self): self.old_perms = settings.FILE_UPLOAD_PERMISSIONS settings.FILE_UPLOAD_PERMISSIONS = 0666 - + self.storage_dir = tempfile.mkdtemp() + self.storage = FileSystemStorage(self.storage_dir) + + def tearDown(self): + settings.FILE_UPLOAD_PERMISSIONS = self.old_perms + shutil.rmtree(self.storage_dir) + def test_file_upload_permissions(self): - name = temp_storage.save("the_file", ContentFile("data")) - actual_mode = os.stat(temp_storage.path(name))[0] & 0777 + name = self.storage.save("the_file", ContentFile("data")) + actual_mode = os.stat(self.storage.path(name))[0] & 0777 self.assertEqual(actual_mode, 0666) - - def tearDown(self): - settings.FILE_UPLOAD_PERMISSIONS = self.old_perms
\ No newline at end of file + |
