Ticket #31815: tests-31815.diff

File tests-31815.diff, 1.6 KB (added by Mariusz Felisiak, 4 years ago)

Regression test.

  • tests/constraints/models.py

    diff --git a/tests/constraints/models.py b/tests/constraints/models.py
    index 1460673a18..9a88ff83d1 100644
    a b from django.db import models  
    44class Product(models.Model):
    55    price = models.IntegerField(null=True)
    66    discounted_price = models.IntegerField(null=True)
     7    unit = models.CharField(max_length=15, null=True)
    78
    89    class Meta:
    910        required_db_features = {
    class Product(models.Model):  
    3132                ),
    3233                name='%(app_label)s_price_neq_500_wrap',
    3334            ),
     35            models.CheckConstraint(
     36                check=models.Q(unit__isnull=True) | models.Q(unit__in=['μg/mL', 'ng/mL']),
     37                name='unicode_unit_list',
     38            ),
    3439        ]
    3540
    3641
  • tests/constraints/tests.py

    diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py
    index d9e91bdf49..2796a0f30b 100644
    a b class CheckConstraintTests(TestCase):  
    8888        with self.assertRaises(IntegrityError):
    8989            Product.objects.create(price=10, discounted_price=20)
    9090
     91    @skipUnlessDBFeature('supports_table_check_constraints')
     92    def test_database_constraint_unicode(self):
     93        Product.objects.create(price=10, discounted_price=5, unit='μg/mL')
     94        with self.assertRaises(IntegrityError):
     95            Product.objects.create(price=10, discounted_price=7, unit='l')
     96
    9197    @skipUnlessDBFeature('supports_table_check_constraints')
    9298    def test_database_constraint_expression(self):
    9399        Product.objects.create(price=999, discounted_price=5)
Back to Top