def test_history(self): from ptah.migrate import revision, upgrade ptah.register_migration('test1', 'test1:path', 'Test migration') ptah.register_migration('test2', 'test2:path', 'Test migration') self.init_ptah() revision('test1', message='test1 step') revision('test2', message='test2 step') upgrade('test1') upgrade('test2') sys.argv[:] = ['ptah-migrate', 'ptah.ini', 'history', 'test1'] migrate.main() self.assertIn('test1 step', self.out.getvalue()) sys.argv[:] = ['ptah-migrate', 'ptah.ini', 'history'] migrate.main() self.assertIn('test1 step', self.out.getvalue()) self.assertIn('test2 step', self.out.getvalue())
def test_register_conflict(self): ptah.register_migration('test', 'ptah.tests:migrations', 'Ptah database migration') ptah.register_migration('test', 'ptah.tests:migrations', 'Ptah database migration') self.assertRaises(ConfigurationConflictError, self.init_ptah)
def test_upgrade_several(self): from ptah.migrate import revision, Version ptah.register_migration('test1', 'test1:path', 'Test migration') ptah.register_migration('test2', 'test2:path', 'Test migration') self.init_ptah() versions = dict((v.package, v.version_num) for v in ptah.get_session().query(Version).all()) rev1 = revision('test1') rev2 = revision('test2') sys.argv[:] = ['ptah-migrate', 'ptah.ini', 'upgrade', 'test1', 'test2'] migrate.main() self._reset_stdout() versions = dict((v.package, v.version_num) for v in ptah.get_session().query(Version).all()) self.assertIn('test1', versions) self.assertIn('test2', versions) self.assertEqual(versions['test1'], rev1) self.assertEqual(versions['test2'], rev2)
def test_history(self): from ptah.migrate import revision, upgrade, Version ptah.register_migration('test1', 'test1:path', 'Test migration') ptah.register_migration('test2', 'test2:path', 'Test migration') self.init_ptah() rev1 = revision('test1', message='test1 step') rev2 = revision('test2', message='test2 step') upgrade('test1') upgrade('test2') sys.argv[:] = ['ptah-migrate', 'ptah.ini', 'history', 'test1'] migrate.main() self.assertIn('test1 step', self.out.getvalue()) sys.argv[:] = ['ptah-migrate', 'ptah.ini', 'history'] migrate.main() self.assertIn('test1 step', self.out.getvalue()) self.assertIn('test2 step', self.out.getvalue())
def test_register_conflict(self): ptah.register_migration( 'test', 'ptah.tests:migrations', 'Ptah database migration') ptah.register_migration( 'test', 'ptah.tests:migrations', 'Ptah database migration') self.assertRaises(ConfigurationConflictError, self.init_ptah)
def test_doesnt_exist(self): from alembic.util import CommandError from ptah.migrate import ScriptDirectory ptah.register_migration('test', 'ptah:unknown_migrations') self.init_ptah() self.assertRaises(CommandError, ScriptDirectory, 'test')
def test_register_conflict(self): from ptah.migrate import MIGRATION_ID ptah.register_migration( 'test', 'ptah.tests:migrations', 'Ptah database migration') ptah.register_migration( 'test', 'ptah.tests:migrations', 'Ptah database migration') self.assertRaises(ConfigurationConflictError, self.init_ptah)
def test_register(self): from ptah.migrate import MIGRATION_ID ptah.register_migration('test', 'ptah.tests:migrations', 'Ptah database migration') self.init_ptah() st = ptah.get_cfg_storage(MIGRATION_ID) self.assertIn('test', st) self.assertEqual(st['test'], 'ptah.tests:migrations')
def test_list_migrations(self): ptah.register_migration('test', 'test:path', 'Test migration') self.init_ptah() sys.argv[:] = ['ptah-migrate', 'ptah.ini', 'list'] migrate.main() self._reset_stdout() self.assertIn('* test: Test migration', self.out.getvalue())
def test_register(self): from ptah.migrate import MIGRATION_ID ptah.register_migration( 'test', 'ptah.tests:migrations', 'Ptah database migration') self.init_ptah() st = ptah.get_cfg_storage(MIGRATION_ID) self.assertIn('test', st) self.assertEqual(st['test'], 'ptah.tests:migrations')
def test_revision(self): from ptah.migrate import revision, Version ptah.register_migration('test', 'test:path', 'Test migration') self.init_ptah() sys.argv[:] = ['ptah-migrate', 'ptah.ini', 'revision', 'test', '-r', '001', '-m', 'Test message'] migrate.main() path = self.dirs['test'] self.assertIn('001.py', os.listdir(path))
def test_revision(self): ptah.register_migration('test', 'test:path', 'Test migration') self.init_ptah() sys.argv[:] = [ 'ptah-migrate', 'ptah.ini', 'revision', 'test', '-r', '001', '-m', 'Test message' ] migrate.main() path = self.dirs['test'] self.assertIn('001.py', os.listdir(path))
def test_revision_error(self): ptah.register_migration('test', 'test:path', 'Test migration') self.init_ptah() sys.argv[:] = [ 'ptah-migrate', 'ptah.ini', 'revision', 'test', '-r', '0.0;1', '-m', 'Test message' ] migrate.main() self._reset_stdout() self.assertIn('Revision id contains forbidden characters', self.out.getvalue())
def test_revision_error(self): from ptah.migrate import revision, Version ptah.register_migration('test', 'test:path', 'Test migration') self.init_ptah() sys.argv[:] = ['ptah-migrate', 'ptah.ini', 'revision', 'test', '-r', '0.0;1', '-m', 'Test message'] migrate.main() self._reset_stdout() self.assertIn('Revision id contains forbidden characters', self.out.getvalue())
def test_upgrade_to_head_by_default(self): from ptah.migrate import Version, revision, upgrade ptah.register_migration('test', 'ptah.tests:migrations', force=True) self.init_ptah() revision('test', message='Test message1') rev2 = revision('test', message='Test message2') upgrade('test') versions = dict((v.package, v.version_num) for v in ptah.get_session().query(Version).all()) self.assertEqual(versions['test'], rev2)
def test_update_force(self): from ptah.migrate import Version, revision, update_versions ptah.register_migration('test', 'ptah.tests:migrations', force=True) self.init_ptah() revision('test', message='Test message') update_versions(self.registry) session = ptah.get_session() versions = dict( (v.package, v.version_num) for v in session.query(Version).all()) self.assertNotIn('test', versions)
def test_upgrade_to_head_by_default(self): from ptah.migrate import Version, revision, upgrade ptah.register_migration( 'test', 'ptah.tests:migrations', force=True) self.init_ptah() rev1 = revision('test', message='Test message1') rev2 = revision('test', message='Test message2') upgrade('test') versions = dict((v.package, v.version_num) for v in ptah.get_session().query(Version).all()) self.assertEqual(versions['test'], rev2)
def test_update_versions(self): from ptah.migrate import Version, revision, update_versions ptah.register_migration('test', 'ptah.tests:migrations') self.init_ptah() rev = revision('test', message='Test message') update_versions(self.registry) session = ptah.get_session() versions = dict((v.package, v.version_num) for v in session.query(Version).all()) self.assertIn('test', versions) self.assertEqual(versions['test'], rev)
def test_startup_check_version_exit(self): from ptah.migrate import revision, check_version ptah.register_migration('test1', 'ptah.tests1:migrations') ptah.register_migration('test2', 'ptah.tests2:migrations') self.init_ptah() revision('test1', message='Test message1') revision('test2', message='Test message2') exc = None try: check_version(None) except SystemExit as err: # pragma: no cover exc = err self.assertIsInstance(exc, SystemExit)
def test_current_one(self): from ptah.migrate import revision, upgrade ptah.register_migration('test1', 'test1:path', 'Test migration') ptah.register_migration('test2', 'test2:path', 'Test migration') self.init_ptah() rev1 = revision('test1', message='test1 step') revision('test2', message='test2 step') upgrade('test1') sys.argv[:] = ['ptah-migrate', 'ptah.ini', 'current', 'test1'] migrate.main() self.assertIn("Package 'test1' rev: %s(head) test1 step" % rev1, self.out.getvalue())
def test_current_one(self): from ptah.migrate import revision, upgrade, Version ptah.register_migration('test1', 'test1:path', 'Test migration') ptah.register_migration('test2', 'test2:path', 'Test migration') self.init_ptah() rev1 = revision('test1', message='test1 step') rev2 = revision('test2', message='test2 step') upgrade('test1') sys.argv[:] = ['ptah-migrate', 'ptah.ini', 'current', 'test1'] migrate.main() self.assertIn("Package 'test1' rev: %s(head) test1 step"%rev1, self.out.getvalue())
def test_startup_check_version_exit(self): from ptah.migrate import Version, revision, check_version ptah.register_migration( 'test1', 'ptah.tests1:migrations') ptah.register_migration( 'test2', 'ptah.tests2:migrations') self.init_ptah() rev1 = revision('test1', message='Test message1') rev2 = revision('test2', message='Test message2') exc = None try: check_version(None) except SystemExit as err: # pragma: no cover exc = err self.assertIsInstance(exc, SystemExit)
def test_update_version_exists(self): from ptah.migrate import Version, revision, update_versions ptah.register_migration('test', 'ptah.tests:migrations') self.init_ptah() revision('test', message='Test message') session = ptah.get_session() session.add(Version(package='test', version_num='123')) session.flush() update_versions(self.registry) versions = dict( (v.package, v.version_num) for v in session.query(Version).all()) self.assertIn('test', versions) self.assertEqual(versions['test'], '123')
def test_startup_check_version(self): from ptah.migrate import Version, revision, check_version ptah.register_migration('test1', 'ptah.tests1:migrations') ptah.register_migration('test2', 'ptah.tests2:migrations') self.init_ptah() rev1 = revision('test1', message='Test message1') rev2 = revision('test2', message='Test message2') session = ptah.get_session() session.add(Version(package='test1', version_num=rev1)) session.add(Version(package='test2', version_num=rev2)) session.flush() exc = None try: check_version(None) except SystemExit as err: # pragma: no cover exc = err self.assertIsNone(exc)
def test_startup_check_version(self): from ptah.migrate import Version, revision, check_version ptah.register_migration( 'test1', 'ptah.tests1:migrations') ptah.register_migration( 'test2', 'ptah.tests2:migrations') self.init_ptah() rev1 = revision('test1', message='Test message1') rev2 = revision('test2', message='Test message2') session = ptah.get_session() session.add(Version(package='test1', version_num=rev1)) session.add(Version(package='test2', version_num=rev2)) session.flush() exc = None try: check_version(None) except SystemExit as err: # pragma: no cover exc = err self.assertIsNone(exc)
import os import ptah import shutil import tempfile from pyramid.config import ConfigurationConflictError ptah.register_migration('ptah', 'ptah:tests/migrations') class TestRegisterMigration(ptah.PtahTestCase): _init_ptah = False _auto_commit = False def test_register(self): from ptah.migrate import MIGRATION_ID ptah.register_migration('test', 'ptah.tests:migrations', 'Ptah database migration') self.init_ptah() st = ptah.get_cfg_storage(MIGRATION_ID) self.assertIn('test', st) self.assertEqual(st['test'], 'ptah.tests:migrations') def test_register_conflict(self): ptah.register_migration('test', 'ptah.tests:migrations', 'Ptah database migration') ptah.register_migration('test', 'ptah.tests:migrations', 'Ptah database migration')
import os import ptah import shutil import tempfile from pyramid.config import ConfigurationConflictError ptah.register_migration('ptah', 'ptah:tests/migrations') class TestRegisterMigration(ptah.PtahTestCase): _init_ptah = False def test_register(self): from ptah.migrate import MIGRATION_ID ptah.register_migration( 'test', 'ptah.tests:migrations', 'Ptah database migration') self.init_ptah() st = ptah.get_cfg_storage(MIGRATION_ID) self.assertIn('test', st) self.assertEqual(st['test'], 'ptah.tests:migrations') def test_register_conflict(self): from ptah.migrate import MIGRATION_ID ptah.register_migration( 'test', 'ptah.tests:migrations', 'Ptah database migration') ptah.register_migration(