(self)
| 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): |
nothing calls this directly
no test coverage detected