def test_should_return_message_down(self): migration = MigrationWrapper(hello_world) message = TerminalMessages(DiscovererMigration()) with self.get_stdout() as stdout: message.make_message("down", migration) self.assertTextEqual( """ 0.0.1 - hello_world.py migrate all the world of test greetings world down - roolback the world """, stdout.getvalue())
def test_should_return_message_error_of_down(self): migration = MigrationWrapper(hello_world) message = TerminalMessages(DiscovererMigration()) with self.get_stdout() as stdout: message.error_message("down", migration, "AttributeError") self.assertTextEqual( """ \x1b[31m\n0.0.1 - hello_world.py migrate all the world of test greetings world down - roolback the world AttributeError\x1b[0m """.strip(), stdout.getvalue().strip())
def pymigration(): parser = ArgumentParser(description="Parameters to migrate.") parser.add_argument("-u", "--up", dest="up", default=False, action="store_true", help="Execute python methods to upgrade schema of system.") parser.add_argument("--no-exec", default=True, dest="execute", action="store_false", help="If you want only see the list of migrantions command.") parser.add_argument("-d", "--down", dest="down", default=False, action="store_true", help="Execute python methods to downgrade schema of system.") parser.add_argument("-c", "--current-version", dest="current_version", default=False, help="Version of actual migration.", action="store_true") parser.add_argument("-v", "--version", dest="version", default=False, help="Displays pymigration's version and exit.", action="store_true") parser.add_argument("-t", "--to", dest="version_to", default=None, help="Migrate to specific version .") args = parser.parse_args() migrations = DiscovererMigration(**vars(args)) terminal_message = TerminalMessages(migrations, **vars(args)) if args.version: print version if args.down: migrations = list(migrations.down_migrations()) try: if migrations: for migration in migrations: migration.down() terminal_message.make_message("down", migration) else: print "No migrations need to be executed, already in %s version." % Version().get_current() except Exception, e: terminal_message.error_message("down", migration, e) sys.exit() if args.execute: Version().set_current("0")
def test_should_get_message_of_current_version(self): migrations = DiscovererMigration() terminal_message = TerminalMessages(migrations=migrations) with self.get_stdout() as stdout: terminal_message.current_version() self.assertEqual("0.0.1\n", stdout.getvalue())
def test_should_return_down_migration_with_specific_version(self): discover_migrations = DiscovererMigration(version_to='0.0.0') espected_migrations = [MigrationWrapper(hello_world)] self.assertListEqual(espected_migrations, list(discover_migrations.to_migrations()))
def test_should_method_is_not_down(self): discover_migrations = DiscovererMigration(version_to='1.0.0') is_down = discover_migrations.is_down() self.assertFalse(is_down)
def test_should_method_is_not_up(self): discover_migrations = DiscovererMigration(version_to='0.0.0') is_up = discover_migrations.is_up() self.assertFalse(is_up)
def test_should_method_is_up(self): discover_migrations = DiscovererMigration(version_to='1.0.6') is_up = discover_migrations.is_up() self.assertTrue(is_up)
def setUp(self): self.discover_migrations = DiscovererMigration()
def setUp(self): self.old_current_version = pymigrations.conf.current_version pymigrations.conf.current_version = lambda: '0.0.2' self.discover_migrations = DiscovererMigration()