summaryrefslogtreecommitdiff
path: root/tests/invalid_models_tests
diff options
context:
space:
mode:
authorIan Foote <python@ian.feete.org>2016-11-05 13:12:12 +0000
committerTim Graham <timograham@gmail.com>2018-07-10 15:32:33 -0400
commit952f05a6db2665d83c04075119285f2164b03432 (patch)
tree616ddfb21cd44c19292c025c494d1995afca13b8 /tests/invalid_models_tests
parent6fbfb5cb9602574adc867d34241172226291d367 (diff)
Fixed #11964 -- Added support for database check constraints.
Diffstat (limited to 'tests/invalid_models_tests')
-rw-r--r--tests/invalid_models_tests/test_models.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py
index 19ec21c9ae..9dd2fd1f06 100644
--- a/tests/invalid_models_tests/test_models.py
+++ b/tests/invalid_models_tests/test_models.py
@@ -1,10 +1,10 @@
import unittest
from django.conf import settings
-from django.core.checks import Error
+from django.core.checks import Error, Warning
from django.core.checks.model_checks import _check_lazy_references
from django.core.exceptions import ImproperlyConfigured
-from django.db import connections, models
+from django.db import connection, connections, models
from django.db.models.signals import post_init
from django.test import SimpleTestCase
from django.test.utils import isolate_apps, override_settings
@@ -972,3 +972,26 @@ class OtherModelTests(SimpleTestCase):
id='signals.E001',
),
])
+
+
+@isolate_apps('invalid_models_tests')
+class ConstraintsTests(SimpleTestCase):
+ def test_check_constraints(self):
+ class Model(models.Model):
+ age = models.IntegerField()
+
+ class Meta:
+ constraints = [models.CheckConstraint(models.Q(age__gte=18), 'is_adult')]
+
+ errors = Model.check()
+ warn = Warning(
+ '%s does not support check constraints.' % connection.display_name,
+ hint=(
+ "A constraint won't be created. Silence this warning if you "
+ "don't care about it."
+ ),
+ obj=Model,
+ id='models.W027',
+ )
+ expected = [] if connection.features.supports_table_check_constraints else [warn, warn]
+ self.assertCountEqual(errors, expected)