diff options
| author | Simon Charette <charette.s@gmail.com> | 2023-07-07 19:43:51 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-07-19 21:42:27 +0200 |
| commit | 595a2abb58e04caa4d55fb2589bb80fb2a8fdfa1 (patch) | |
| tree | f08cf5a71a9d637818d896a7b31b2d7860e336ca /tests/constraints | |
| parent | 98cfb90182a8baa806fc4e09e294b6cfc5d09eff (diff) | |
Fixed #34701 -- Added support for NULLS [NOT] DISTINCT on PostgreSQL 15+.
Diffstat (limited to 'tests/constraints')
| -rw-r--r-- | tests/constraints/tests.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py index 1ed669a629..5fde168af4 100644 --- a/tests/constraints/tests.py +++ b/tests/constraints/tests.py @@ -503,6 +503,27 @@ class UniqueConstraintTests(TestCase): self.assertEqual(constraint, mock.ANY) self.assertNotEqual(constraint, another_constraint) + def test_eq_with_nulls_distinct(self): + constraint_1 = models.UniqueConstraint( + Lower("title"), + nulls_distinct=False, + name="book_func_nulls_distinct_uq", + ) + constraint_2 = models.UniqueConstraint( + Lower("title"), + nulls_distinct=True, + name="book_func_nulls_distinct_uq", + ) + constraint_3 = models.UniqueConstraint( + Lower("title"), + name="book_func_nulls_distinct_uq", + ) + self.assertEqual(constraint_1, constraint_1) + self.assertEqual(constraint_1, mock.ANY) + self.assertNotEqual(constraint_1, constraint_2) + self.assertNotEqual(constraint_1, constraint_3) + self.assertNotEqual(constraint_2, constraint_3) + def test_repr(self): fields = ["foo", "bar"] name = "unique_fields" @@ -560,6 +581,18 @@ class UniqueConstraintTests(TestCase): "opclasses=['text_pattern_ops', 'varchar_pattern_ops']>", ) + def test_repr_with_nulls_distinct(self): + constraint = models.UniqueConstraint( + fields=["foo", "bar"], + name="nulls_distinct_fields", + nulls_distinct=False, + ) + self.assertEqual( + repr(constraint), + "<UniqueConstraint: fields=('foo', 'bar') name='nulls_distinct_fields' " + "nulls_distinct=False>", + ) + def test_repr_with_expressions(self): constraint = models.UniqueConstraint( Lower("title"), @@ -679,6 +712,24 @@ class UniqueConstraintTests(TestCase): }, ) + def test_deconstruction_with_nulls_distinct(self): + fields = ["foo", "bar"] + name = "unique_fields" + constraint = models.UniqueConstraint( + fields=fields, name=name, nulls_distinct=True + ) + path, args, kwargs = constraint.deconstruct() + self.assertEqual(path, "django.db.models.UniqueConstraint") + self.assertEqual(args, ()) + self.assertEqual( + kwargs, + { + "fields": tuple(fields), + "name": name, + "nulls_distinct": True, + }, + ) + def test_deconstruction_with_expressions(self): name = "unique_fields" constraint = models.UniqueConstraint(Lower("title"), name=name) @@ -1029,6 +1080,13 @@ class UniqueConstraintTests(TestCase): opclasses="jsonb_path_ops", ) + def test_invalid_nulls_distinct_argument(self): + msg = "UniqueConstraint.nulls_distinct must be a bool." + with self.assertRaisesMessage(ValueError, msg): + models.UniqueConstraint( + name="uniq_opclasses", fields=["field"], nulls_distinct="NULLS DISTINCT" + ) + def test_opclasses_and_fields_same_length(self): msg = ( "UniqueConstraint.fields and UniqueConstraint.opclasses must have " |
