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_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_format_a_message_up(self): migration = MigrationWrapper(migration_file=hello_world) message = FormatterMessage(migration).message(method="down") expected_message = """ 0.0.1 - hello_world.py migrate all the world of test greetings world down - roolback the world """ self.assertTextEqual(expected_message.strip(), message.strip())
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_format_message_of_error(self): migration = MigrationWrapper(migration_file=exception) message = FormatterMessage(migration).message_error( method="down", error="integer division or modulo by zero") expected_message = """ \x1b[31m\n0.0.4 - exception.py Test for raise a exception down - Rollback and raise exception integer division or modulo by zero\x1b[0m """ self.assertTextEqual(expected_message.strip(), message.strip())
class TestMigrationWrapper(UnitTestCase): def setUp(self): self.migration = MigrationWrapper(hello_world) def test_should_execute_up_method_of_migration_and_get_message(self): with self.get_stdout() as stdout: self.migration.up() self.assertEqual("HeLo World\n", stdout.getvalue()) def test_should_not_execute_up_method(self): migration = MigrationWrapper(hello_world, execute=False) with self.get_stdout() as stdout: migration.up() self.assertNotEqual("HeLo World\n", stdout.getvalue()) def test_should_execute_down_method_of_migration_and_get_message(self): with self.get_stdout() as stdout: self.migration.down() self.assertEqual("Bye World\n", stdout.getvalue()) def test_should_not_execute_method_down_if_parameter_execute_is_equal_false(self): migration = MigrationWrapper(hello_world, execute=False) with self.get_stdout() as stdout: migration.down() self.assertNotEqual("Bye World\n", stdout.getvalue()) def test_should_execute_doc_up_and_get_docstring_of_method_up_in_migration(self): expected_doc = "HeLo World\nand migrate the world" self.assertEqual(expected_doc, self.migration.doc_up()) def test_should_execute_doc_down_and_get_docstring_of_method_down_in_migration(self): expected_doc = "roolback the world" self.assertEqual(expected_doc, self.migration.doc_down()) def test_should_get_the_version_of_migration(self): expected_version = "0.0.1" self.assertEqual(expected_version, self.migration.version) def test_should_get_the_name_of_migration_file(self): filename = "hello_world.py" self.assertEqual(filename, self.migration.filename()) def test_should_show_represent_of_migration(self): self.assertEqual("hello_world.py", repr(self.migration)) def test_should_get_the_message_no_docstring_founded_if_developer_not_implemented_docstring_in_migration(self): expected_message = "No docstring founded" migration = MigrationWrapper(without_docstring) self.assertEqual(expected_message, migration.header()) self.assertEqual(expected_message, migration.doc_up()) self.assertEqual(expected_message, migration.doc_down())
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 test_should_ident_message(self): migration = MigrationWrapper(migration_file=hello_world) message = FormatterMessage(migration).ident(migration.header()) self.assertEqual( " migrate all the world of test\n greetings world", message)
def setUp(self): self.migration = MigrationWrapper(hello_world)
def test_should_get_the_message_no_docstring_founded_if_developer_not_implemented_docstring_in_migration(self): expected_message = "No docstring founded" migration = MigrationWrapper(without_docstring) self.assertEqual(expected_message, migration.header()) self.assertEqual(expected_message, migration.doc_up()) self.assertEqual(expected_message, migration.doc_down())
def test_should_not_execute_method_down_if_parameter_execute_is_equal_false(self): migration = MigrationWrapper(hello_world, execute=False) with self.get_stdout() as stdout: migration.down() self.assertNotEqual("Bye World\n", stdout.getvalue())
def test_should_not_execute_up_method(self): migration = MigrationWrapper(hello_world, execute=False) with self.get_stdout() as stdout: migration.up() self.assertNotEqual("HeLo World\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_downgrade(self): self.assertListEqual([MigrationWrapper(hello_world)], list(self.discover_migrations.down_migrations()))
def test_should_ident_message(self): migration = MigrationWrapper(migration_file=hello_world) message = FormatterMessage(migration).ident(migration.header()) self.assertEqual(" migrate all the world of test\n greetings world", message)