diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-02-24 09:02:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-24 09:02:45 +0100 |
| commit | 2c428b37ae14b1514cfe1466fd91f01d56799bf4 (patch) | |
| tree | 09adcab2d6b27aa7274c42d591d027ef1bb68953 | |
| parent | 40e88ae8c899bcae3a9520f7a6519dd178185f85 (diff) | |
Refs #34338 -- Fixed isolation of constraints tests.
Regression in 5b3d3e400ab9334ba429ca360c9818c6dfc3a51b.
| -rw-r--r-- | tests/constraints/models.py | 8 | ||||
| -rw-r--r-- | tests/constraints/tests.py | 13 |
2 files changed, 14 insertions, 7 deletions
diff --git a/tests/constraints/models.py b/tests/constraints/models.py index 3b349d204e..ab3d4dc1e0 100644 --- a/tests/constraints/models.py +++ b/tests/constraints/models.py @@ -34,7 +34,13 @@ class UniqueConstraintProduct(models.Model): class Meta: constraints = [ - models.UniqueConstraint(fields=["name", "color"], name="name_color_uniq"), + models.UniqueConstraint( + fields=["name", "color"], + name="name_color_uniq", + # Custom message and error code are ignored. + violation_error_code="custom_code", + violation_error_message="Custom message", + ) ] diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py index ec2b030ac5..1ed669a629 100644 --- a/tests/constraints/tests.py +++ b/tests/constraints/tests.py @@ -744,9 +744,6 @@ class UniqueConstraintTests(TestCase): def test_validate(self): constraint = UniqueConstraintProduct._meta.constraints[0] - # Custom message and error code are ignored. - constraint.violation_error_message = "Custom message" - constraint.violation_error_code = "custom_code" msg = "Unique constraint product with this Name and Color already exists." non_unique_product = UniqueConstraintProduct( name=self.p1.name, color=self.p1.color @@ -811,9 +808,13 @@ class UniqueConstraintTests(TestCase): @skipUnlessDBFeature("supports_partial_indexes") def test_validate_conditon_custom_error(self): p1 = UniqueConstraintConditionProduct.objects.create(name="p1") - constraint = UniqueConstraintConditionProduct._meta.constraints[0] - constraint.violation_error_message = "Custom message" - constraint.violation_error_code = "custom_code" + constraint = models.UniqueConstraint( + fields=["name"], + name="name_without_color_uniq", + condition=models.Q(color__isnull=True), + violation_error_code="custom_code", + violation_error_message="Custom message", + ) msg = "Custom message" with self.assertRaisesMessage(ValidationError, msg) as cm: constraint.validate( |
