MCPcopy
hub / github.com/django/django / test_conditional_expression

Method test_conditional_expression

tests/lookup/tests.py:1955–1972  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1953 self.assertEqual(qs["modern"], 2)
1954
1955 def test_conditional_expression(self):
1956 qs = Season.objects.annotate(
1957 century=Case(
1958 When(
1959 GreaterThan(F("year"), 1900) & LessThanOrEqual(F("year"), 2000),
1960 then=Value("20th"),
1961 ),
1962 default=Value("other"),
1963 )
1964 ).values("year", "century")
1965 self.assertCountEqual(
1966 qs,
1967 [
1968 {"year": 1942, "century": "20th"},
1969 {"year": 1842, "century": "other"},
1970 {"year": 2042, "century": "other"},
1971 ],
1972 )
1973
1974 def test_multivalued_join_reuse(self):
1975 self.assertEqual(

Callers

nothing calls this directly

Calls 8

CaseClass · 0.90
WhenClass · 0.90
GreaterThanClass · 0.90
FClass · 0.90
LessThanOrEqualClass · 0.90
ValueClass · 0.90
annotateMethod · 0.80
valuesMethod · 0.45

Tested by

no test coverage detected