summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-11-09 16:16:09 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-11-09 16:16:09 -0500
commit36fa6e4603ba19d6c27b4e4c728a30effa72fdc0 (patch)
tree8201a795140abe5cccdab1abb6847d385a3408dc /tests
parenta9c58f1ca6b3adb7869aba241f3fd5f64ddd279c (diff)
downloadalembic-36fa6e4603ba19d6c27b4e4c728a30effa72fdc0.tar.gz
- test fixup
- get batch mode to fail gracefully, dropping the temp table if the operation fails - finish tutorial
Diffstat (limited to 'tests')
-rw-r--r--tests/requirements.py6
-rw-r--r--tests/test_batch.py32
2 files changed, 37 insertions, 1 deletions
diff --git a/tests/requirements.py b/tests/requirements.py
index 1c2c278..65c59d0 100644
--- a/tests/requirements.py
+++ b/tests/requirements.py
@@ -13,3 +13,9 @@ class DefaultRequirements(SuiteRequirements):
"sqlite",
"firebird"
], "no schema support")
+
+ @property
+ def no_referential_integrity(self):
+ """test will fail if referential integrity is enforced"""
+
+ return exclusions.fails_on_everything_except("sqlite")
diff --git a/tests/test_batch.py b/tests/test_batch.py
index faeff5a..a387792 100644
--- a/tests/test_batch.py
+++ b/tests/test_batch.py
@@ -16,6 +16,8 @@ from sqlalchemy.schema import CreateTable
class BatchApplyTest(TestBase):
+ __requires__ = ('sqlalchemy_08', )
+
def setUp(self):
self.op = Operations(mock.Mock(opts={}))
@@ -257,6 +259,8 @@ class BatchApplyTest(TestBase):
class BatchAPITest(TestBase):
+ __requires__ = ('sqlalchemy_08', )
+
@contextmanager
def _fixture(self):
migration_context = mock.Mock(opts={})
@@ -351,6 +355,7 @@ class BatchAPITest(TestBase):
class BatchRoundTripTest(TestBase):
+ __requires__ = ('sqlalchemy_08', )
__only_on__ = "sqlite"
def setUp(self):
@@ -360,7 +365,8 @@ class BatchRoundTripTest(TestBase):
'foo', self.metadata,
Column('id', Integer, primary_key=True),
Column('data', String(50)),
- Column('x', Integer)
+ Column('x', Integer),
+ mysql_engine='InnoDB'
)
t1.create(self.conn)
@@ -387,6 +393,30 @@ class BatchRoundTripTest(TestBase):
data
)
+ def test_fk_points_to_me_auto(self):
+ self._test_fk_points_to_me("auto")
+
+ # in particular, this tests that the failures
+ # on PG and MySQL result in recovery of the batch system,
+ # e.g. that the _alembic_batch_temp table is dropped
+ @config.requirements.no_referential_integrity
+ def test_fk_points_to_me_recreate(self):
+ self._test_fk_points_to_me("always")
+
+ def _test_fk_points_to_me(self, recreate):
+ bar = Table(
+ 'bar', self.metadata,
+ Column('id', Integer, primary_key=True),
+ Column('foo_id', Integer, ForeignKey('foo.id')),
+ mysql_engine='InnoDB'
+ )
+ bar.create(self.conn)
+ self.conn.execute(bar.insert(), {'id': 1, 'foo_id': 3})
+
+ with self.op.batch_alter_table("foo", recreate=recreate) as batch_op:
+ batch_op.alter_column(
+ 'data', new_column_name='newdata', existing_type=String(50))
+
def test_change_type(self):
with self.op.batch_alter_table("foo") as batch_op:
batch_op.alter_column('data', type_=Integer)