From a19b373d89d9839c1b3a05768370ce5abd94e03c Mon Sep 17 00:00:00 2001 From: Collin Anderson Date: Mon, 10 Apr 2017 08:59:29 -0400 Subject: [PATCH] Changed assertQuerysetEqual()s that use default Model.__str__() to assertSequenceEqual(). --- tests/many_to_one/tests.py | 2 +- tests/null_queries/tests.py | 41 +++++++++---------------------------- tests/one_to_one/tests.py | 33 +++++++---------------------- 3 files changed, 18 insertions(+), 58 deletions(-) diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py index 8252fd0e56..0382a9a45e 100644 --- a/tests/many_to_one/tests.py +++ b/tests/many_to_one/tests.py @@ -581,7 +581,7 @@ class ManyToOneTests(TestCase): private_student = Student.objects.create(school=private_school) # Only one school is available via all() due to the custom default manager. - self.assertQuerysetEqual(School.objects.all(), [""]) + self.assertSequenceEqual(School.objects.all(), [public_school]) self.assertEqual(public_student.school, public_school) diff --git a/tests/null_queries/tests.py b/tests/null_queries/tests.py index 547b586e00..221bd05946 100644 --- a/tests/null_queries/tests.py +++ b/tests/null_queries/tests.py @@ -23,19 +23,13 @@ class NullQueriesTests(TestCase): # Exact query with value None returns nothing ("is NULL" in sql, # but every 'id' field has a value). - self.assertQuerysetEqual(Choice.objects.filter(choice__exact=None), []) + self.assertSequenceEqual(Choice.objects.filter(choice__exact=None), []) # The same behavior for iexact query. - self.assertQuerysetEqual(Choice.objects.filter(choice__iexact=None), []) + self.assertSequenceEqual(Choice.objects.filter(choice__iexact=None), []) # Excluding the previous result returns everything. - self.assertQuerysetEqual( - Choice.objects.exclude(choice=None).order_by('id'), - [ - '', - '' - ] - ) + self.assertSequenceEqual(Choice.objects.exclude(choice=None).order_by('id'), [c1, c2]) # Valid query, but fails because foo isn't a keyword with self.assertRaises(FieldError): @@ -55,30 +49,15 @@ class NullQueriesTests(TestCase): insert outer joins correctly so as not to exclude results. """ obj = OuterA.objects.create() - self.assertQuerysetEqual( - OuterA.objects.filter(inner__third=None), - [''] - ) - self.assertQuerysetEqual( - OuterA.objects.filter(inner__third__data=None), - [''] - ) + self.assertSequenceEqual(OuterA.objects.filter(inner__third=None), [obj]) + self.assertSequenceEqual(OuterA.objects.filter(inner__third__data=None), [obj]) - Inner.objects.create(first=obj) - self.assertQuerysetEqual( - Inner.objects.filter(first__inner__third=None), - [''] - ) + inner = Inner.objects.create(first=obj) + self.assertSequenceEqual(Inner.objects.filter(first__inner__third=None), [inner]) # Ticket #13815: check if _isnull=False does not produce # faulty empty lists - OuterB.objects.create(data="reverse") - self.assertQuerysetEqual( - OuterB.objects.filter(inner__isnull=False), - [] - ) + outerb = OuterB.objects.create(data='reverse') + self.assertSequenceEqual(OuterB.objects.filter(inner__isnull=False), []) Inner.objects.create(first=obj) - self.assertQuerysetEqual( - OuterB.objects.exclude(inner__isnull=False), - [''] - ) + self.assertSequenceEqual(OuterB.objects.exclude(inner__isnull=False), [outerb]) diff --git a/tests/one_to_one/tests.py b/tests/one_to_one/tests.py index 2fb118538d..b0843084c2 100644 --- a/tests/one_to_one/tests.py +++ b/tests/one_to_one/tests.py @@ -254,24 +254,11 @@ class OneToOneTests(TestCase): misbehaving. We test both (primary_key=True & False) cases here to prevent any reappearance of the problem. """ - Target.objects.create() - - self.assertQuerysetEqual( - Target.objects.filter(pointer=None), - [''] - ) - self.assertQuerysetEqual( - Target.objects.exclude(pointer=None), - [] - ) - self.assertQuerysetEqual( - Target.objects.filter(second_pointer=None), - [''] - ) - self.assertQuerysetEqual( - Target.objects.exclude(second_pointer=None), - [] - ) + target = Target.objects.create() + self.assertSequenceEqual(Target.objects.filter(pointer=None), [target]) + self.assertSequenceEqual(Target.objects.exclude(pointer=None), []) + self.assertSequenceEqual(Target.objects.filter(second_pointer=None), [target]) + self.assertSequenceEqual(Target.objects.exclude(second_pointer=None), []) def test_o2o_primary_key_delete(self): t = Target.objects.create(name='name') @@ -424,16 +411,10 @@ class OneToOneTests(TestCase): private_director = Director.objects.create(school=private_school, is_temp=True) # Only one school is available via all() due to the custom default manager. - self.assertQuerysetEqual( - School.objects.all(), - [""] - ) + self.assertSequenceEqual(School.objects.all(), [public_school]) # Only one director is available via all() due to the custom default manager. - self.assertQuerysetEqual( - Director.objects.all(), - [""] - ) + self.assertSequenceEqual(Director.objects.all(), [public_director]) self.assertEqual(public_director.school, public_school) self.assertEqual(public_school.director, public_director)