diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2018-11-21 09:06:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-21 09:06:50 +0100 |
| commit | d5f4ce9849b062cc788988f2600359dc3c2890cb (patch) | |
| tree | 8293093d13cc38fec2561987cf32c7273672fe0e /tests | |
| parent | 2e4776196d0e7519f2fb306e8aabadc6f2968866 (diff) | |
Fixed #29949 -- Refactored db introspection identifier converters.
Removed DatabaseIntrospection.table_name_converter()/column_name_converter()
and use instead DatabaseIntrospection.identifier_converter().
Removed DatabaseFeatures.uppercases_column_names.
Thanks Tim Graham for the initial patch and review and Simon Charette
for the review.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/backends/tests.py | 6 | ||||
| -rw-r--r-- | tests/constraints/tests.py | 4 | ||||
| -rw-r--r-- | tests/gis_tests/gis_migrations/test_operations.py | 5 | ||||
| -rw-r--r-- | tests/inspectdb/tests.py | 2 | ||||
| -rw-r--r-- | tests/schema/tests.py | 41 | ||||
| -rw-r--r-- | tests/select_for_update/tests.py | 7 |
6 files changed, 23 insertions, 42 deletions
diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 6e6868edfb..19b46e916e 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -80,7 +80,7 @@ class ParameterHandlingTest(TestCase): "An executemany call with too many/not enough parameters will raise an exception (Refs #12612)" with connection.cursor() as cursor: query = ('INSERT INTO %s (%s, %s) VALUES (%%s, %%s)' % ( - connection.introspection.table_name_converter('backends_square'), + connection.introspection.identifier_converter('backends_square'), connection.ops.quote_name('root'), connection.ops.quote_name('square') )) @@ -217,7 +217,7 @@ class BackendTestCase(TransactionTestCase): def create_squares(self, args, paramstyle, multiple): opts = Square._meta - tbl = connection.introspection.table_name_converter(opts.db_table) + tbl = connection.introspection.identifier_converter(opts.db_table) f1 = connection.ops.quote_name(opts.get_field('root').column) f2 = connection.ops.quote_name(opts.get_field('square').column) if paramstyle == 'format': @@ -303,7 +303,7 @@ class BackendTestCase(TransactionTestCase): 'SELECT %s, %s FROM %s ORDER BY %s' % ( qn(f3.column), qn(f4.column), - connection.introspection.table_name_converter(opts2.db_table), + connection.introspection.identifier_converter(opts2.db_table), qn(f3.column), ) ) diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py index ddcaf7cfe0..d53892c3a3 100644 --- a/tests/constraints/tests.py +++ b/tests/constraints/tests.py @@ -48,8 +48,6 @@ class CheckConstraintTests(TestCase): 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) @@ -87,6 +85,4 @@ class UniqueConstraintTests(TestCase): def test_name(self): constraints = get_constraints(Product._meta.db_table) expected_name = 'unique_name' - if connection.features.uppercases_column_names: - expected_name = expected_name.upper() self.assertIn(expected_name, constraints) diff --git a/tests/gis_tests/gis_migrations/test_operations.py b/tests/gis_tests/gis_migrations/test_operations.py index 3694a7eb67..c5794eebc2 100644 --- a/tests/gis_tests/gis_migrations/test_operations.py +++ b/tests/gis_tests/gis_migrations/test_operations.py @@ -63,12 +63,9 @@ class OperationTestCase(TransactionTestCase): self.current_state = self.apply_operations('gis', ProjectState(), operations) def assertGeometryColumnsCount(self, expected_count): - table_name = 'gis_neighborhood' - if connection.features.uppercases_column_names: - table_name = table_name.upper() self.assertEqual( GeometryColumns.objects.filter(**{ - GeometryColumns.table_name_col(): table_name, + '%s__iexact' % GeometryColumns.table_name_col(): 'gis_neighborhood', }).count(), expected_count ) diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index b578dbf3df..6452002c3e 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -184,7 +184,7 @@ class InspectDBTestCase(TestCase): out = StringIO() call_command('inspectdb', table_name_filter=special_table_only, stdout=out) output = out.getvalue() - base_name = 'field' if connection.features.uppercases_column_names else 'Field' + base_name = connection.introspection.identifier_converter('Field') self.assertIn("field = models.IntegerField()", output) self.assertIn("field_field = models.IntegerField(db_column='%s_')" % base_name, output) self.assertIn("field_field_0 = models.IntegerField(db_column='%s__')" % base_name, output) diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 6f2b6df765..fc39b77f87 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -85,7 +85,7 @@ class SchemaTests(TransactionTestCase): def delete_tables(self): "Deletes all model tables for our models for a clean test environment" - converter = connection.introspection.table_name_converter + converter = connection.introspection.identifier_converter with connection.schema_editor() as editor: connection.disable_constraint_checking() table_names = connection.introspection.table_names() @@ -1868,9 +1868,6 @@ class SchemaTests(TransactionTestCase): table_name=AuthorWithIndexedName._meta.db_table, column_names=('name',), ) - if connection.features.uppercases_column_names: - author_index_name = author_index_name.upper() - db_index_name = db_index_name.upper() try: AuthorWithIndexedName._meta.indexes = [index] with connection.schema_editor() as editor: @@ -1908,8 +1905,6 @@ class SchemaTests(TransactionTestCase): with connection.schema_editor() as editor: editor.add_index(Author, index) if connection.features.supports_index_column_ordering: - if connection.features.uppercases_column_names: - index_name = index_name.upper() self.assertIndexOrder(Author._meta.db_table, index_name, ['ASC', 'DESC']) # Drop the index with connection.schema_editor() as editor: @@ -2122,12 +2117,14 @@ class SchemaTests(TransactionTestCase): field = get_field() table = model._meta.db_table column = field.column + identifier_converter = connection.introspection.identifier_converter with connection.schema_editor() as editor: editor.create_model(model) editor.add_field(model, field) - constraint_name = "CamelCaseIndex" + constraint_name = 'CamelCaseIndex' + expected_constraint_name = identifier_converter(constraint_name) editor.execute( editor.sql_create_index % { "table": editor.quote_name(table), @@ -2138,22 +2135,20 @@ class SchemaTests(TransactionTestCase): "condition": "", } ) - if connection.features.uppercases_column_names: - constraint_name = constraint_name.upper() - self.assertIn(constraint_name, self.get_constraints(model._meta.db_table)) + self.assertIn(expected_constraint_name, self.get_constraints(model._meta.db_table)) editor.alter_field(model, get_field(db_index=True), field, strict=True) - self.assertNotIn(constraint_name, self.get_constraints(model._meta.db_table)) + self.assertNotIn(expected_constraint_name, self.get_constraints(model._meta.db_table)) - constraint_name = "CamelCaseUniqConstraint" + constraint_name = 'CamelCaseUniqConstraint' + expected_constraint_name = identifier_converter(constraint_name) editor.execute(editor._create_unique_sql(model, [field.column], constraint_name)) - if connection.features.uppercases_column_names: - constraint_name = constraint_name.upper() - self.assertIn(constraint_name, self.get_constraints(model._meta.db_table)) + self.assertIn(expected_constraint_name, self.get_constraints(model._meta.db_table)) editor.alter_field(model, get_field(unique=True), field, strict=True) - self.assertNotIn(constraint_name, self.get_constraints(model._meta.db_table)) + self.assertNotIn(expected_constraint_name, self.get_constraints(model._meta.db_table)) if editor.sql_foreign_key_constraint: - constraint_name = "CamelCaseFKConstraint" + constraint_name = 'CamelCaseFKConstraint' + expected_constraint_name = identifier_converter(constraint_name) fk_sql = editor.sql_foreign_key_constraint % { "column": editor.quote_name(column), "to_table": editor.quote_name(table), @@ -2170,11 +2165,9 @@ class SchemaTests(TransactionTestCase): "constraint": constraint_sql, } ) - if connection.features.uppercases_column_names: - constraint_name = constraint_name.upper() - self.assertIn(constraint_name, self.get_constraints(model._meta.db_table)) + self.assertIn(expected_constraint_name, self.get_constraints(model._meta.db_table)) editor.alter_field(model, get_field(Author, CASCADE, field_class=ForeignKey), field, strict=True) - self.assertNotIn(constraint_name, self.get_constraints(model._meta.db_table)) + self.assertNotIn(expected_constraint_name, self.get_constraints(model._meta.db_table)) def test_add_field_use_effective_default(self): """ @@ -2491,11 +2484,7 @@ class SchemaTests(TransactionTestCase): new_field.set_attributes_from_name('weight') with connection.schema_editor() as editor: editor.alter_field(Author, old_field, new_field, strict=True) - - expected = 'schema_author_weight_587740f9' - if connection.features.uppercases_column_names: - expected = expected.upper() - self.assertEqual(self.get_constraints_for_column(Author, 'weight'), [expected]) + self.assertEqual(self.get_constraints_for_column(Author, 'weight'), ['schema_author_weight_587740f9']) # Remove db_index=True to drop index. with connection.schema_editor() as editor: diff --git a/tests/select_for_update/tests.py b/tests/select_for_update/tests.py index a750dc61db..f359dc2650 100644 --- a/tests/select_for_update/tests.py +++ b/tests/select_for_update/tests.py @@ -113,11 +113,10 @@ class SelectForUpdateTests(TransactionTestCase): )) features = connections['default'].features if features.select_for_update_of_column: - expected = ['"select_for_update_person"."id"', '"select_for_update_country"."id"'] + expected = ['select_for_update_person"."id', 'select_for_update_country"."id'] else: - expected = ['"select_for_update_person"', '"select_for_update_country"'] - if features.uppercases_column_names: - expected = [value.upper() for value in expected] + expected = ['select_for_update_person', 'select_for_update_country'] + expected = [connection.ops.quote_name(value) for value in expected] self.assertTrue(self.has_for_update_sql(ctx.captured_queries, of=expected)) @skipUnlessDBFeature('has_select_for_update_of') |
