Ejemplo n.º 1
0
    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())
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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())
Ejemplo n.º 4
0
    def test_script_help(self):
        self.init_ptah()

        sys.argv[:] = ['ptah-migrate', '-h', 'ptah.ini']

        try:
            migrate.main()
        except:
            pass

        self._reset_stdout()
        self.assertIn('usage: ptah-migrate [-h] config', self.out.getvalue())
Ejemplo n.º 5
0
    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))
Ejemplo n.º 6
0
    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())
Ejemplo n.º 7
0
    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())