From b96b4509811d097a1217c065141f36be27f79823 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Tue, 16 Dec 2008 04:52:55 +0000 Subject: [PATCH] Fixed #9786 -- Fixed inequality checking for django.db.models.fields.file.FieldFile class. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9647 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/fields/files.py | 3 +++ tests/regressiontests/file_storage/models.py | 20 +++++++++++++++---- tests/regressiontests/file_storage/test1.png | Bin 0 -> 480 bytes 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 tests/regressiontests/file_storage/test1.png diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index fc845c5ba1..40b4e98026 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -29,6 +29,9 @@ class FieldFile(File): return self.name == other.name return self.name == other + def __ne__(self, other): + return not self.__eq__(other) + # The standard File contains most of the necessary properties, but # FieldFiles can be instantiated without a name, so that needs to # be checked for here. diff --git a/tests/regressiontests/file_storage/models.py b/tests/regressiontests/file_storage/models.py index 2575a15d3a..32fb83b348 100644 --- a/tests/regressiontests/file_storage/models.py +++ b/tests/regressiontests/file_storage/models.py @@ -22,12 +22,12 @@ except ImportError: if Image: class Person(models.Model): name = models.CharField(max_length=50) - mugshot = models.ImageField(storage=temp_storage, upload_to='tests', - height_field='mug_height', + mugshot = models.ImageField(storage=temp_storage, upload_to='tests', + height_field='mug_height', width_field='mug_width') mug_height = models.PositiveSmallIntegerField() mug_width = models.PositiveSmallIntegerField() - + __test__ = {'API_TESTS': """ >>> image_data = open(os.path.join(os.path.dirname(__file__), "test.png"), 'rb').read() @@ -42,6 +42,18 @@ if Image: >>> p.mug_width 16 +# Bug #9786: Ensure '==' and '!=' work correctly. +>>> image_data = open(os.path.join(os.path.dirname(__file__), "test1.png"), 'rb').read() +>>> p1 = Person(name="Bob") +>>> p1.mugshot.save("mug", ContentFile(image_data)) +>>> p2 = Person.objects.get(name="Joe") +>>> p.mugshot == p2.mugshot +True +>>> p.mugshot != p2.mugshot +False +>>> p.mugshot != p1.mugshot +True + # Bug #8175: correctly delete files that have been removed off the file system. >>> import os >>> p2 = Person(name="Fred") @@ -69,4 +81,4 @@ False >>> shutil.rmtree(temp_storage_dir) """} - \ No newline at end of file + diff --git a/tests/regressiontests/file_storage/test1.png b/tests/regressiontests/file_storage/test1.png new file mode 100644 index 0000000000000000000000000000000000000000..bc9874113d4820349320eef07d7ad71676af44f5 GIT binary patch literal 480 zcmV<60U!Q}P)Px$nn^@KR4C75Y)B~ev2ti-Cb5-XlEIFM)x9VcDLwfB*er zU|?YQ5A_#%D82dkj)8$eNm3qvR3J2n3yLx@FdV;n8a=pRW}`bP%+arP@q{hMcVE1F zO@N2**Pq`E3=BVh{rva;KLY~;GZQnqhCmx{W+vw4d)ME4_VDqmr=08@vSLz?UOi!8 zVBqHDVr5~)5)Xb>9)4CH|NsC0`|mFcGt0mK|Ep%VFfcF}s_5d2I7UWB7G{>e|Nhp_ z@7Qzp5ECO)v`a8T7FXhfq^PYYcFT*)7^&*P1(~HpB-CV;v1(vuV%C&Xl@u07jw=Al WO`jhQQlBIM0000