def test_should_return_up_migrations_with_specific_version(self): discover_migrations = DiscovererMigration(version_to='0.0.3') espected_migrations = [ MigrationWrapper(bla_bla_bla), MigrationWrapper(bye_world) ] self.assertListEqual(espected_migrations, list(discover_migrations.to_migrations()))
class TestDiscovererMigration(UnitTestCase): def setUp(self): self.discover_migrations = DiscovererMigration() def test_should_upgrade(self): self.assertEqual([ MigrationWrapper(bla_bla_bla), MigrationWrapper(bye_world), MigrationWrapper(exception), MigrationWrapper(without_docstring)], list(self.discover_migrations.up_migrations())) def test_should_downgrade(self): self.assertListEqual([MigrationWrapper(hello_world)], list(self.discover_migrations.down_migrations())) def test_should_get_migrations_files(self): submodules = self.discover_migrations.migrations_files() self.assertListEqual([hello_world, bla_bla_bla, bye_world, exception, without_docstring], submodules) def test_should_get_migrations_files_in_reverse(self): submodules = self.discover_migrations.migrations_files(reverse=True) self.assertListEqual([without_docstring ,exception, bye_world, bla_bla_bla, hello_world], submodules) 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 test_should_method_is_down(self): discover_migrations = DiscovererMigration(version_to='0.0.0') is_down = discover_migrations.is_down() self.assertTrue(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_not_down(self): discover_migrations = DiscovererMigration(version_to='1.0.0') is_down = discover_migrations.is_down() self.assertFalse(is_down) def test_should_return_up_migrations_with_specific_version(self): discover_migrations = DiscovererMigration(version_to='0.0.3') espected_migrations = [MigrationWrapper(bla_bla_bla), MigrationWrapper(bye_world)] self.assertListEqual(espected_migrations, list(discover_migrations.to_migrations())) 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 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_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())
class TestDiscovererMigrationMidleVersion(UnitTestCase): def setUp(self): self.old_current_version = pymigrations.conf.current_version pymigrations.conf.current_version = lambda: '0.0.2' self.discover_migrations = DiscovererMigration() def tearDown(self): pymigrations.conf.current_version = self.old_current_version def test_should_upgrade(self): self.assertEqual([ MigrationWrapper(bye_world), MigrationWrapper(exception), MigrationWrapper(without_docstring) ], list(self.discover_migrations.up_migrations())) def test_should_downgrade(self): self.assertListEqual( [MigrationWrapper(bla_bla_bla), MigrationWrapper(hello_world)], list(self.discover_migrations.down_migrations()))
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 setUp(self): self.old_current_version = pymigrations.conf.current_version pymigrations.conf.current_version = lambda: '0.0.2' self.discover_migrations = DiscovererMigration()
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 setUp(self): self.discover_migrations = DiscovererMigration()
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)
class TestDiscovererMigrationMidleVersion(UnitTestCase): def setUp(self): self.old_current_version = pymigrations.conf.current_version pymigrations.conf.current_version = lambda: '0.0.2' self.discover_migrations = DiscovererMigration() def tearDown(self): pymigrations.conf.current_version = self.old_current_version def test_should_upgrade(self): self.assertEqual([MigrationWrapper(bye_world), MigrationWrapper(exception), MigrationWrapper(without_docstring)], list(self.discover_migrations.up_migrations())) def test_should_downgrade(self): self.assertListEqual([MigrationWrapper(bla_bla_bla), MigrationWrapper(hello_world)], list(self.discover_migrations.down_migrations()))
def test_should_return_up_migrations_with_specific_version(self): discover_migrations = DiscovererMigration(version_to='0.0.3') espected_migrations = [MigrationWrapper(bla_bla_bla), MigrationWrapper(bye_world)] self.assertListEqual(espected_migrations, list(discover_migrations.to_migrations()))
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())
class TestDiscovererMigration(UnitTestCase): def setUp(self): self.discover_migrations = DiscovererMigration() def test_should_upgrade(self): self.assertEqual([ MigrationWrapper(bla_bla_bla), MigrationWrapper(bye_world), MigrationWrapper(exception), MigrationWrapper(without_docstring) ], list(self.discover_migrations.up_migrations())) def test_should_downgrade(self): self.assertListEqual([MigrationWrapper(hello_world)], list(self.discover_migrations.down_migrations())) def test_should_get_migrations_files(self): submodules = self.discover_migrations.migrations_files() self.assertListEqual([ hello_world, bla_bla_bla, bye_world, exception, without_docstring ], submodules) def test_should_get_migrations_files_in_reverse(self): submodules = self.discover_migrations.migrations_files(reverse=True) self.assertListEqual([ without_docstring, exception, bye_world, bla_bla_bla, hello_world ], submodules) 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 test_should_method_is_down(self): discover_migrations = DiscovererMigration(version_to='0.0.0') is_down = discover_migrations.is_down() self.assertTrue(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_not_down(self): discover_migrations = DiscovererMigration(version_to='1.0.0') is_down = discover_migrations.is_down() self.assertFalse(is_down) def test_should_return_up_migrations_with_specific_version(self): discover_migrations = DiscovererMigration(version_to='0.0.3') espected_migrations = [ MigrationWrapper(bla_bla_bla), MigrationWrapper(bye_world) ] self.assertListEqual(espected_migrations, list(discover_migrations.to_migrations())) 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()))