summaryrefslogtreecommitdiff
path: root/tests/constraints
diff options
context:
space:
mode:
authorcan <cansarigol@derinbilgi.com.tr>2019-07-05 15:15:41 +0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-07-08 14:57:56 +0200
commitfebe136d4c3310ec8901abecca3ea5ba2be3952c (patch)
tree4eeae36c3ae832a90f8a4721b2de54ea555a8478 /tests/constraints
parent8233144ca0c93b589b61a2ad0fb7c851f3356a3b (diff)
Fixed #30397 -- Added app_label/class interpolation for names of indexes and constraints.
Diffstat (limited to 'tests/constraints')
-rw-r--r--tests/constraints/models.py21
-rw-r--r--tests/constraints/tests.py15
2 files changed, 33 insertions, 3 deletions
diff --git a/tests/constraints/models.py b/tests/constraints/models.py
index f316b95161..fb6ef620f0 100644
--- a/tests/constraints/models.py
+++ b/tests/constraints/models.py
@@ -13,6 +13,10 @@ class Product(models.Model):
check=models.Q(price__gt=models.F('discounted_price')),
name='price_gt_discounted_price',
),
+ models.CheckConstraint(
+ check=models.Q(price__gt=0),
+ name='%(app_label)s_%(class)s_price_gt_0',
+ ),
models.UniqueConstraint(fields=['name', 'color'], name='name_color_uniq'),
models.UniqueConstraint(
fields=['name'],
@@ -20,3 +24,20 @@ class Product(models.Model):
condition=models.Q(color__isnull=True),
),
]
+
+
+class AbstractModel(models.Model):
+ age = models.IntegerField()
+
+ class Meta:
+ abstract = True
+ constraints = [
+ models.CheckConstraint(
+ check=models.Q(age__gte=18),
+ name='%(app_label)s_%(class)s_adult',
+ ),
+ ]
+
+
+class ChildModel(AbstractModel):
+ pass
diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py
index b7aeb1e7f0..c2f99c565d 100644
--- a/tests/constraints/tests.py
+++ b/tests/constraints/tests.py
@@ -3,7 +3,7 @@ from django.db import IntegrityError, connection, models
from django.db.models.constraints import BaseConstraint
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
-from .models import Product
+from .models import ChildModel, Product
def get_constraints(table):
@@ -76,8 +76,17 @@ class CheckConstraintTests(TestCase):
@skipUnlessDBFeature('supports_table_check_constraints')
def test_name(self):
constraints = get_constraints(Product._meta.db_table)
- expected_name = 'price_gt_discounted_price'
- self.assertIn(expected_name, constraints)
+ for expected_name in (
+ 'price_gt_discounted_price',
+ 'constraints_product_price_gt_0',
+ ):
+ with self.subTest(expected_name):
+ self.assertIn(expected_name, constraints)
+
+ @skipUnlessDBFeature('supports_table_check_constraints')
+ def test_abstract_name(self):
+ constraints = get_constraints(ChildModel._meta.db_table)
+ self.assertIn('constraints_childmodel_adult', constraints)
class UniqueConstraintTests(TestCase):