MCPcopy
hub / github.com/django/django / test_func_unique_constraint

Method test_func_unique_constraint

tests/schema/tests.py:3570–3590  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3568
3569 @skipUnlessDBFeature("supports_expression_indexes")
3570 def test_func_unique_constraint(self):
3571 with connection.schema_editor() as editor:
3572 editor.create_model(Author)
3573 constraint = UniqueConstraint(Upper("name").desc(), name="func_upper_uq")
3574 # Add constraint.
3575 with connection.schema_editor() as editor:
3576 editor.add_constraint(Author, constraint)
3577 sql = constraint.create_sql(Author, editor)
3578 table = Author._meta.db_table
3579 constraints = self.get_constraints(table)
3580 if connection.features.supports_index_column_ordering:
3581 self.assertIndexOrder(table, constraint.name, ["DESC"])
3582 self.assertIn(constraint.name, constraints)
3583 self.assertIs(constraints[constraint.name]["unique"], True)
3584 # SQL contains a database function.
3585 self.assertIs(sql.references_column(table, "name"), True)
3586 self.assertIn("UPPER(%s)" % editor.quote_name("name"), str(sql))
3587 # Remove constraint.
3588 with connection.schema_editor() as editor:
3589 editor.remove_constraint(Author, constraint)
3590 self.assertNotIn(constraint.name, self.get_constraints(table))
3591
3592 @skipUnlessDBFeature("supports_expression_indexes")
3593 def test_composite_func_unique_constraint(self):

Callers

nothing calls this directly

Calls 12

create_sqlMethod · 0.95
get_constraintsMethod · 0.95
assertIndexOrderMethod · 0.95
UniqueConstraintClass · 0.90
UpperClass · 0.90
schema_editorMethod · 0.80
create_modelMethod · 0.45
descMethod · 0.45
add_constraintMethod · 0.45
references_columnMethod · 0.45
quote_nameMethod · 0.45
remove_constraintMethod · 0.45

Tested by

no test coverage detected