diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2008-08-08 20:59:02 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2008-08-08 20:59:02 +0000 |
| commit | 7899568e01fc9c68afe995fa71de915dd9fcdd76 (patch) | |
| tree | 35f1e999a9a48fe24790f00c2335e558a53fc718 /tests/regressiontests/file_uploads | |
| parent | c49eac7d4f64c374d19aa81f2c813a4b20e4cad7 (diff) | |
File storage refactoring, adding far more flexibility to Django's file handling. The new files.txt document has details of the new features.
This is a backwards-incompatible change; consult BackwardsIncompatibleChanges for details.
Fixes #3567, #3621, #4345, #5361, #5655, #7415.
Many thanks to Marty Alchin who did the vast majority of this work.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8244 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/file_uploads')
| -rw-r--r-- | tests/regressiontests/file_uploads/models.py | 7 | ||||
| -rw-r--r-- | tests/regressiontests/file_uploads/tests.py | 22 |
2 files changed, 15 insertions, 14 deletions
diff --git a/tests/regressiontests/file_uploads/models.py b/tests/regressiontests/file_uploads/models.py index 3701750afe..9d020509af 100644 --- a/tests/regressiontests/file_uploads/models.py +++ b/tests/regressiontests/file_uploads/models.py @@ -1,9 +1,10 @@ import tempfile import os from django.db import models +from django.core.files.storage import FileSystemStorage -UPLOAD_ROOT = tempfile.mkdtemp() -UPLOAD_TO = os.path.join(UPLOAD_ROOT, 'test_upload') +temp_storage = FileSystemStorage(tempfile.mkdtemp()) +UPLOAD_TO = os.path.join(temp_storage.location, 'test_upload') class FileModel(models.Model): - testfile = models.FileField(upload_to=UPLOAD_TO) + testfile = models.FileField(storage=temp_storage, upload_to='test_upload') diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py index dd6b7c4181..7c8b53ea89 100644 --- a/tests/regressiontests/file_uploads/tests.py +++ b/tests/regressiontests/file_uploads/tests.py @@ -9,7 +9,7 @@ from django.test import TestCase, client from django.utils import simplejson from django.utils.hashcompat import sha_constructor -from models import FileModel, UPLOAD_ROOT, UPLOAD_TO +from models import FileModel, temp_storage, UPLOAD_TO class FileUploadTests(TestCase): def test_simple_upload(self): @@ -194,22 +194,22 @@ class DirectoryCreationTests(unittest.TestCase): """ def setUp(self): self.obj = FileModel() - if not os.path.isdir(UPLOAD_ROOT): - os.makedirs(UPLOAD_ROOT) + if not os.path.isdir(temp_storage.location): + os.makedirs(temp_storage.location) def tearDown(self): - os.chmod(UPLOAD_ROOT, 0700) - shutil.rmtree(UPLOAD_ROOT) + os.chmod(temp_storage.location, 0700) + shutil.rmtree(temp_storage.location) def test_readonly_root(self): """Permission errors are not swallowed""" - os.chmod(UPLOAD_ROOT, 0500) + os.chmod(temp_storage.location, 0500) try: - self.obj.save_testfile_file('foo.txt', SimpleUploadedFile('foo.txt', 'x')) + self.obj.testfile.save('foo.txt', SimpleUploadedFile('foo.txt', 'x')) except OSError, err: self.assertEquals(err.errno, errno.EACCES) - except: - self.fail("OSError [Errno %s] not raised" % errno.EACCES) + except Exception, err: + self.fail("OSError [Errno %s] not raised." % errno.EACCES) def test_not_a_directory(self): """The correct IOError is raised when the upload directory name exists but isn't a directory""" @@ -217,11 +217,11 @@ class DirectoryCreationTests(unittest.TestCase): fd = open(UPLOAD_TO, 'w') fd.close() try: - self.obj.save_testfile_file('foo.txt', SimpleUploadedFile('foo.txt', 'x')) + self.obj.testfile.save('foo.txt', SimpleUploadedFile('foo.txt', 'x')) except IOError, err: # The test needs to be done on a specific string as IOError # is raised even without the patch (just not early enough) self.assertEquals(err.args[0], - "%s exists and is not a directory" % UPLOAD_TO) + "%s exists and is not a directory." % UPLOAD_TO) except: self.fail("IOError not raised") |
