summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2017-11-11 19:17:20 -0500
committerTim Graham <timograham@gmail.com>2017-11-15 07:58:36 -0500
commit0696edbc6a724ceaba86a977b6d21e57647cb2ac (patch)
treef0e268d7a58d7d63e0e06b8cd867290a8ff9fe7c /tests
parent022aebc55049075e0852dc7b0ce01ea085fe5dcb (diff)
[2.0.x] Fixed #28792 -- Fixed index name truncation of namespaced tables.
Refs #27458, #27843. Thanks Tim and Mariusz for the review. Backport of ee85ef8315db839e5723dea19d8b971420a2ebb4 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/backends/test_utils.py10
-rw-r--r--tests/schema/tests.py15
2 files changed, 24 insertions, 1 deletions
diff --git a/tests/backends/test_utils.py b/tests/backends/test_utils.py
index be9aeaf698..cd4911fd1a 100644
--- a/tests/backends/test_utils.py
+++ b/tests/backends/test_utils.py
@@ -2,7 +2,9 @@
from decimal import Decimal, Rounded
from django.db import connection
-from django.db.backends.utils import format_number, truncate_name
+from django.db.backends.utils import (
+ format_number, split_identifier, truncate_name,
+)
from django.db.utils import NotSupportedError
from django.test import (
SimpleTestCase, TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature,
@@ -21,6 +23,12 @@ class TestUtils(SimpleTestCase):
self.assertEqual(truncate_name('username"."some_long_table', 10), 'username"."some_la38a')
self.assertEqual(truncate_name('username"."some_long_table', 10, 3), 'username"."some_loa38')
+ def test_split_identifier(self):
+ self.assertEqual(split_identifier('some_table'), ('', 'some_table'))
+ self.assertEqual(split_identifier('"some_table"'), ('', 'some_table'))
+ self.assertEqual(split_identifier('namespace"."some_table'), ('namespace', 'some_table'))
+ self.assertEqual(split_identifier('"namespace"."some_table"'), ('namespace', 'some_table'))
+
def test_format_number(self):
def equal(value, max_d, places, result):
self.assertEqual(format_number(Decimal(value), max_d, places), result)
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index e7f47865d4..e40dd117ff 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -2372,6 +2372,21 @@ class SchemaTests(TransactionTestCase):
cast_function=lambda x: x.time(),
)
+ def test_namespaced_db_table_create_index_name(self):
+ """
+ Table names are stripped of their namespace/schema before being used to
+ generate index names.
+ """
+ with connection.schema_editor() as editor:
+ max_name_length = connection.ops.max_name_length() or 200
+ namespace = 'n' * max_name_length
+ table_name = 't' * max_name_length
+ namespaced_table_name = '"%s"."%s"' % (namespace, table_name)
+ self.assertEqual(
+ editor._create_index_name(table_name, []),
+ editor._create_index_name(namespaced_table_name, []),
+ )
+
@unittest.skipUnless(connection.vendor == 'oracle', 'Oracle specific db_table syntax')
def test_creation_with_db_table_double_quotes(self):
oracle_user = connection.creation._test_database_user()