summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_constraints.py
diff options
context:
space:
mode:
authorDavid Sanders <shang.xiao.sanders@gmail.com>2022-08-09 20:02:07 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-08-09 20:06:59 +0200
commite0ac72fe80a806421dcbbbac22e483b27d2ede7b (patch)
treecbe15381f637c0e01c75620c9d441d05649164f0 /tests/postgres_tests/test_constraints.py
parentcccfb45d0044513f2c632d2a5d5544127d0d019b (diff)
Refs #33905 -- Added test for CheckConstraint() validation with ArrayField and __contains.
Diffstat (limited to 'tests/postgres_tests/test_constraints.py')
-rw-r--r--tests/postgres_tests/test_constraints.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_constraints.py b/tests/postgres_tests/test_constraints.py
index a33c485a36..b3822e5805 100644
--- a/tests/postgres_tests/test_constraints.py
+++ b/tests/postgres_tests/test_constraints.py
@@ -65,6 +65,16 @@ class SchemaTests(PostgreSQLTestCase):
RangesModel.objects.create(ints=(20, 50))
RangesModel.objects.create(ints=(10, 30))
+ def test_check_constraint_array_contains(self):
+ constraint = CheckConstraint(
+ check=Q(field__contains=[1]),
+ name="array_contains",
+ )
+ msg = f"Constraint “{constraint.name}” is violated."
+ with self.assertRaisesMessage(ValidationError, msg):
+ constraint.validate(IntegerArrayModel, IntegerArrayModel())
+ constraint.validate(IntegerArrayModel, IntegerArrayModel(field=[1]))
+
def test_check_constraint_daterange_contains(self):
constraint_name = "dates_contains"
self.assertNotIn(