Ticket #21005: 21005-1.2.diff

File 21005-1.2.diff, 2.4 KB (added by Claude Paroz, 11 years ago)
  • tests/schema/tests.py

    diff --git a/tests/schema/tests.py b/tests/schema/tests.py
    index 7c21b58..03c5d79 100644
    a b class SchemaTests(TransactionTestCase):  
    2121    available_apps = []
    2222
    2323    models = [Author, AuthorWithM2M, Book, BookWithSlug, BookWithM2M, Tag, TagIndexed, TagM2MTest, TagUniqueRename, UniqueTest]
    24     no_table_strings = ["no such table", "unknown table", "does not exist"]
    2524
    2625    # Utility functions
    2726
    class SchemaTests(TransactionTestCase):  
    3332        "Deletes all model tables for our models for a clean test environment"
    3433        cursor = connection.cursor()
    3534        connection.disable_constraint_checking()
     35        table_names = connection.introspection.table_names(cursor)
    3636        for model in self.models:
    3737            # Remove any M2M tables first
    3838            for field in model._meta.local_many_to_many:
    3939                with atomic():
    40                     try:
     40                    tbl = field.rel.through._meta.db_table
     41                    if tbl in table_names:
    4142                        cursor.execute(connection.schema_editor().sql_delete_table % {
    42                             "table": connection.ops.quote_name(field.rel.through._meta.db_table),
     43                            "table": connection.ops.quote_name(tbl),
    4344                        })
    44                     except DatabaseError as e:
    45                         if any(s in str(e).lower() for s in self.no_table_strings):
    46                             pass
    47                         else:
    48                             raise
     45                        table_names.remove(tbl)
    4946            # Then remove the main tables
    5047            with atomic():
    51                 try:
     48                tbl = model._meta.db_table
     49                if tbl in table_names:
    5250                    cursor.execute(connection.schema_editor().sql_delete_table % {
    53                         "table": connection.ops.quote_name(model._meta.db_table),
     51                        "table": connection.ops.quote_name(tbl),
    5452                    })
    55                 except DatabaseError as e:
    56                     if any(s in str(e).lower() for s in self.no_table_strings):
    57                         pass
    58                     else:
    59                         raise
     53                    table_names.remove(tbl)
    6054        connection.enable_constraint_checking()
    6155
    6256    def column_classes(self, model):
Back to Top