mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #34701 -- Moved UniqueConstraint(nulls_distinct) validation tests.
The original tests required the creation of a model that is no longer necessary and were exercising Model.full_clean(validate_constraints) which has nothing to do with the nulls_distinct feature.
This commit is contained in:
committed by
Sarah Boyce
parent
adc0b6aac3
commit
0e49a8c3bd
@@ -1070,6 +1070,19 @@ class UniqueConstraintTests(TestCase):
|
||||
is_not_null_constraint.validate(Product, Product(price=4, discounted_price=3))
|
||||
is_not_null_constraint.validate(Product, Product(price=2, discounted_price=1))
|
||||
|
||||
def test_validate_nulls_distinct_fields(self):
|
||||
Product.objects.create(price=42)
|
||||
constraint = models.UniqueConstraint(
|
||||
fields=["price"],
|
||||
nulls_distinct=False,
|
||||
name="uniq_prices_nulls_distinct",
|
||||
)
|
||||
constraint.validate(Product, Product(price=None))
|
||||
Product.objects.create(price=None)
|
||||
msg = "Product with this Price already exists."
|
||||
with self.assertRaisesMessage(ValidationError, msg):
|
||||
constraint.validate(Product, Product(price=None))
|
||||
|
||||
def test_validate_nulls_distinct_expressions(self):
|
||||
Product.objects.create(price=42)
|
||||
constraint = models.UniqueConstraint(
|
||||
|
||||
Reference in New Issue
Block a user