Fixed #21005 -- Made schema tests language-independent
Thanks Simon Charette for the review.
This commit is contained in:
parent
11cd7388f7
commit
b04f8ddbaa
|
@ -21,7 +21,6 @@ class SchemaTests(TransactionTestCase):
|
||||||
available_apps = []
|
available_apps = []
|
||||||
|
|
||||||
models = [Author, AuthorWithM2M, Book, BookWithSlug, BookWithM2M, Tag, TagIndexed, TagM2MTest, TagUniqueRename, UniqueTest]
|
models = [Author, AuthorWithM2M, Book, BookWithSlug, BookWithM2M, Tag, TagIndexed, TagM2MTest, TagUniqueRename, UniqueTest]
|
||||||
no_table_strings = ["no such table", "unknown table", "does not exist"]
|
|
||||||
|
|
||||||
# Utility functions
|
# Utility functions
|
||||||
|
|
||||||
|
@ -33,30 +32,25 @@ class SchemaTests(TransactionTestCase):
|
||||||
"Deletes all model tables for our models for a clean test environment"
|
"Deletes all model tables for our models for a clean test environment"
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
connection.disable_constraint_checking()
|
connection.disable_constraint_checking()
|
||||||
|
table_names = connection.introspection.table_names(cursor)
|
||||||
for model in self.models:
|
for model in self.models:
|
||||||
# Remove any M2M tables first
|
# Remove any M2M tables first
|
||||||
for field in model._meta.local_many_to_many:
|
for field in model._meta.local_many_to_many:
|
||||||
with atomic():
|
with atomic():
|
||||||
try:
|
tbl = field.rel.through._meta.db_table
|
||||||
|
if tbl in table_names:
|
||||||
cursor.execute(connection.schema_editor().sql_delete_table % {
|
cursor.execute(connection.schema_editor().sql_delete_table % {
|
||||||
"table": connection.ops.quote_name(field.rel.through._meta.db_table),
|
"table": connection.ops.quote_name(tbl),
|
||||||
})
|
})
|
||||||
except DatabaseError as e:
|
table_names.remove(tbl)
|
||||||
if any(s in str(e).lower() for s in self.no_table_strings):
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
# Then remove the main tables
|
# Then remove the main tables
|
||||||
with atomic():
|
with atomic():
|
||||||
try:
|
tbl = model._meta.db_table
|
||||||
|
if tbl in table_names:
|
||||||
cursor.execute(connection.schema_editor().sql_delete_table % {
|
cursor.execute(connection.schema_editor().sql_delete_table % {
|
||||||
"table": connection.ops.quote_name(model._meta.db_table),
|
"table": connection.ops.quote_name(tbl),
|
||||||
})
|
})
|
||||||
except DatabaseError as e:
|
table_names.remove(tbl)
|
||||||
if any(s in str(e).lower() for s in self.no_table_strings):
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
connection.enable_constraint_checking()
|
connection.enable_constraint_checking()
|
||||||
|
|
||||||
def column_classes(self, model):
|
def column_classes(self, model):
|
||||||
|
|
Loading…
Reference in New Issue