1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Refs #33829 -- Added violation_error_message to constraints' __repr__().

This commit is contained in:
Xavier Fernandez
2023-02-22 21:04:05 +01:00
committed by Mariusz Felisiak
parent dcd9746983
commit 51c9bb7cd1
4 changed files with 58 additions and 3 deletions

View File

@@ -160,6 +160,18 @@ class CheckConstraintTests(TestCase):
"name='price_gt_discounted_price'>",
)
def test_repr_with_violation_error_message(self):
constraint = models.CheckConstraint(
check=models.Q(price__lt=1),
name="price_lt_one",
violation_error_message="More than 1",
)
self.assertEqual(
repr(constraint),
"<CheckConstraint: check=(AND: ('price__lt', 1)) name='price_lt_one' "
"violation_error_message='More than 1'>",
)
def test_invalid_check_types(self):
msg = "CheckConstraint.check must be a Q instance or boolean expression."
with self.assertRaisesMessage(TypeError, msg):
@@ -486,6 +498,20 @@ class UniqueConstraintTests(TestCase):
"name='book_func_uq'>",
)
def test_repr_with_violation_error_message(self):
constraint = models.UniqueConstraint(
models.F("baz__lower"),
name="unique_lower_baz",
violation_error_message="BAZ",
)
self.assertEqual(
repr(constraint),
(
"<UniqueConstraint: expressions=(F(baz__lower),) "
"name='unique_lower_baz' violation_error_message='BAZ'>"
),
)
def test_deconstruction(self):
fields = ["foo", "bar"]
name = "unique_fields"