MCPcopy
hub / github.com/django/django / test_order_by_f_expression_duplicates

Method test_order_by_f_expression_duplicates

tests/ordering/tests.py:509–541  ·  view source on GitHub ↗

A column may only be included once (the first occurrence) so we check to ensure there are no duplicates by inspecting the SQL.

(self)

Source from the content-addressed store, hash-verified

507 )
508
509 def test_order_by_f_expression_duplicates(self):
510 """
511 A column may only be included once (the first occurrence) so we check
512 to ensure there are no duplicates by inspecting the SQL.
513 """
514 qs = Article.objects.order_by(F("headline").asc(), F("headline").desc())
515 sql = str(qs.query).upper()
516 fragment = sql[sql.find("ORDER BY") :]
517 self.assertEqual(fragment.count("HEADLINE"), 1)
518 self.assertQuerySetEqual(
519 qs,
520 [
521 "Article 1",
522 "Article 2",
523 "Article 3",
524 "Article 4",
525 ],
526 attrgetter("headline"),
527 )
528 qs = Article.objects.order_by(F("headline").desc(), F("headline").asc())
529 sql = str(qs.query).upper()
530 fragment = sql[sql.find("ORDER BY") :]
531 self.assertEqual(fragment.count("HEADLINE"), 1)
532 self.assertQuerySetEqual(
533 qs,
534 [
535 "Article 4",
536 "Article 3",
537 "Article 2",
538 "Article 1",
539 ],
540 attrgetter("headline"),
541 )
542
543 def test_order_by_constant_value(self):
544 # Order by annotated constant from selected columns.

Callers

nothing calls this directly

Calls 7

FClass · 0.90
order_byMethod · 0.80
assertQuerySetEqualMethod · 0.80
ascMethod · 0.45
descMethod · 0.45
findMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected