summaryrefslogtreecommitdiff
path: root/tests/introspection
diff options
context:
space:
mode:
authorHannes Ljungberg <hannes.ljungberg@gmail.com>2021-02-17 10:46:40 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-02-17 10:59:17 +0100
commit4d99375b46ad03fa4b4795319973046f438328c8 (patch)
treef928aaee2cf4ba8d786d511a9f269386df67f7c3 /tests/introspection
parent45bef6706ae7436b5c2c503018b21ff70b2e6728 (diff)
Fixed #32453 -- Added introspection of unique constraint field ordering on SQLite.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests/introspection')
-rw-r--r--tests/introspection/models.py15
-rw-r--r--tests/introspection/tests.py15
2 files changed, 29 insertions, 1 deletions
diff --git a/tests/introspection/models.py b/tests/introspection/models.py
index 72881cf43c..30a7a8b3ee 100644
--- a/tests/introspection/models.py
+++ b/tests/introspection/models.py
@@ -80,3 +80,18 @@ class CheckConstraintModel(models.Model):
constraints = [
models.CheckConstraint(name='up_votes_gte_0_check', check=models.Q(up_votes__gte=0)),
]
+
+
+class UniqueConstraintConditionModel(models.Model):
+ name = models.CharField(max_length=255)
+ color = models.CharField(max_length=32, null=True)
+
+ class Meta:
+ required_db_features = {'supports_partial_indexes'}
+ constraints = [
+ models.UniqueConstraint(
+ fields=['name'],
+ name='cond_name_without_color_uniq',
+ condition=models.Q(color__isnull=True),
+ ),
+ ]
diff --git a/tests/introspection/tests.py b/tests/introspection/tests.py
index 82a661a83d..bd5d7c942a 100644
--- a/tests/introspection/tests.py
+++ b/tests/introspection/tests.py
@@ -6,7 +6,7 @@ from django.test import TransactionTestCase, skipUnlessDBFeature
from .models import (
Article, ArticleReporter, CheckConstraintModel, City, Comment, Country,
- District, Reporter,
+ District, Reporter, UniqueConstraintConditionModel,
)
@@ -221,6 +221,19 @@ class IntrospectionTests(TransactionTestCase):
indexes_verified += 1
self.assertEqual(indexes_verified, len(expected_columns))
+ @skipUnlessDBFeature('supports_index_column_ordering', 'supports_partial_indexes')
+ def test_get_constraints_unique_indexes_orders(self):
+ with connection.cursor() as cursor:
+ constraints = connection.introspection.get_constraints(
+ cursor,
+ UniqueConstraintConditionModel._meta.db_table,
+ )
+ self.assertIn('cond_name_without_color_uniq', constraints)
+ constraint = constraints['cond_name_without_color_uniq']
+ self.assertIs(constraint['unique'], True)
+ self.assertEqual(constraint['columns'], ['name'])
+ self.assertEqual(constraint['orders'], ['ASC'])
+
def test_get_constraints(self):
def assertDetails(details, cols, primary_key=False, unique=False, index=False, check=False, foreign_key=None):
# Different backends have different values for same constraints: