MCPcopy
hub / github.com/django/django / test_order_by_constant_value

Method test_order_by_constant_value

tests/ordering/tests.py:543–561  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

541 )
542
543 def test_order_by_constant_value(self):
544 # Order by annotated constant from selected columns.
545 qs = Article.objects.annotate(
546 constant=Value("1", output_field=CharField()),
547 ).order_by("constant", "-headline")
548 self.assertSequenceEqual(qs, [self.a4, self.a3, self.a2, self.a1])
549 # Order by annotated constant which is out of selected columns.
550 self.assertSequenceEqual(
551 qs.values_list("headline", flat=True),
552 [
553 "Article 4",
554 "Article 3",
555 "Article 2",
556 "Article 1",
557 ],
558 )
559 # Order by constant.
560 qs = Article.objects.order_by(Value("1", output_field=CharField()), "-headline")
561 self.assertSequenceEqual(qs, [self.a4, self.a3, self.a2, self.a1])
562
563 def test_order_by_case_when_constant_value(self):
564 qs = Article.objects.order_by(

Callers

nothing calls this directly

Calls 5

ValueClass · 0.90
CharFieldClass · 0.90
order_byMethod · 0.80
annotateMethod · 0.80
values_listMethod · 0.80

Tested by

no test coverage detected