mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #34701 -- Added support for NULLS [NOT] DISTINCT on PostgreSQL 15+.
This commit is contained in:
committed by
Mariusz Felisiak
parent
98cfb90182
commit
595a2abb58
@@ -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 "
|
||||
|
||||
Reference in New Issue
Block a user