Fixed #25508 -- Modified QuerySet.__repr__() to disambiguate it from a list.

This commit is contained in:
Tim Graham 2015-10-05 19:07:34 -04:00
parent 3543fec3b7
commit e0837f2cb1
20 changed files with 185 additions and 184 deletions

View file

@ -800,11 +800,12 @@ class NaturalKeyFixtureTests(TestCase):
verbosity=0,
)
books = Book.objects.all()
self.assertEqual(
books.__repr__(),
"[<Book: Cryptonomicon by Neal Stephenson (available at Amazon, Borders)>, "
"<Book: Ender's Game by Orson Scott Card (available at Collins Bookstore)>, "
"<Book: Permutation City by Greg Egan (available at Angus and Robertson)>]"
self.assertQuerysetEqual(
books, [
"<Book: Cryptonomicon by Neal Stephenson (available at Amazon, Borders)>",
"<Book: Ender's Game by Orson Scott Card (available at Collins Bookstore)>",
"<Book: Permutation City by Greg Egan (available at Angus and Robertson)>",
]
)

View file

@ -47,7 +47,7 @@ class NullQueriesTests(TestCase):
# Related managers use __exact=None implicitly if the object hasn't been saved.
p2 = Poll(question="How?")
self.assertEqual(repr(p2.choice_set.all()), '[]')
self.assertEqual(repr(p2.choice_set.all()), '<QuerySet []>')
def test_reverse_relations(self):
"""

View file

@ -78,7 +78,9 @@ class StringLookupTests(TestCase):
"""
a = Article(name='IP test', text='The body', submitted_from='192.0.2.100')
a.save()
self.assertEqual(repr(Article.objects.filter(submitted_from__contains='192.0.2')),
repr([a]))
self.assertQuerysetEqual(
Article.objects.filter(submitted_from__contains='192.0.2'),
[a], lambda x: x
)
# Test that the searches do not match the subnet mask (/32 in this case)
self.assertEqual(Article.objects.filter(submitted_from__contains='32').count(), 0)