diff options
| author | Simon Charette <charette.s@gmail.com> | 2018-08-05 21:06:52 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-11-13 15:25:44 -0500 |
| commit | dba4a634ba999bf376caee193b3378bc0b730bd4 (patch) | |
| tree | dcf309133def892bc314e69f423e926f6e4dcc73 /tests/constraints | |
| parent | 2f120ac51722a257219a7577759702605cefddf4 (diff) | |
Refs #29641 -- Refactored database schema constraint creation.
Added a test for constraint names in the database.
Updated SQLite introspection to use sqlparse to allow reading the
constraint name for table check and unique constraints.
Co-authored-by: Ian Foote <python@ian.feete.org>
Diffstat (limited to 'tests/constraints')
| -rw-r--r-- | tests/constraints/tests.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py index 28a5c4ba34..b144c24a28 100644 --- a/tests/constraints/tests.py +++ b/tests/constraints/tests.py @@ -1,10 +1,15 @@ -from django.db import IntegrityError, models +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 +def get_constraints(table): + with connection.cursor() as cursor: + return connection.introspection.get_constraints(cursor, table) + + class BaseConstraintTests(SimpleTestCase): def test_constraint_sql(self): c = BaseConstraint('name') @@ -37,3 +42,11 @@ class CheckConstraintTests(TestCase): Product.objects.create(name='Valid', price=10, discounted_price=5) with self.assertRaises(IntegrityError): Product.objects.create(name='Invalid', price=10, discounted_price=20) + + @skipUnlessDBFeature('supports_table_check_constraints') + def test_name(self): + constraints = get_constraints(Product._meta.db_table) + expected_name = 'price_gt_discounted_price' + if connection.features.uppercases_column_names: + expected_name = expected_name.upper() + self.assertIn(expected_name, constraints) |
