mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Changed assertQuerysetEqual()s that use default Model.__str__() to assertSequenceEqual().
This commit is contained in:
parent
eb9a3bd63a
commit
a19b373d89
@ -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(), ["<School: School object>"])
|
||||
self.assertSequenceEqual(School.objects.all(), [public_school])
|
||||
|
||||
self.assertEqual(public_student.school, public_school)
|
||||
|
||||
|
@ -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'),
|
||||
[
|
||||
'<Choice: Choice: Because. in poll Q: Why? >',
|
||||
'<Choice: Choice: Why Not? in poll Q: Why? >'
|
||||
]
|
||||
)
|
||||
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),
|
||||
['<OuterA: OuterA object>']
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
OuterA.objects.filter(inner__third__data=None),
|
||||
['<OuterA: OuterA object>']
|
||||
)
|
||||
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 object>']
|
||||
)
|
||||
inner = Inner.objects.create(first=obj)
|
||||
self.assertSequenceEqual(Inner.objects.filter(first__inner__third=None), [inner])
|
||||
|
||||
# Ticket #13815: check if <reverse>_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),
|
||||
['<OuterB: OuterB object>']
|
||||
)
|
||||
self.assertSequenceEqual(OuterB.objects.exclude(inner__isnull=False), [outerb])
|
||||
|
@ -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),
|
||||
['<Target: Target object>']
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Target.objects.exclude(pointer=None),
|
||||
[]
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Target.objects.filter(second_pointer=None),
|
||||
['<Target: Target object>']
|
||||
)
|
||||
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(),
|
||||
["<School: School object>"]
|
||||
)
|
||||
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(),
|
||||
["<Director: Director object>"]
|
||||
)
|
||||
self.assertSequenceEqual(Director.objects.all(), [public_director])
|
||||
|
||||
self.assertEqual(public_director.school, public_school)
|
||||
self.assertEqual(public_school.director, public_director)
|
||||
|
Loading…
Reference in New Issue
Block a user