summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-05-08 15:08:09 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-05-08 15:08:09 +0000
commit68a890e79f660484d05482902663b6168f0bd71e (patch)
tree201e3380e461d0d7bdcfeb42a0994b703fca349e /tests
parent2af75b485db15a8494b040aa04337c052b896cca (diff)
Fixed #7712, #9404, #10249, #10300: a light refactor and cleanup of file storage and the `File` object. Thanks to Armin Ronacher and Alex Gaynor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10717 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/files/models.py2
-rw-r--r--tests/regressiontests/file_storage/models.py9
2 files changed, 6 insertions, 5 deletions
diff --git a/tests/modeltests/files/models.py b/tests/modeltests/files/models.py
index 30bbdf2841..beea97e808 100644
--- a/tests/modeltests/files/models.py
+++ b/tests/modeltests/files/models.py
@@ -6,6 +6,7 @@ and where files should be stored.
"""
import shutil
+import random
import tempfile
from django.db import models
from django.core.files.base import ContentFile
@@ -26,7 +27,6 @@ class Storage(models.Model):
def random_upload_to(self, filename):
# This returns a different result each time,
# to make sure it only gets called once.
- import random
return '%s/%s' % (random.randint(100, 999), filename)
normal = models.FileField(storage=temp_storage, upload_to='tests')
diff --git a/tests/regressiontests/file_storage/models.py b/tests/regressiontests/file_storage/models.py
index 94acc8e534..c3dafcc287 100644
--- a/tests/regressiontests/file_storage/models.py
+++ b/tests/regressiontests/file_storage/models.py
@@ -29,7 +29,7 @@ if Image:
mug_width = models.PositiveSmallIntegerField()
__test__ = {'API_TESTS': """
-
+>>> from django.core.files import File
>>> image_data = open(os.path.join(os.path.dirname(__file__), "test.png"), 'rb').read()
>>> p = Person(name="Joe")
>>> p.mugshot.save("mug", ContentFile(image_data))
@@ -76,14 +76,15 @@ True
# It won't have an opened file. This is a bit brittle since it depends on the
# the internals of FieldFile, but there's no other way of telling if the
# file's been opened or not.
->>> hasattr(p3.mugshot, '_file')
+>>> p3.mugshot._file is not None
False
# After asking for the size, the file should still be closed.
>>> _ = p3.mugshot.size
->>> hasattr(p3.mugshot, '_file')
+>>> p3.mugshot._file is not None
False
+>>> p = Person.objects.create(name="Bob", mugshot=File(p3.mugshot.file))
+
>>> shutil.rmtree(temp_storage_dir)
"""}
-