summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-05-11 09:57:19 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-05-11 09:57:19 +0000
commit2b0903b2c4b6f5534e88d25254c6dcf02cc9d485 (patch)
treecaf8a2a5d26420265d38d593c4bf2461a947dded /tests
parent4f9fd449658132362c8274e1fec96df5e843cf05 (diff)
Fixed #10404: ImageField height_field and width_field options no longer depend on putting the image field after the height/width fields as they did after r9766.
This bug actually exposed a related handful of inconsistancies in the underlying file handling and wraping, so a few related changes are in here as well: * Dimensions are also now calculated the moment the image is assigned to the field instead of upon save. * The base `File` object now when possible delegates its closed attribute down to the os-level file it wrapps. * In-memory files' `close()` now is a no-op. Without this certain APIs that should be able to handle in-memory files were failing. * Accessing `FieldFile.closed` used to open the file. That's silly, and it doesn't any more. * Some over-eager error handling was squishing some errors that would normally be raised. One unit test was incorrectly depending on this behavior, so the test was removed. Thanks to Armin Ronacher for much of this work. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10737 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/model_forms/models.py7
-rw-r--r--tests/regressiontests/file_storage/models.py18
2 files changed, 15 insertions, 10 deletions
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
index c5795b7e56..95fda273f0 100644
--- a/tests/modeltests/model_forms/models.py
+++ b/tests/modeltests/model_forms/models.py
@@ -112,10 +112,13 @@ try:
return '%s/%s' % (path, filename)
description = models.CharField(max_length=20)
- image = models.ImageField(storage=temp_storage, upload_to=custom_upload_path,
- width_field='width', height_field='height')
+
+ # Deliberately put the image field *after* the width/height fields to
+ # trigger the bug in #10404 with width/height not getting assigned.
width = models.IntegerField(editable=False)
height = models.IntegerField(editable=False)
+ image = models.ImageField(storage=temp_storage, upload_to=custom_upload_path,
+ width_field='width', height_field='height')
path = models.CharField(max_length=16, blank=True, default='')
def __unicode__(self):
diff --git a/tests/regressiontests/file_storage/models.py b/tests/regressiontests/file_storage/models.py
index c3dafcc287..42d16b6382 100644
--- a/tests/regressiontests/file_storage/models.py
+++ b/tests/regressiontests/file_storage/models.py
@@ -73,18 +73,20 @@ True
# Get a "clean" model instance
>>> p3 = Person.objects.get(name="Joan")
-# 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.
->>> p3.mugshot._file is not None
-False
+# It won't have an opened file.
+>>> p3.mugshot.closed
+True
# After asking for the size, the file should still be closed.
>>> _ = p3.mugshot.size
->>> p3.mugshot._file is not None
-False
+>>> p3.mugshot.closed
+True
->>> p = Person.objects.create(name="Bob", mugshot=File(p3.mugshot.file))
+# Make sure that wrapping the file in a file still works
+>>> p3.mugshot.file.open()
+>>> p = Person.objects.create(name="Bob The Builder", mugshot=File(p3.mugshot.file))
+>>> p.save()
+# Delete all test files
>>> shutil.rmtree(temp_storage_dir)
"""}