Fix some tests that broke when adding descriptions for sql scripts

This commit is contained in:
Pete Keen 2011-06-12 12:54:57 -07:00
parent b78a249b52
commit bf2fcaf2ee
5 changed files with 19 additions and 16 deletions

View File

@ -37,7 +37,7 @@ class TestAPI(Pathed):
def test_script_sql(self): def test_script_sql(self):
repo = self.tmp_repos() repo = self.tmp_repos()
api.create(repo, 'temp') api.create(repo, 'temp')
api.script_sql('postgres', repo) api.script_sql('postgres', 'desc', repo)
def test_version(self): def test_version(self):
repo = self.tmp_repos() repo = self.tmp_repos()
@ -48,7 +48,7 @@ class TestAPI(Pathed):
repo = self.tmp_repos() repo = self.tmp_repos()
api.create(repo, 'temp') api.create(repo, 'temp')
api.script('first version', repo) api.script('first version', repo)
api.script_sql('default', repo) api.script_sql('default', 'desc', repo)
# no repository # no repository
self.assertRaises(UsageError, api.source, 1) self.assertRaises(UsageError, api.source, 1)
@ -95,7 +95,7 @@ class TestSchemaAPI(fixture.DB, Pathed):
out = api.upgrade(self.url, self.repo, preview_sql=True) out = api.upgrade(self.url, self.repo, preview_sql=True)
api.upgrade(self.url, self.repo, 1) api.upgrade(self.url, self.repo, 1)
api.script_sql('default', self.repo) api.script_sql('default', 'desc', self.repo)
self.assertRaises(UsageError, api.upgrade, self.url, self.repo, 2, preview_py=True) self.assertRaises(UsageError, api.upgrade, self.url, self.repo, 2, preview_py=True)
out = api.upgrade(self.url, self.repo, 2, preview_sql=True) out = api.upgrade(self.url, self.repo, 2, preview_sql=True)

View File

@ -127,14 +127,14 @@ class TestShellCommands(Shell):
repos = self.tmp_repos() repos = self.tmp_repos()
result = self.env.run('migrate create %s repository_name' % repos) result = self.env.run('migrate create %s repository_name' % repos)
result = self.env.run('migrate script_sql mydb %s' % repos) result = self.env.run('migrate script_sql mydb foo %s' % repos)
self.assert_(os.path.exists('%s/versions/001_mydb_upgrade.sql' % repos)) self.assert_(os.path.exists('%s/versions/001_foo_mydb_upgrade.sql' % repos))
self.assert_(os.path.exists('%s/versions/001_mydb_downgrade.sql' % repos)) self.assert_(os.path.exists('%s/versions/001_foo_mydb_downgrade.sql' % repos))
# Test creating a second # Test creating a second
result = self.env.run('migrate script_sql postgres --repository=%s' % repos) result = self.env.run('migrate script_sql postgres foo --repository=%s' % repos)
self.assert_(os.path.exists('%s/versions/002_postgres_upgrade.sql' % repos)) self.assert_(os.path.exists('%s/versions/002_foo_postgres_upgrade.sql' % repos))
self.assert_(os.path.exists('%s/versions/002_postgres_downgrade.sql' % repos)) self.assert_(os.path.exists('%s/versions/002_foo_postgres_downgrade.sql' % repos))
# TODO: test --previews # TODO: test --previews

View File

@ -58,7 +58,7 @@ class TestTemplate(fixture.Pathed):
kw['templates_theme'] = 'custom' kw['templates_theme'] = 'custom'
api.create(new_repo_dest, 'repo_name', **kw) api.create(new_repo_dest, 'repo_name', **kw)
api.script('test', new_repo_dest, **kw) api.script('test', new_repo_dest, **kw)
api.script_sql('postgres', new_repo_dest, **kw) api.script_sql('postgres', 'foo', new_repo_dest, **kw)
api.manage(new_manage_dest, **kw) api.manage(new_manage_dest, **kw)
# assert changes # assert changes
@ -66,5 +66,5 @@ class TestTemplate(fixture.Pathed):
self.assertEqual(open(os.path.join(new_repo_dest, 'manage.py')).read(), MANAGE_CONTENTS) self.assertEqual(open(os.path.join(new_repo_dest, 'manage.py')).read(), MANAGE_CONTENTS)
self.assertEqual(open(os.path.join(new_repo_dest, 'README')).read(), README_CONTENTS) self.assertEqual(open(os.path.join(new_repo_dest, 'README')).read(), README_CONTENTS)
self.assertEqual(open(os.path.join(new_repo_dest, 'versions/001_test.py')).read(), SCRIPT_FILE_CONTENTS) self.assertEqual(open(os.path.join(new_repo_dest, 'versions/001_test.py')).read(), SCRIPT_FILE_CONTENTS)
self.assertEqual(open(os.path.join(new_repo_dest, 'versions/002_postgres_downgrade.sql')).read(), SCRIPT_FILE_CONTENTS) self.assertEqual(open(os.path.join(new_repo_dest, 'versions/002_foo_postgres_downgrade.sql')).read(), SCRIPT_FILE_CONTENTS)
self.assertEqual(open(os.path.join(new_repo_dest, 'versions/002_postgres_upgrade.sql')).read(), SCRIPT_FILE_CONTENTS) self.assertEqual(open(os.path.join(new_repo_dest, 'versions/002_foo_postgres_upgrade.sql')).read(), SCRIPT_FILE_CONTENTS)

View File

@ -89,8 +89,8 @@ class TestVersion(fixture.Pathed):
"""Let's see how we handle versions collection""" """Let's see how we handle versions collection"""
coll = Collection(self.temp_usable_dir) coll = Collection(self.temp_usable_dir)
coll.create_new_python_version("foo bar") coll.create_new_python_version("foo bar")
coll.create_new_sql_version("postgres") coll.create_new_sql_version("postgres", "foo bar")
coll.create_new_sql_version("sqlite") coll.create_new_sql_version("sqlite", "foo bar")
coll.create_new_python_version("") coll.create_new_python_version("")
self.assertEqual(coll.latest, 4) self.assertEqual(coll.latest, 4)
@ -118,7 +118,7 @@ class TestVersion(fixture.Pathed):
def test_create_new_sql_version(self): def test_create_new_sql_version(self):
coll = Collection(self.temp_usable_dir) coll = Collection(self.temp_usable_dir)
coll.create_new_sql_version("sqlite") coll.create_new_sql_version("sqlite", "foo bar")
ver = coll.version() ver = coll.version()
ver_up = ver.script('sqlite', 'upgrade') ver_up = ver.script('sqlite', 'upgrade')

View File

@ -202,7 +202,10 @@ class Version(object):
if match: if match:
basename = basename.replace('.sql', '') basename = basename.replace('.sql', '')
parts = basename.split('_') parts = basename.split('_')
assert len(parts) >= 3 if len(parts) < 3:
raise exceptions.ScriptError(
"Invalid SQL script name %s " % basename + \
"(needs to be ###_description_database_operation.sql)")
version = parts[0] version = parts[0]
op = parts[-1] op = parts[-1]
dbms = parts[-2] dbms = parts[-2]