From e0ac72fe80a806421dcbbbac22e483b27d2ede7b Mon Sep 17 00:00:00 2001 From: David Sanders Date: Tue, 9 Aug 2022 20:02:07 +0200 Subject: [PATCH] Refs #33905 -- Added test for CheckConstraint() validation with ArrayField and __contains. --- tests/postgres_tests/test_constraints.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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(