diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2016-06-16 11:19:18 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-06-16 14:21:14 -0400 |
| commit | 13d60298ea2a07242dc3952a9dfcd9c8857bf1f9 (patch) | |
| tree | 230d0f843401781e9b2062fe3c1f929655a5527e /tests/model_fields/test_imagefield.py | |
| parent | 70b7d6b4ea0cbd67406d193f0a7fed7e290d1eb6 (diff) | |
[1.10.x] Fixed #26747 -- Used more specific assertions in the Django test suite.
Backport of 4f336f66523001b009ab038b10848508fd208b3b from master
Diffstat (limited to 'tests/model_fields/test_imagefield.py')
| -rw-r--r-- | tests/model_fields/test_imagefield.py | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/tests/model_fields/test_imagefield.py b/tests/model_fields/test_imagefield.py index 74926a5363..f9ae83b8b2 100644 --- a/tests/model_fields/test_imagefield.py +++ b/tests/model_fields/test_imagefield.py @@ -120,18 +120,18 @@ class ImageFieldTests(ImageFieldTestMixin, TestCase): p1.mugshot.save("mug", self.file1) p2 = self.PersonModel(name="Bob") p2.mugshot.save("mug", self.file2) - self.assertEqual(p1.mugshot == p2.mugshot, False) - self.assertEqual(p1.mugshot != p2.mugshot, True) + self.assertIs(p1.mugshot == p2.mugshot, False) + self.assertIs(p1.mugshot != p2.mugshot, True) # Test again with an instance fetched from the db. p1_db = self.PersonModel.objects.get(name="Joe") - self.assertEqual(p1_db.mugshot == p2.mugshot, False) - self.assertEqual(p1_db.mugshot != p2.mugshot, True) + self.assertIs(p1_db.mugshot == p2.mugshot, False) + self.assertIs(p1_db.mugshot != p2.mugshot, True) # Instance from db should match the local instance. - self.assertEqual(p1_db.mugshot == p1.mugshot, True) + self.assertIs(p1_db.mugshot == p1.mugshot, True) self.assertEqual(hash(p1_db.mugshot), hash(p1.mugshot)) - self.assertEqual(p1_db.mugshot != p1.mugshot, False) + self.assertIs(p1_db.mugshot != p1.mugshot, False) def test_instantiate_missing(self): """ @@ -165,11 +165,11 @@ class ImageFieldTests(ImageFieldTestMixin, TestCase): # Get a "clean" model instance p = self.PersonModel.objects.get(name="Joan") # It won't have an opened file. - self.assertEqual(p.mugshot.closed, True) + self.assertIs(p.mugshot.closed, True) # After asking for the size, the file should still be closed. p.mugshot.size - self.assertEqual(p.mugshot.closed, True) + self.assertIs(p.mugshot.closed, True) def test_pickle(self): """ @@ -213,7 +213,7 @@ class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase): # attr_class, a TestImageFieldFile, with name == None, which will # cause it to evaluate as False. self.assertIsInstance(p.mugshot, TestImageFieldFile) - self.assertEqual(bool(p.mugshot), False) + self.assertFalse(p.mugshot) # Test setting a fresh created model instance. p = self.PersonModel(name='Joe') @@ -235,7 +235,7 @@ class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase): """ p = self.PersonModel() self.assertIsInstance(p.mugshot, TestImageFieldFile) - self.assertEqual(bool(p.mugshot), False) + self.assertFalse(p.mugshot) def test_assignment_to_None(self): """ @@ -284,23 +284,23 @@ class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase): # Bug 11084: Dimensions should not get recalculated if file is # coming from the database. We test this by checking if the file # was opened. - self.assertEqual(p.mugshot.was_opened, False) + self.assertIs(p.mugshot.was_opened, False) self.check_dimensions(p, 4, 8) # After checking dimensions on the image field, the file will have # opened. - self.assertEqual(p.mugshot.was_opened, True) + self.assertIs(p.mugshot.was_opened, True) # Dimensions should now be cached, and if we reset was_opened and # check dimensions again, the file should not have opened. p.mugshot.was_opened = False self.check_dimensions(p, 4, 8) - self.assertEqual(p.mugshot.was_opened, False) + self.assertIs(p.mugshot.was_opened, False) # If we assign a new image to the instance, the dimensions should # update. p.mugshot = self.file2 self.check_dimensions(p, 8, 4) # Dimensions were recalculated, and hence file should have opened. - self.assertEqual(p.mugshot.was_opened, True) + self.assertIs(p.mugshot.was_opened, True) @skipIf(Image is None, "Pillow is required to test ImageField") @@ -419,22 +419,22 @@ class TwoImageFieldTests(ImageFieldTestMixin, TestCase): # Bug 11084: Dimensions should not get recalculated if file is # coming from the database. We test this by checking if the file # was opened. - self.assertEqual(p.mugshot.was_opened, False) - self.assertEqual(p.headshot.was_opened, False) + self.assertIs(p.mugshot.was_opened, False) + self.assertIs(p.headshot.was_opened, False) self.check_dimensions(p, 4, 8, 'mugshot') self.check_dimensions(p, 8, 4, 'headshot') # After checking dimensions on the image fields, the files will # have been opened. - self.assertEqual(p.mugshot.was_opened, True) - self.assertEqual(p.headshot.was_opened, True) + self.assertIs(p.mugshot.was_opened, True) + self.assertIs(p.headshot.was_opened, True) # Dimensions should now be cached, and if we reset was_opened and # check dimensions again, the file should not have opened. p.mugshot.was_opened = False p.headshot.was_opened = False self.check_dimensions(p, 4, 8, 'mugshot') self.check_dimensions(p, 8, 4, 'headshot') - self.assertEqual(p.mugshot.was_opened, False) - self.assertEqual(p.headshot.was_opened, False) + self.assertIs(p.mugshot.was_opened, False) + self.assertIs(p.headshot.was_opened, False) # If we assign a new image to the instance, the dimensions should # update. @@ -443,5 +443,5 @@ class TwoImageFieldTests(ImageFieldTestMixin, TestCase): self.check_dimensions(p, 8, 4, 'mugshot') self.check_dimensions(p, 4, 8, 'headshot') # Dimensions were recalculated, and hence file should have opened. - self.assertEqual(p.mugshot.was_opened, True) - self.assertEqual(p.headshot.was_opened, True) + self.assertIs(p.mugshot.was_opened, True) + self.assertIs(p.headshot.was_opened, True) |
