def test_should_return_feedback_to_user_when_no_have_migration_to_run( self): Version().set_current("0.0.5") output = shell("pymigration -u") self.assertEqual( "Running command: pymigration -u\nNo migrations need to be executed, already in 0.0.5 version.", output)
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_use_command_to_version_and_raise_exception(self): Version().set_current("0.0.3") output = shell("pymigration --to 0.0.4") self.assertTextEqual( """Running command: pymigration --to 0.0.4 \x1b[31m 0.0.4 - exception.py Test for raise a exception up - Starting exeception integer division or modulo by zero\x1b[0m""", output)
def test_should_use_command_down_and_raise_exception(self): Version().set_current("0.0.4") output = shell("pymigration -d") self.assertTextEqual( """Running command: pymigration -d \x1b[31m 0.0.4 - exception.py Test for raise a exception down - Rollback and raise exception integer division or modulo by zero\x1b[0m""", output)
def tearDown(self): Version().set_current("0.0.1")
def setUp(self): Version().set_current("0.0.1")
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") if args.up: migrations = list(migrations.up_migrations()) try: if migrations: for migration in migrations: migration.up() terminal_message.make_message("up", migration) else: print "No migrations need to be executed, already in %s version." % Version().get_current() except Exception, e: terminal_message.error_message("up", migration, e) if args.current_version: terminal_message.current_version() if args.version_to: for migration in migrations.to_migrations(): if migrations.is_up(): try: migration.up() terminal_message.make_message("up", migration) except Exception, e: terminal_message.error_message("up", migration, e) sys.exit()
def setUp(self): self.version = Version()