return a, b, c
+def multi_heads_fixture(cfg, a, b, c):
+ """Create a multiple head fixture from the three-revs fixture"""
+
+ d = util.rev_id()
+ e = util.rev_id()
+ f = util.rev_id()
+
+ script = ScriptDirectory.from_config(cfg)
+ script.generate_revision(
+ d, "revision d from b", head=b, splice=True, refresh=True)
+ write_script(script, d, """\
+"Rev D"
+revision = '%s'
+down_revision = '%s'
+
+from alembic import op
+
+
+def upgrade():
+ op.execute("CREATE STEP 4")
+
+
+def downgrade():
+ op.execute("DROP STEP 4")
+
+""" % (d, b))
+
+ script.generate_revision(
+ e, "revision e from d", head=d, splice=True, refresh=True)
+ write_script(script, e, """\
+"Rev E"
+revision = '%s'
+down_revision = '%s'
+
+from alembic import op
+
+
+def upgrade():
+ op.execute("CREATE STEP 5")
+
+
+def downgrade():
+ op.execute("DROP STEP 5")
+
+""" % (e, d))
+
+ script.generate_revision(
+ f, "revision f from b", head=b, splice=True, refresh=True)
+ write_script(script, f, """\
+"Rev F"
+revision = '%s'
+down_revision = '%s'
+
+from alembic import op
+
+
+def upgrade():
+ op.execute("CREATE STEP 6")
+
+
+def downgrade():
+ op.execute("DROP STEP 6")
+
+""" % (f, b))
+
+ return d, e, f
+
+
def _multidb_testing_config(engines):
"""alembic.ini fixture to work exactly with the 'multidb' template"""
from alembic.testing import assert_raises_message
from alembic.testing.env import staging_env, _no_sql_testing_config, \
- three_rev_fixture, clear_staging_env, env_file_fixture
+ three_rev_fixture, clear_staging_env, env_file_fixture, \
+ multi_heads_fixture
import re
a = b = c = None
command.stamp(self.cfg, b, sql=True)
command.downgrade(self.cfg, "%s:%s" % (c, b), sql=True)
+ def test_destination_rev_pre_context_multihead(self):
+ d, e, f = multi_heads_fixture(self.cfg, a, b, c)
+ env_file_fixture("""
+assert set(context.get_revision_argument()) == set(('%s', '%s', '%s', ))
+""" % (f, e, c))
+ command.upgrade(self.cfg, 'heads', sql=True)
def test_destination_rev_post_context(self):
env_file_fixture("""
command.downgrade(self.cfg, "%s:%s" % (c, b), sql=True)
command.stamp(self.cfg, b, sql=True)
+ def test_destination_rev_post_context_multihead(self):
+ d, e, f = multi_heads_fixture(self.cfg, a, b, c)
+ env_file_fixture("""
+context.configure(dialect_name='sqlite')
+assert set(context.get_revision_argument()) == set(('%s', '%s', '%s', ))
+""" % (f, e, c))
+ command.upgrade(self.cfg, 'heads', sql=True)
+
def test_head_rev_pre_context(self):
env_file_fixture("""
assert context.get_head_revision() == '%s'
-""" % c)
+assert context.get_head_revisions() == ('%s', )
+""" % (c, c))
command.upgrade(self.cfg, b, sql=True)
command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True)
command.stamp(self.cfg, b, sql=True)
command.current(self.cfg)
+ def test_head_rev_pre_context_multihead(self):
+ d, e, f = multi_heads_fixture(self.cfg, a, b, c)
+ env_file_fixture("""
+assert set(context.get_head_revisions()) == set(('%s', '%s', '%s', ))
+""" % (e, f, c))
+ command.upgrade(self.cfg, e, sql=True)
+ command.downgrade(self.cfg, "%s:%s" % (e, b), sql=True)
+ command.stamp(self.cfg, c, sql=True)
+ command.current(self.cfg)
+
def test_head_rev_post_context(self):
env_file_fixture("""
context.configure(dialect_name='sqlite')
assert context.get_head_revision() == '%s'
-""" % c)
+assert context.get_head_revisions() == ('%s', )
+""" % (c, c))
command.upgrade(self.cfg, b, sql=True)
command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True)
command.stamp(self.cfg, b, sql=True)
command.current(self.cfg)
+ def test_head_rev_post_context_multihead(self):
+ d, e, f = multi_heads_fixture(self.cfg, a, b, c)
+ env_file_fixture("""
+context.configure(dialect_name='sqlite')
+assert set(context.get_head_revisions()) == set(('%s', '%s', '%s', ))
+""" % (e, f, c))
+ command.upgrade(self.cfg, e, sql=True)
+ command.downgrade(self.cfg, "%s:%s" % (e, b), sql=True)
+ command.stamp(self.cfg, c, sql=True)
+ command.current(self.cfg)
+
def test_tag_pre_context(self):
env_file_fixture("""
assert context.get_tag_argument() == 'hi'