Ticket #33982: test-33982.diff

File test-33982.diff, 1.8 KB (added by Mariusz Felisiak, 20 months ago)

Regression test.

  • tests/postgres_tests/test_constraints.py

    diff --git a/tests/postgres_tests/test_constraints.py b/tests/postgres_tests/test_constraints.py
    index a6f7b5be85..2b6df7d5f5 100644
    a b from django.db.models import (  
    1010    F,
    1111    Func,
    1212    IntegerField,
     13    Model,
    1314    Q,
    1415    UniqueConstraint,
    1516)
    1617from django.db.models.fields.json import KeyTextTransform
    1718from django.db.models.functions import Cast, Left, Lower
    1819from django.test import ignore_warnings, modify_settings, skipUnlessDBFeature
     20from django.test.utils import isolate_apps
    1921from django.utils import timezone
    2022from django.utils.deprecation import RemovedInDjango50Warning
    2123
    class ExclusionConstraintTests(PostgreSQLTestCase):  
    11511153            editor.add_constraint(Room, constraint)
    11521154        self.assertIn(constraint_name, self.get_constraints(Room._meta.db_table))
    11531155
     1156    @isolate_apps("postgres_tests")
     1157    def test_table_create(self):
     1158        constraint_name = "exclusion_equal_number_tc"
     1159
     1160        class ModelWithExclusionConstraint(Model):
     1161            number = IntegerField()
     1162
     1163            class Meta:
     1164                app_label = "postgres_tests"
     1165                constraints = [
     1166                    ExclusionConstraint(
     1167                        name=constraint_name,
     1168                        expressions=[("number", RangeOperators.EQUAL)],
     1169                    )
     1170                ]
     1171
     1172        with connection.schema_editor() as editor:
     1173            editor.create_model(ModelWithExclusionConstraint)
     1174        self.assertIn(
     1175            constraint_name,
     1176            self.get_constraints(ModelWithExclusionConstraint._meta.db_table),
     1177        )
     1178
    11541179
    11551180@modify_settings(INSTALLED_APPS={"append": "django.contrib.postgres"})
    11561181class ExclusionConstraintOpclassesDepracationTests(PostgreSQLTestCase):
Back to Top