summaryrefslogtreecommitdiff
path: root/tests/inspectdb
diff options
context:
space:
mode:
authorAndrii Kohut <kogut.andriy@gmail.com>2023-05-22 00:00:25 +0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-05-22 16:48:06 +0200
commitf8172f45fc83af2315aefed77ee34b5654f5c347 (patch)
tree50b672b6ba7b73678b924964796dbde12639c2a3 /tests/inspectdb
parentc3862735cd8c268e99fb8d54c3955aacc4f2dc25 (diff)
Fixed #34587 -- Allowed customizing table name normalization in inspectdb command.
Diffstat (limited to 'tests/inspectdb')
-rw-r--r--tests/inspectdb/models.py5
-rw-r--r--tests/inspectdb/tests.py20
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/inspectdb/models.py b/tests/inspectdb/models.py
index 9e6871ce46..25714cb086 100644
--- a/tests/inspectdb/models.py
+++ b/tests/inspectdb/models.py
@@ -51,6 +51,11 @@ class SpecialName(models.Model):
db_table = "inspectdb_special.table name"
+class PascalCaseName(models.Model):
+ class Meta:
+ db_table = "inspectdb_pascal.PascalCase"
+
+
class ColumnTypes(models.Model):
id = models.AutoField(primary_key=True)
big_int_field = models.BigIntegerField()
diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py
index 4f44190686..1be4efc430 100644
--- a/tests/inspectdb/tests.py
+++ b/tests/inspectdb/tests.py
@@ -3,6 +3,7 @@ from io import StringIO
from unittest import mock, skipUnless
from django.core.management import call_command
+from django.core.management.commands import inspectdb
from django.db import connection
from django.db.backends.base.introspection import TableInfo
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
@@ -354,6 +355,25 @@ class InspectDBTestCase(TestCase):
output = out.getvalue()
self.assertIn("class InspectdbSpecialTableName(models.Model):", output)
+ def test_custom_normalize_table_name(self):
+ def pascal_case_table_only(table_name):
+ return table_name.startswith("inspectdb_pascal")
+
+ class MyCommand(inspectdb.Command):
+ def normalize_table_name(self, table_name):
+ normalized_name = table_name.split(".")[1]
+ if connection.features.ignores_table_name_case:
+ normalized_name = normalized_name.lower()
+ return normalized_name
+
+ out = StringIO()
+ call_command(MyCommand(), table_name_filter=pascal_case_table_only, stdout=out)
+ if connection.features.ignores_table_name_case:
+ expected_model_name = "pascalcase"
+ else:
+ expected_model_name = "PascalCase"
+ self.assertIn(f"class {expected_model_name}(models.Model):", out.getvalue())
+
@skipUnlessDBFeature("supports_expression_indexes")
def test_table_with_func_unique_constraint(self):
out = StringIO()