Skip to content
Prev Previous commit
Next Next commit
call filter once in each test
  • Loading branch information
Jibola committed Sep 12, 2025
commit 50177bc2871fce17e44528d118b755334234f90c
12 changes: 5 additions & 7 deletions tests/lookup_/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,19 @@ def setUpTestData(cls):

def _test_none_filter_nullable_json(self, op, predicate, field):
with self.assertNumQueries(1) as ctx:
list(NullableJSONModel.objects.filter(**{f"{field}__{op}": None}))
self.assertQuerySetEqual(
NullableJSONModel.objects.filter(**{f"{field}__{op}": None}),
[],
)
self.assertAggregateQuery(
ctx.captured_queries[0]["sql"],
"lookup__nullablejsonmodel",
[{"$match": {"$and": [{"$exists": False}, predicate(field)]}}],
)
self.assertQuerySetEqual(
NullableJSONModel.objects.filter(**{f"{field}__{op}": None}),
[],
)

def _test_none_filter_binary_operator(self, op, predicate, field):
with self.assertNumQueries(1) as ctx:
list(Book.objects.filter(**{f"{field}__{op}": None}))
self.assertQuerySetEqual(Book.objects.filter(**{f"{field}__{op}": None}), [])
self.assertAggregateQuery(
ctx.captured_queries[0]["sql"],
"lookup__book",
Expand All @@ -116,7 +115,6 @@ def _test_none_filter_binary_operator(self, op, predicate, field):
}
],
)
self.assertQuerySetEqual(Book.objects.filter(**{f"{field}__{op}": None}), [])

def _test_with_raw_data(self, model, test_function):
collection = connection.database.get_collection(model._meta.db_table)
Expand Down
Loading