コード例 #1
0
ファイル: test_migrate.py プロジェクト: sidloki/ptah
    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())
コード例 #2
0
    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)
コード例 #3
0
ファイル: test_migrate.py プロジェクト: webmaven/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)
コード例 #4
0
ファイル: test_migrate.py プロジェクト: sidloki/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)
コード例 #5
0
ファイル: test_migrate.py プロジェクト: webmaven/ptah
    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())
コード例 #6
0
ファイル: test_migrate.py プロジェクト: djedproject/ptah
    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)
コード例 #7
0
ファイル: test_migrate.py プロジェクト: webmaven/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')
コード例 #8
0
    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')
コード例 #9
0
ファイル: test_migrate.py プロジェクト: webmaven/ptah
    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)
コード例 #10
0
    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')
コード例 #11
0
ファイル: test_migrate.py プロジェクト: sidloki/ptah
    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())
コード例 #12
0
ファイル: test_migrate.py プロジェクト: webmaven/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')
コード例 #13
0
ファイル: test_migrate.py プロジェクト: webmaven/ptah
    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())
コード例 #14
0
ファイル: test_migrate.py プロジェクト: webmaven/ptah
    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))
コード例 #15
0
ファイル: test_migrate.py プロジェクト: sidloki/ptah
    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))
コード例 #16
0
ファイル: test_migrate.py プロジェクト: sidloki/ptah
    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())
コード例 #17
0
ファイル: test_migrate.py プロジェクト: webmaven/ptah
    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())
コード例 #18
0
    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)
コード例 #19
0
    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)
コード例 #20
0
ファイル: test_migrate.py プロジェクト: webmaven/ptah
    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)
コード例 #21
0
ファイル: test_migrate.py プロジェクト: webmaven/ptah
    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)
コード例 #22
0
    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)
コード例 #23
0
ファイル: test_migrate.py プロジェクト: sidloki/ptah
    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())
コード例 #24
0
ファイル: test_migrate.py プロジェクト: webmaven/ptah
    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())
コード例 #25
0
ファイル: test_migrate.py プロジェクト: webmaven/ptah
    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)
コード例 #26
0
    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')
コード例 #27
0
    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)
コード例 #28
0
ファイル: test_migrate.py プロジェクト: webmaven/ptah
    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)
コード例 #29
0
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')
コード例 #30
0
ファイル: test_migrate.py プロジェクト: webmaven/ptah
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(