MCPcopy
hub / github.com/django/django / test_partial_func_index

Method test_partial_func_index

tests/indexes/tests.py:518–554  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

516
517 @skipUnlessDBFeature("supports_expression_indexes")
518 def test_partial_func_index(self):
519 index_name = "partial_func_idx"
520 index = Index(
521 Lower("headline").desc(),
522 name=index_name,
523 condition=Q(pub_date__isnull=False),
524 )
525 with connection.schema_editor() as editor:
526 editor.add_index(index=index, model=Article)
527 sql = index.create_sql(Article, schema_editor=editor)
528 table = Article._meta.db_table
529 self.assertIs(sql.references_column(table, "headline"), True)
530 sql = str(sql)
531 self.assertIn("LOWER(%s)" % editor.quote_name("headline"), sql)
532 self.assertIn(
533 "WHERE %s IS NOT NULL" % editor.quote_name("pub_date"),
534 sql,
535 )
536 self.assertGreater(sql.find("WHERE"), sql.find("LOWER"))
537 with connection.cursor() as cursor:
538 constraints = connection.introspection.get_constraints(
539 cursor=cursor,
540 table_name=table,
541 )
542 self.assertIn(index_name, constraints)
543 if connection.features.supports_index_column_ordering:
544 self.assertEqual(constraints[index_name]["orders"], ["DESC"])
545 with connection.schema_editor() as editor:
546 editor.remove_index(Article, index)
547 with connection.cursor() as cursor:
548 self.assertNotIn(
549 index_name,
550 connection.introspection.get_constraints(
551 cursor=cursor,
552 table_name=table,
553 ),
554 )
555
556
557@skipUnlessDBFeature("supports_covering_indexes")

Callers

nothing calls this directly

Calls 13

create_sqlMethod · 0.95
IndexClass · 0.90
LowerClass · 0.90
QClass · 0.90
schema_editorMethod · 0.80
cursorMethod · 0.80
descMethod · 0.45
add_indexMethod · 0.45
references_columnMethod · 0.45
quote_nameMethod · 0.45
findMethod · 0.45
get_constraintsMethod · 0.45

Tested by

no test coverage detected