MCPcopy
hub / github.com/django/django / test_custom_name_lookup

Method test_custom_name_lookup

tests/custom_lookups/tests.py:239–251  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

237
238class LookupTests(TestCase):
239 def test_custom_name_lookup(self):
240 a1 = Author.objects.create(name="a1", birthdate=date(1981, 2, 16))
241 Author.objects.create(name="a2", birthdate=date(2012, 2, 29))
242 with (
243 register_lookup(models.DateField, YearTransform),
244 register_lookup(models.DateField, YearTransform, lookup_name="justtheyear"),
245 register_lookup(YearTransform, Exactly),
246 register_lookup(YearTransform, Exactly, lookup_name="isactually"),
247 ):
248 qs1 = Author.objects.filter(birthdate__testyear__exactly=1981)
249 qs2 = Author.objects.filter(birthdate__justtheyear__isactually=1981)
250 self.assertSequenceEqual(qs1, [a1])
251 self.assertSequenceEqual(qs2, [a1])
252
253 def test_custom_lookup_with_subquery(self):
254 class NotEqual(models.Lookup):

Callers

nothing calls this directly

Calls 4

register_lookupFunction · 0.90
dateFunction · 0.85
createMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected