diff options
| author | David Sanders <shang.xiao.sanders@gmail.com> | 2022-08-09 20:02:07 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-08-09 20:06:59 +0200 |
| commit | e0ac72fe80a806421dcbbbac22e483b27d2ede7b (patch) | |
| tree | cbe15381f637c0e01c75620c9d441d05649164f0 /tests/postgres_tests/test_constraints.py | |
| parent | cccfb45d0044513f2c632d2a5d5544127d0d019b (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.py | 10 |
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( |
