diff --git a/tests/postgres_tests/test_constraints.py b/tests/postgres_tests/test_constraints.py
index 0e09a1c546..24557939ee 100644
a
|
b
|
from django.db.models.constraints import CheckConstraint
|
4 | 4 | from django.db.utils import IntegrityError |
5 | 5 | |
6 | 6 | from . import PostgreSQLTestCase |
7 | | from .models import RangesModel |
| 7 | from .models import CharFieldModel, RangesModel |
8 | 8 | |
9 | 9 | try: |
10 | 10 | from psycopg2.extras import NumericRange |
… |
… |
class SchemaTests(PostgreSQLTestCase):
|
33 | 33 | with self.assertRaises(IntegrityError), transaction.atomic(): |
34 | 34 | RangesModel.objects.create(ints=(20, 50)) |
35 | 35 | RangesModel.objects.create(ints=(10, 30)) |
| 36 | |
| 37 | def test_check_constraint_startswith(self): |
| 38 | constraint_name = 'char_startswith_bar' |
| 39 | self.assertNotIn(constraint_name, self.get_constraints(CharFieldModel._meta.db_table)) |
| 40 | constraint = CheckConstraint( |
| 41 | check=Q(field__startswith='BAR'), |
| 42 | name=constraint_name, |
| 43 | ) |
| 44 | with connection.schema_editor() as editor: |
| 45 | editor.add_constraint(CharFieldModel, constraint) |
| 46 | with connection.cursor() as cursor: |
| 47 | constraints = connection.introspection.get_constraints(cursor, CharFieldModel._meta.db_table) |
| 48 | self.assertIn(constraint_name, constraints) |
| 49 | with self.assertRaises(IntegrityError), transaction.atomic(): |
| 50 | CharFieldModel.objects.create(field='FOO') |
| 51 | CharFieldModel.objects.create(field='BAR1') |