Refs #33905 -- Added test for CheckConstraint() validation with ArrayField and __contains.

This commit is contained in:
David Sanders 2022-08-09 20:02:07 +02:00 committed by Mariusz Felisiak
parent cccfb45d00
commit e0ac72fe80
1 changed files with 10 additions and 0 deletions

View File

@ -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(