Skip to content

Commit 0b29263

Browse files
committed
update tests to support ordering and have a default for self.title
1 parent 0161dfb commit 0b29263

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

tests/lookup_/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ class Book(models.Model):
55
title = models.CharField(max_length=10, default=None)
66
isbn = models.CharField(max_length=13, default=None)
77

8+
class Meta:
9+
ordering = ("title",)
10+
811
def __str__(self):
9-
return self.title
12+
return self.title or "Title Not Found"
1013

1114

1215
class Number(models.Model):

tests/lookup_/tests.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,31 +85,33 @@ def setUpTestData(cls):
8585

8686
def test_none_filter_nullable_json_exact(self):
8787
with self.assertNumQueries(1) as ctx:
88-
self.assertQuerySetEqual(
89-
NullableJSONModel.objects.filter(value=None),
90-
self.null_objs[:-1],
91-
)
88+
list(NullableJSONModel.objects.filter(value=None))
9289
self.assertAggregateQuery(
9390
ctx.captured_queries[0]["sql"],
9491
"lookup__nullablejsonmodel",
9592
[{"$match": {"$and": [{"value": {"$exists": True}}, {"value": None}]}}],
9693
)
94+
self.assertQuerySetEqual(
95+
NullableJSONModel.objects.filter(value=None),
96+
self.null_objs[:-1],
97+
)
9798

9899
def test_none_filter_nullable_json_in(self):
99100
with self.assertNumQueries(1) as ctx:
100-
self.assertQuerySetEqual(
101-
NullableJSONModel.objects.filter(value__in=[None]),
102-
self.null_objs[:-1],
103-
)
101+
list(NullableJSONModel.objects.filter(value__in=[None]))
104102
self.assertAggregateQuery(
105103
ctx.captured_queries[0]["sql"],
106104
"lookup__nullablejsonmodel",
107105
[{"$match": {"$and": [{"value": {"$exists": True}}, {"value": {"$in": [None]}}]}}],
108106
)
107+
self.assertQuerySetEqual(
108+
NullableJSONModel.objects.filter(value__in=[None]),
109+
self.null_objs[:-1],
110+
)
109111

110112
def test_none_filter_binary_operator_exact(self):
111113
with self.assertNumQueries(1) as ctx:
112-
self.assertQuerySetEqual(Book.objects.filter(title=None), [])
114+
list(Book.objects.filter(title=None))
113115
self.assertAggregateQuery(
114116
ctx.captured_queries[0]["sql"],
115117
"lookup__book",
@@ -124,10 +126,11 @@ def test_none_filter_binary_operator_exact(self):
124126
}
125127
],
126128
)
129+
self.assertQuerySetEqual(Book.objects.filter(title=None), [])
127130

128131
def test_none_filter_binary_operator_in(self):
129132
with self.assertNumQueries(1) as ctx:
130-
self.assertQuerySetEqual(Book.objects.filter(title__in=[None]), [])
133+
list(Book.objects.filter(title__in=[None]))
131134
self.assertAggregateQuery(
132135
ctx.captured_queries[0]["sql"],
133136
"lookup__book",
@@ -142,3 +145,4 @@ def test_none_filter_binary_operator_in(self):
142145
}
143146
],
144147
)
148+
self.assertQuerySetEqual(Book.objects.filter(title__in=[None]), [])

0 commit comments

Comments
 (0)