summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-04-21 23:08:00 +0200
committerClaude Paroz <claude@2xlibre.net>2014-04-21 23:08:00 +0200
commitab90c4707bc8c813962658350b2e6c13ea0b4711 (patch)
tree17ed2caa72b95dede0f585bfcfa57321c72525c4
parent1667e736a7da634bbda0df171bb60a980cbab7a3 (diff)
Fixed table cleanup in GIS migration tests
-rw-r--r--django/contrib/gis/tests/gis_migrations/test_operations.py25
-rw-r--r--tests/migrations/test_operations.py6
2 files changed, 17 insertions, 14 deletions
diff --git a/django/contrib/gis/tests/gis_migrations/test_operations.py b/django/contrib/gis/tests/gis_migrations/test_operations.py
index 2655b2c61c..61e4d3b69f 100644
--- a/django/contrib/gis/tests/gis_migrations/test_operations.py
+++ b/django/contrib/gis/tests/gis_migrations/test_operations.py
@@ -6,6 +6,7 @@ from django.contrib.gis.tests.utils import HAS_SPATIAL_DB
from django.db import connection, migrations, models
from django.db.migrations.migration import Migration
from django.db.migrations.state import ProjectState
+from django.db.utils import DatabaseError
from django.test import TransactionTestCase
if HAS_SPATIAL_DB:
@@ -21,6 +22,19 @@ if HAS_SPATIAL_DB:
class OperationTests(TransactionTestCase):
available_apps = ["django.contrib.gis.tests.gis_migrations"]
+ def tearDown(self):
+ # Delete table after testing
+ with connection.cursor() as cursor:
+ try:
+ cursor.execute("DROP TABLE %s" % connection.ops.quote_name("gis_neighborhood"))
+ except DatabaseError:
+ pass
+ else:
+ if HAS_GEOMETRY_COLUMNS:
+ cursor.execute("DELETE FROM geometry_columns WHERE %s = %%s" % (
+ GeometryColumns.table_name_col(),), ["gis_neighborhood"])
+ super(OperationTests, self).tearDown()
+
def get_table_description(self, table):
with connection.cursor() as cursor:
return connection.introspection.get_table_description(cursor, table)
@@ -38,17 +52,6 @@ class OperationTests(TransactionTestCase):
return migration.apply(project_state, editor)
def set_up_test_model(self):
- # Delete the tables if they already exist
- with connection.cursor() as cursor:
- try:
- cursor.execute("DROP TABLE %s" % connection.ops.quote_name("gis_neighborhood"))
- except:
- pass
- else:
- if HAS_GEOMETRY_COLUMNS:
- cursor.execute("DELETE FROM geometry_columns WHERE %s = %%s" % (
- GeometryColumns.table_name_col(),), ["gis_neighborhood"])
-
operations = [migrations.CreateModel(
"Neighborhood",
[
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index ec0d046df8..e1b4682d58 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -5,7 +5,7 @@ from django.db.migrations.migration import Migration
from django.db.migrations.state import ProjectState
from django.db.models.fields import NOT_PROVIDED
from django.db.transaction import atomic
-from django.db.utils import IntegrityError
+from django.db.utils import IntegrityError, DatabaseError
from .test_base import MigrationTestBase
@@ -37,11 +37,11 @@ class OperationTests(MigrationTestBase):
with connection.cursor() as cursor:
try:
cursor.execute("DROP TABLE %s_pony" % app_label)
- except:
+ except DatabaseError:
pass
try:
cursor.execute("DROP TABLE %s_stable" % app_label)
- except:
+ except DatabaseError:
pass
# Make the "current" state
operations = [migrations.CreateModel(