diff options
Diffstat (limited to 'tests/constraints/tests.py')
| -rw-r--r-- | tests/constraints/tests.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py index 39b170125f..0c10429c22 100644 --- a/tests/constraints/tests.py +++ b/tests/constraints/tests.py @@ -1297,6 +1297,19 @@ class UniqueConstraintTests(TestCase): with self.assertRaisesMessage(ValidationError, msg): constraint.validate(Product, Product(price=None)) + @skipUnlessDBFeature("supports_comparing_boolean_expr") + def test_validate_nullable_condition(self): + GeneratedFieldStoredProduct.objects.create(name="Product", price=42) + constraint = models.UniqueConstraint( + fields=["name"], + name="uniq_name_for_positive_price", + condition=models.Q(price__gt=0), + ) + constraint.validate( + GeneratedFieldStoredProduct, + GeneratedFieldStoredProduct(name="Product", price=None), + ) + def test_name(self): constraints = get_constraints(UniqueConstraintProduct._meta.db_table) expected_name = "name_color_uniq" |
