diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-07-27 06:39:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-27 06:39:02 +0200 |
commit | f4e93919e4608cfc50849a1f764fd856e0917401 (patch) | |
tree | d80c18ab737ed40de0a29f84b426afb57480dbec /tests/constraints | |
parent | c1f8d87bb0ac72b213bf31e672bd34c93bda6b18 (diff) | |
download | django-f4e93919e4608cfc50849a1f764fd856e0917401.tar.gz |
Fixed #31815 -- Fixed schema value encoding on PostgreSQL.
Diffstat (limited to 'tests/constraints')
-rw-r--r-- | tests/constraints/models.py | 8 | ||||
-rw-r--r-- | tests/constraints/tests.py | 6 |
2 files changed, 14 insertions, 0 deletions
diff --git a/tests/constraints/models.py b/tests/constraints/models.py index 1460673a18..f8a4ebe675 100644 --- a/tests/constraints/models.py +++ b/tests/constraints/models.py @@ -4,6 +4,7 @@ from django.db import models class Product(models.Model): price = models.IntegerField(null=True) discounted_price = models.IntegerField(null=True) + unit = models.CharField(max_length=15, null=True) class Meta: required_db_features = { @@ -31,6 +32,13 @@ class Product(models.Model): ), name='%(app_label)s_price_neq_500_wrap', ), + models.CheckConstraint( + check=models.Q( + models.Q(unit__isnull=True) | + models.Q(unit__in=['μg/mL', 'ng/mL']) + ), + name='unicode_unit_list', + ), ] diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py index d9e91bdf49..2796a0f30b 100644 --- a/tests/constraints/tests.py +++ b/tests/constraints/tests.py @@ -89,6 +89,12 @@ class CheckConstraintTests(TestCase): Product.objects.create(price=10, discounted_price=20) @skipUnlessDBFeature('supports_table_check_constraints') + def test_database_constraint_unicode(self): + Product.objects.create(price=10, discounted_price=5, unit='μg/mL') + with self.assertRaises(IntegrityError): + Product.objects.create(price=10, discounted_price=7, unit='l') + + @skipUnlessDBFeature('supports_table_check_constraints') def test_database_constraint_expression(self): Product.objects.create(price=999, discounted_price=5) with self.assertRaises(IntegrityError): |