diff options
author | django-bot <ops@djangoproject.com> | 2022-02-03 20:24:19 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-07 20:37:05 +0100 |
commit | 9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch) | |
tree | f0506b668a013d0063e5fba3dbf4863b466713ba /tests/null_queries | |
parent | f68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff) | |
download | django-9c19aff7c7561e3a82978a272ecdaad40dda5c00.tar.gz |
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/null_queries')
-rw-r--r-- | tests/null_queries/models.py | 1 | ||||
-rw-r--r-- | tests/null_queries/tests.py | 21 |
2 files changed, 13 insertions, 9 deletions
diff --git a/tests/null_queries/models.py b/tests/null_queries/models.py index 298d4d9277..2ed7fef2cc 100644 --- a/tests/null_queries/models.py +++ b/tests/null_queries/models.py @@ -9,6 +9,7 @@ class Choice(models.Model): poll = models.ForeignKey(Poll, models.CASCADE) choice = models.CharField(max_length=200) + # A set of models with an inner one pointing to two outer ones. diff --git a/tests/null_queries/tests.py b/tests/null_queries/tests.py index 342b43f126..f0aad73057 100644 --- a/tests/null_queries/tests.py +++ b/tests/null_queries/tests.py @@ -5,7 +5,6 @@ from .models import Choice, Inner, OuterA, OuterB, Poll class NullQueriesTests(TestCase): - def test_none_as_null(self): """ Regression test for the use of None as a query value. @@ -14,11 +13,11 @@ class NullQueriesTests(TestCase): queries. Set up some initial polls and choices """ - p1 = Poll(question='Why?') + p1 = Poll(question="Why?") p1.save() - c1 = Choice(poll=p1, choice='Because.') + c1 = Choice(poll=p1, choice="Because.") c1.save() - c2 = Choice(poll=p1, choice='Why Not?') + c2 = Choice(poll=p1, choice="Why Not?") c2.save() # Exact query with value None returns nothing ("is NULL" in sql, @@ -29,7 +28,9 @@ class NullQueriesTests(TestCase): self.assertSequenceEqual(Choice.objects.filter(choice__iexact=None), []) # Excluding the previous result returns everything. - self.assertSequenceEqual(Choice.objects.exclude(choice=None).order_by('id'), [c1, c2]) + self.assertSequenceEqual( + Choice.objects.exclude(choice=None).order_by("id"), [c1, c2] + ) # Valid query, but fails because foo isn't a keyword msg = "Cannot resolve keyword 'foo' into field. Choices are: choice, id, poll, poll_id" @@ -37,12 +38,12 @@ class NullQueriesTests(TestCase): Choice.objects.filter(foo__exact=None) # Can't use None on anything other than __exact and __iexact - with self.assertRaisesMessage(ValueError, 'Cannot use None as a query value'): + with self.assertRaisesMessage(ValueError, "Cannot use None as a query value"): Choice.objects.filter(id__gt=None) # Related managers use __exact=None implicitly if the object hasn't been saved. p2 = Poll(question="How?") - self.assertEqual(repr(p2.choice_set.all()), '<QuerySet []>') + self.assertEqual(repr(p2.choice_set.all()), "<QuerySet []>") def test_reverse_relations(self): """ @@ -54,11 +55,13 @@ class NullQueriesTests(TestCase): self.assertSequenceEqual(OuterA.objects.filter(inner__third__data=None), [obj]) inner = Inner.objects.create(first=obj) - self.assertSequenceEqual(Inner.objects.filter(first__inner__third=None), [inner]) + self.assertSequenceEqual( + Inner.objects.filter(first__inner__third=None), [inner] + ) # Ticket #13815: check if <reverse>_isnull=False does not produce # faulty empty lists - outerb = OuterB.objects.create(data='reverse') + outerb = OuterB.objects.create(data="reverse") self.assertSequenceEqual(OuterB.objects.filter(inner__isnull=False), []) Inner.objects.create(first=obj) self.assertSequenceEqual(OuterB.objects.exclude(inner__isnull=False), [outerb]) |