summaryrefslogtreecommitdiff
path: root/tests/test_script_production.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-11-20 18:08:02 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-11-20 18:08:02 -0500
commit5c747a068b539cec9dd88836427f57352f3f0735 (patch)
tree46fe04c30ee7f7f72d45d5d987868889718095ff /tests/test_script_production.py
parent0b63884a2ce2b4b89f2ddf0db7fba47fce5540f0 (diff)
downloadalembic-5c747a068b539cec9dd88836427f57352f3f0735.tar.gz
- The "multiple heads / branches" feature has now landed. This is
by far the most significant change Alembic has seen since its inception; while the workflow of most commands hasn't changed, and the format of version files and the ``alembic_version`` table are unchanged as well, a new suite of features opens up in the case where multiple version files refer to the same parent, or to the "base". Merging of branches, operating across distinct named heads, and multiple independent bases are now all supported. The feature incurs radical changes to the internals of versioning and traversal, and should be treated as "beta mode" for the next several subsequent releases within 0.7. fixes #167
Diffstat (limited to 'tests/test_script_production.py')
-rw-r--r--tests/test_script_production.py81
1 files changed, 75 insertions, 6 deletions
diff --git a/tests/test_script_production.py b/tests/test_script_production.py
index 2ed0653..647cf5b 100644
--- a/tests/test_script_production.py
+++ b/tests/test_script_production.py
@@ -1,8 +1,9 @@
from alembic.testing.fixtures import TestBase
-from alembic.testing import eq_, ne_, is_
+from alembic.testing import eq_, ne_, is_, assert_raises_message
from alembic.testing.env import clear_staging_env, staging_env, \
_get_staging_directory, _no_sql_testing_config, env_file_fixture, \
- script_file_fixture, _testing_config
+ script_file_fixture, _testing_config, _sqlite_testing_config, \
+ three_rev_fixture
from alembic import command
from alembic.script import ScriptDirectory
from alembic.environment import EnvironmentContext
@@ -72,7 +73,7 @@ class GeneralOrderedTests(TestBase):
'%s_this_is_the_next_rev.py' % def_), os.F_OK)
eq_(script.revision, def_)
eq_(script.down_revision, abc)
- eq_(env._revision_map[abc].nextrev, set([def_]))
+ eq_(env.get_revision(abc).nextrev, set([def_]))
assert script.module.down_revision == abc
assert callable(script.module.upgrade)
assert callable(script.module.downgrade)
@@ -84,8 +85,8 @@ class GeneralOrderedTests(TestBase):
# new ScriptDirectory instance.
env = staging_env(create=False)
- abc_rev = env._revision_map[abc]
- def_rev = env._revision_map[def_]
+ abc_rev = env.get_revision(abc)
+ def_rev = env.get_revision(def_)
eq_(abc_rev.nextrev, set([def_]))
eq_(abc_rev.revision, abc)
eq_(def_rev.down_revision, abc)
@@ -97,7 +98,7 @@ class GeneralOrderedTests(TestBase):
script = env.generate_revision(rid, "dont' refresh")
is_(script, None)
env2 = staging_env(create=False)
- eq_(env2._as_rev_number("head"), rid)
+ eq_(env2.get_current_head(), rid)
def _test_008_long_name(self):
rid = util.rev_id()
@@ -151,6 +152,74 @@ class ScriptNamingTest(TestBase):
)
+class RevisionCommandTest(TestBase):
+ def setUp(self):
+ self.env = staging_env()
+ self.cfg = _sqlite_testing_config()
+ self.a, self.b, self.c = three_rev_fixture(self.cfg)
+
+ def tearDown(self):
+ clear_staging_env()
+
+ def test_create_script_basic(self):
+ rev = command.revision(self.cfg, message="some message")
+ script = ScriptDirectory.from_config(self.cfg)
+ rev = script.get_revision(rev.revision)
+ eq_(rev.down_revision, self.c)
+ assert "some message" in rev.doc
+
+ def test_create_script_splice(self):
+ rev = command.revision(
+ self.cfg, message="some message", head=self.b, splice=True)
+ script = ScriptDirectory.from_config(self.cfg)
+ rev = script.get_revision(rev.revision)
+ eq_(rev.down_revision, self.b)
+ assert "some message" in rev.doc
+ eq_(set(script.get_heads()), set([rev.revision, self.c]))
+
+ def test_create_script_missing_splice(self):
+ assert_raises_message(
+ util.CommandError,
+ "Revision %s is not a head revision; please specify --splice "
+ "to create a new branch from this revision" % self.b,
+ command.revision,
+ self.cfg, message="some message", head=self.b
+ )
+
+ def test_create_script_branches(self):
+ rev = command.revision(
+ self.cfg, message="some message", branch_label="foobar")
+ script = ScriptDirectory.from_config(self.cfg)
+ rev = script.get_revision(rev.revision)
+ eq_(script.get_revision("foobar"), rev)
+
+ def test_create_script_branches_old_template(self):
+ script = ScriptDirectory.from_config(self.cfg)
+ with open(os.path.join(script.dir, "script.py.mako"), "w") as file_:
+ file_.write(
+ "<%text>#</%text> ${message}\n"
+ "revision = ${repr(up_revision)}\n"
+ "down_revision = ${repr(down_revision)}\n"
+ "def upgrade():\n"
+ " ${upgrades if upgrades else 'pass'}\n\n"
+ "def downgrade():\n"
+ " ${downgrade if downgrades else 'pass'}\n\n"
+ )
+
+ # works OK if no branch names
+ command.revision(self.cfg, message="some message")
+
+ assert_raises_message(
+ util.CommandError,
+ r"Version \w+ specified branch_labels foobar, "
+ r"however the migration file .+?\b does not have them; have you "
+ "upgraded your script.py.mako to include the 'branch_labels' "
+ r"section\?",
+ command.revision,
+ self.cfg, message="some message", branch_label="foobar"
+ )
+
+
class TemplateArgsTest(TestBase):
def setUp(self):