summaryrefslogtreecommitdiff
path: root/tests/introspection
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2019-08-10 02:41:18 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-08-12 06:44:37 +0200
commit8b3e1b6e9e4ee87fe85b2e5437faf59457e03e62 (patch)
treef2b55bc4805add78a494942135bf75c999033f39 /tests/introspection
parent2fb872e56f064361c2cd4674c0f23cd419994d82 (diff)
downloaddjango-8b3e1b6e9e4ee87fe85b2e5437faf59457e03e62.tar.gz
Refs #11964 -- Made constraint support check respect required_db_features.
This will notably silence the warnings issued when running the test suite on MySQL.
Diffstat (limited to 'tests/introspection')
-rw-r--r--tests/introspection/models.py14
-rw-r--r--tests/introspection/tests.py22
2 files changed, 25 insertions, 11 deletions
diff --git a/tests/introspection/models.py b/tests/introspection/models.py
index d069c5820e..6f43359dd4 100644
--- a/tests/introspection/models.py
+++ b/tests/introspection/models.py
@@ -70,14 +70,24 @@ class Comment(models.Model):
article = models.ForeignKey(Article, models.CASCADE, db_index=True)
email = models.EmailField()
pub_date = models.DateTimeField()
- up_votes = models.PositiveIntegerField()
body = models.TextField()
class Meta:
constraints = [
- models.CheckConstraint(name='up_votes_gte_0_check', check=models.Q(up_votes__gte=0)),
models.UniqueConstraint(fields=['article', 'email', 'pub_date'], name='article_email_pub_date_uniq'),
]
indexes = [
models.Index(fields=['email', 'pub_date'], name='email_pub_date_idx'),
]
+
+
+class CheckConstraintModel(models.Model):
+ up_votes = models.PositiveIntegerField()
+
+ class Meta:
+ required_db_features = {
+ 'supports_table_check_constraints',
+ }
+ constraints = [
+ models.CheckConstraint(name='up_votes_gte_0_check', check=models.Q(up_votes__gte=0)),
+ ]
diff --git a/tests/introspection/tests.py b/tests/introspection/tests.py
index 4a7ce11e7a..91b6ec732e 100644
--- a/tests/introspection/tests.py
+++ b/tests/introspection/tests.py
@@ -6,7 +6,8 @@ from django.db.utils import DatabaseError
from django.test import TransactionTestCase, skipUnlessDBFeature
from .models import (
- Article, ArticleReporter, City, Comment, Country, District, Reporter,
+ Article, ArticleReporter, CheckConstraintModel, City, Comment, Country,
+ District, Reporter,
)
@@ -241,19 +242,22 @@ class IntrospectionTests(TransactionTestCase):
self.assertEqual(details['check'], check)
self.assertEqual(details['foreign_key'], foreign_key)
- with connection.cursor() as cursor:
- constraints = connection.introspection.get_constraints(cursor, Comment._meta.db_table)
# Test custom constraints
custom_constraints = {
'article_email_pub_date_uniq',
'email_pub_date_idx',
}
- if (
- connection.features.supports_column_check_constraints and
- connection.features.can_introspect_check_constraints
- ):
- custom_constraints.add('up_votes_gte_0_check')
- assertDetails(constraints['up_votes_gte_0_check'], ['up_votes'], check=True)
+ with connection.cursor() as cursor:
+ constraints = connection.introspection.get_constraints(cursor, Comment._meta.db_table)
+ if (
+ connection.features.supports_column_check_constraints and
+ connection.features.can_introspect_check_constraints
+ ):
+ constraints.update(
+ connection.introspection.get_constraints(cursor, CheckConstraintModel._meta.db_table)
+ )
+ custom_constraints.add('up_votes_gte_0_check')
+ assertDetails(constraints['up_votes_gte_0_check'], ['up_votes'], check=True)
assertDetails(constraints['article_email_pub_date_uniq'], ['article_id', 'email', 'pub_date'], unique=True)
assertDetails(constraints['email_pub_date_idx'], ['email', 'pub_date'], index=True)
# Test field constraints