Ejemplo n.º 1
0
 def test_it_should_show_info_message_and_exit(self, msg_mock):
     try:
         CLI.info_and_exit("info test message, dont mind about it :)")
         self.fail("it should not get here")
     except:
         pass
     msg_mock.assert_called_with("info test message, dont mind about it :)\n", "BLUE")
Ejemplo n.º 2
0
 def test_it_should_show_error_message_and_exit(self, msg_mock):
     try:
         CLI.error_and_exit("error test message, dont mind about it :)")
         self.fail("it should not get here")
     except:
         pass
     msg_mock.assert_called_with("[ERROR] error test message, dont mind about it :)\n", "RED")
Ejemplo n.º 3
0
 def test_it_should_show_error_message_and_exit(self, msg_mock):
     try:
         CLI.error_and_exit("error test message, dont mind about it :)")
         self.fail("it should not get here")
     except:
         pass
     msg_mock.assert_called_with(
         "[ERROR] error test message, dont mind about it :)\n", "RED")
Ejemplo n.º 4
0
 def test_it_should_accept_force_files_options(self):
     self.assertEqual(
         True,
         CLI.parse(["--force-files"])[0].force_use_files_on_down)
     self.assertEqual(
         True,
         CLI.parse(["--force-use-files-on-down"
                    ])[0].force_use_files_on_down)
Ejemplo n.º 5
0
 def test_it_should_show_info_message_and_exit(self, msg_mock):
     try:
         CLI.info_and_exit("info test message, dont mind about it :)")
         self.fail("it should not get here")
     except:
         pass
     msg_mock.assert_called_with(
         "info test message, dont mind about it :)\n", "BLUE")
Ejemplo n.º 6
0
 def test_it_should_accept_schema_version_options(self):
     self.assertEqual(
         "schema_version_value",
         CLI.parse(["-m", "schema_version_value"])[0].schema_version)
     self.assertEqual(
         "schema_version_value",
         CLI.parse(["--migration",
                    "schema_version_value"])[0].schema_version)
Ejemplo n.º 7
0
 def test_it_should_define_colors_values_when_asked_to_show_collors(self):
     CLI.show_colors()
     self.assertEqual("\033[35m", CLI.color["PINK"])
     self.assertEqual("\033[34m", CLI.color["BLUE"])
     self.assertEqual("\033[36m", CLI.color["CYAN"])
     self.assertEqual("\033[32m", CLI.color["GREEN"])
     self.assertEqual("\033[33m", CLI.color["YELLOW"])
     self.assertEqual("\033[31m", CLI.color["RED"])
     self.assertEqual("\033[0m", CLI.color["END"])
Ejemplo n.º 8
0
 def test_it_should_define_colors_values_when_asked_to_show_collors(self):
     CLI.show_colors()
     self.assertEqual("\033[35m", CLI.color["PINK"])
     self.assertEqual("\033[34m", CLI.color["BLUE"])
     self.assertEqual("\033[36m", CLI.color["CYAN"])
     self.assertEqual("\033[32m", CLI.color["GREEN"])
     self.assertEqual("\033[33m", CLI.color["YELLOW"])
     self.assertEqual("\033[31m", CLI.color["RED"])
     self.assertEqual("\033[0m", CLI.color["END"])
Ejemplo n.º 9
0
 def test_it_should_accept_force_old_migrations_options(self):
     self.assertEqual(
         True,
         CLI.parse(["--force-old-migrations"
                    ])[0].force_execute_old_migrations_versions)
     self.assertEqual(
         True,
         CLI.parse(["--force-execute-old-migrations-versions"
                    ])[0].force_execute_old_migrations_versions)
Ejemplo n.º 10
0
 def test_it_should_accept_new_migration_options(self):
     self.assertEqual(
         "new_migration_value",
         CLI.parse(["-n", "new_migration_value"])[0].new_migration)
     self.assertEqual(
         "new_migration_value",
         CLI.parse(["--new", "new_migration_value"])[0].new_migration)
     self.assertEqual(
         "new_migration_value",
         CLI.parse(["--create", "new_migration_value"])[0].new_migration)
Ejemplo n.º 11
0
    def test_it_should_exit_with_help_options(self, stdout_mock):
        try:
            CLI.parse(["-h"])
        except SystemExit as e:
            self.assertEqual(0, e.code)
            self.assertTrue(stdout_mock.getvalue().find("Displays simple-db-migrate's version and exit") > 0)

        stdout_mock.buf = ''
        try:
            CLI.parse(["--help"])
        except SystemExit as e:
            self.assertEqual(0, e.code)
Ejemplo n.º 12
0
class CLITest(unittest.TestCase):
    def setUp(self):
        self.color = CLI.color

    def tearDown(self):
        CLI.color = self.color

    def test_it_should_define_colors_values_as_empty_strings_by_default(self):
        self.assertEqual("", CLI.color["PINK"])
        self.assertEqual("", CLI.color["BLUE"])
        self.assertEqual("", CLI.color["CYAN"])
        self.assertEqual("", CLI.color["GREEN"])
        self.assertEqual("", CLI.color["YELLOW"])
        self.assertEqual("", CLI.color["RED"])
        self.assertEqual("", CLI.color["END"])

    def test_it_should_define_colors_values_when_asked_to_show_collors(self):
        CLI.show_colors()
        self.assertEqual("\033[35m", CLI.color["PINK"])
        self.assertEqual("\033[34m", CLI.color["BLUE"])
        self.assertEqual("\033[36m", CLI.color["CYAN"])
        self.assertEqual("\033[32m", CLI.color["GREEN"])
        self.assertEqual("\033[33m", CLI.color["YELLOW"])
        self.assertEqual("\033[31m", CLI.color["RED"])
        self.assertEqual("\033[0m", CLI.color["END"])

    @patch('sys.stdout', new_callable=StringIO)
    def test_it_should_exit_with_help_options(self, stdout_mock):
        try:
            CLI.parse(["-h"])
        except SystemExit, e:
            self.assertEqual(0, e.code)
            self.assertTrue(stdout_mock.getvalue().find(
                "Displays simple-db-migrate's version and exit") > 0)

        stdout_mock.buf = ''
        try:
            CLI.parse(["--help"])
        except SystemExit, e:
            self.assertEqual(0, e.code)
Ejemplo n.º 13
0
 def test_it_should_has_a_default_value_for_log_level(self):
     self.assertEqual(1, CLI.parse([])[0].log_level)
Ejemplo n.º 14
0
 def test_it_should_accept_new_migration_options(self):
     self.assertEqual("new_migration_value", CLI.parse(["-n", "new_migration_value"])[0].new_migration)
     self.assertEqual("new_migration_value", CLI.parse(["--new", "new_migration_value"])[0].new_migration)
     self.assertEqual("new_migration_value", CLI.parse(["--create", "new_migration_value"])[0].new_migration)
Ejemplo n.º 15
0
 def test_it_should_call_print_statment_with_the_given_message_and_color_codes_when_colors_are_on(
         self, stdout_mock):
     CLI.show_colors()
     CLI.msg("message to print")
     self.assertEqual("\x1b[36mmessage to print\x1b[0m\n",
                      stdout_mock.getvalue())
Ejemplo n.º 16
0
 def test_it_should_not_has_a_default_value_for_configuration_file(self):
     self.assertEqual(None, CLI.parse([])[0].config_file)
Ejemplo n.º 17
0
 def test_it_should_accept_database_version_table_options(self):
     self.assertEqual(
         "version_table_value",
         CLI.parse(["--db-version-table",
                    "version_table_value"])[0].database_version_table)
Ejemplo n.º 18
0
 def test_it_should_not_has_a_default_value_for_database_name(self):
     self.assertEqual(None, CLI.parse([])[0].database_name)
Ejemplo n.º 19
0
 def test_it_should_accept_migrations_dir_options(self):
     self.assertEqual(".:../:/tmp", CLI.parse(["--db-migrations-dir", ".:../:/tmp"])[0].database_migrations_dir)
Ejemplo n.º 20
0
 def test_it_should_accept_paused_mode_options(self):
     self.assertEqual(True, CLI.parse(["-p"])[0].paused_mode)
     self.assertEqual(True, CLI.parse(["--paused-mode"])[0].paused_mode)
Ejemplo n.º 21
0
 def test_it_should_accept_database_password_options(self):
     self.assertEqual("password_value", CLI.parse(["--db-password", "password_value"])[0].database_password)
Ejemplo n.º 22
0
 def test_it_should_accept_log_dir_options(self):
     self.assertEqual("log_dir_value",
                      CLI.parse(["--log-dir", "log_dir_value"])[0].log_dir)
Ejemplo n.º 23
0
 def test_it_should_accept_database_host_options(self):
     self.assertEqual("host_value", CLI.parse(["--db-host", "host_value"])[0].database_host)
Ejemplo n.º 24
0
 def test_it_should_accept_database_name_options(self):
     self.assertEqual("name_value", CLI.parse(["--db-name", "name_value"])[0].database_name)
Ejemplo n.º 25
0
 def test_it_should_use_color_code_to_the_specified_color(self, stdout_mock):
     CLI.show_colors()
     CLI.msg("message to print", "RED")
     self.assertEqual("\x1b[31mmessage to print\x1b[0m\n", stdout_mock.getvalue())
Ejemplo n.º 26
0
 def test_it_should_call_print_statment_with_the_given_message_and_color_codes_when_colors_are_on(self, stdout_mock):
     CLI.show_colors()
     CLI.msg("message to print")
     self.assertEqual("\x1b[36mmessage to print\x1b[0m\n", stdout_mock.getvalue())
Ejemplo n.º 27
0
 def test_it_should_call_print_statment_with_the_given_message(self, stdout_mock):
     CLI.msg("message to print")
     self.assertEqual("message to print\n", stdout_mock.getvalue())
Ejemplo n.º 28
0
 def test_it_should_accept_database_user_options(self):
     self.assertEqual(
         "user_value",
         CLI.parse(["--db-user", "user_value"])[0].database_user)
Ejemplo n.º 29
0
 def test_it_should_not_has_a_default_value_for_migrations_dir(self):
     self.assertEqual(None, CLI.parse([])[0].database_migrations_dir)
Ejemplo n.º 30
0
 def test_it_should_not_has_a_default_value_for_new_migration(self):
     self.assertEqual(None, CLI.parse([])[0].new_migration)
Ejemplo n.º 31
0
 def test_it_should_accept_database_host_options(self):
     self.assertEqual(
         "host_value",
         CLI.parse(["--db-host", "host_value"])[0].database_host)
Ejemplo n.º 32
0
 def test_it_should_has_a_default_value_for_paused_mode(self):
     self.assertEqual(False, CLI.parse([])[0].paused_mode)
Ejemplo n.º 33
0
 def test_it_should_not_has_a_default_value_for_database_name(self):
     self.assertEqual(None, CLI.parse([])[0].database_name)
Ejemplo n.º 34
0
 def test_it_should_not_has_a_default_value_for_migrations_dir(self):
     self.assertEqual(None, CLI.parse([])[0].database_migrations_dir)
Ejemplo n.º 35
0
 def test_it_should_accept_database_info_options(self):
     self.assertEqual("labels",
                      CLI.parse(["--info", "labels"])[0].info_database)
Ejemplo n.º 36
0
 def test_it_should_not_has_a_default_value_for_configuration_file(self):
     self.assertEqual(None, CLI.parse([])[0].config_file)
Ejemplo n.º 37
0
 def test_it_should_accept_database_port_options(self):
     self.assertEqual(42, CLI.parse(["--db-port", "42"])[0].database_port)
Ejemplo n.º 38
0
 def test_it_should_accept_database_password_options(self):
     self.assertEqual(
         "password_value",
         CLI.parse(["--db-password",
                    "password_value"])[0].database_password)
Ejemplo n.º 39
0
 def test_it_should_accept_configuration_file_options(self):
     self.assertEqual("file.conf", CLI.parse(["-c", "file.conf"])[0].config_file)
     self.assertEqual("file.conf", CLI.parse(["--config", "file.conf"])[0].config_file)
Ejemplo n.º 40
0
 def test_it_should_accept_database_port_options(self):
     self.assertEqual(42, CLI.parse(["--db-port", "42"])[0].database_port)
Ejemplo n.º 41
0
 def test_it_should_has_a_default_value_for_log_level(self):
     self.assertEqual(1, CLI.parse([])[0].log_level)
Ejemplo n.º 42
0
 def test_it_should_accept_database_name_options(self):
     self.assertEqual(
         "name_value",
         CLI.parse(["--db-name", "name_value"])[0].database_name)
Ejemplo n.º 43
0
 def test_it_should_accept_log_level_options(self):
     self.assertEqual("log_level_value", CLI.parse(["-l", "log_level_value"])[0].log_level)
     self.assertEqual("log_level_value", CLI.parse(["--log-level", "log_level_value"])[0].log_level)
Ejemplo n.º 44
0
 def test_it_should_accept_migrations_dir_options(self):
     self.assertEqual(
         ".:../:/tmp",
         CLI.parse(["--db-migrations-dir",
                    ".:../:/tmp"])[0].database_migrations_dir)
Ejemplo n.º 45
0
 def test_it_should_not_has_a_default_value_for_log_dir(self):
     self.assertEqual(None, CLI.parse([])[0].log_dir)
Ejemplo n.º 46
0
 def test_it_should_call_print_statment_with_the_given_message(
         self, stdout_mock):
     CLI.msg("message to print")
     self.assertEqual("message to print\n", stdout_mock.getvalue())
Ejemplo n.º 47
0
 def test_it_should_accept_log_dir_options(self):
     self.assertEqual("log_dir_value", CLI.parse(["--log-dir", "log_dir_value"])[0].log_dir)
Ejemplo n.º 48
0
 def test_it_should_use_color_code_to_the_specified_color(
         self, stdout_mock):
     CLI.show_colors()
     CLI.msg("message to print", "RED")
     self.assertEqual("\x1b[31mmessage to print\x1b[0m\n",
                      stdout_mock.getvalue())
Ejemplo n.º 49
0
 def test_it_should_has_a_default_value_for_force_old_migrations(self):
     self.assertEqual(False, CLI.parse([])[0].force_execute_old_migrations_versions)
Ejemplo n.º 50
0
 def test_it_should_accept_configuration_file_options(self):
     self.assertEqual("file.conf",
                      CLI.parse(["-c", "file.conf"])[0].config_file)
     self.assertEqual("file.conf",
                      CLI.parse(["--config", "file.conf"])[0].config_file)
Ejemplo n.º 51
0
 def test_it_should_accept_force_old_migrations_options(self):
     self.assertEqual(True, CLI.parse(["--force-old-migrations"])[0].force_execute_old_migrations_versions)
     self.assertEqual(True, CLI.parse(["--force-execute-old-migrations-versions"])[0].force_execute_old_migrations_versions)
Ejemplo n.º 52
0
 def test_it_should_accept_log_level_options(self):
     self.assertEqual("log_level_value",
                      CLI.parse(["-l", "log_level_value"])[0].log_level)
     self.assertEqual(
         "log_level_value",
         CLI.parse(["--log-level", "log_level_value"])[0].log_level)
Ejemplo n.º 53
0
 def test_it_should_has_a_default_value_for_force_files(self):
     self.assertEqual(False, CLI.parse([])[0].force_use_files_on_down)
Ejemplo n.º 54
0
 def test_it_should_not_has_a_default_value_for_log_dir(self):
     self.assertEqual(None, CLI.parse([])[0].log_dir)
Ejemplo n.º 55
0
 def test_it_should_accept_force_files_options(self):
     self.assertEqual(True, CLI.parse(["--force-files"])[0].force_use_files_on_down)
     self.assertEqual(True, CLI.parse(["--force-use-files-on-down"])[0].force_use_files_on_down)
Ejemplo n.º 56
0
 def test_it_should_has_a_default_value_for_force_old_migrations(self):
     self.assertEqual(
         False,
         CLI.parse([])[0].force_execute_old_migrations_versions)
Ejemplo n.º 57
0
 def test_it_should_not_has_a_default_value_for_schema_version(self):
     self.assertEqual(None, CLI.parse([])[0].schema_version)
Ejemplo n.º 58
0
 def test_it_should_has_a_default_value_for_force_files(self):
     self.assertEqual(False, CLI.parse([])[0].force_use_files_on_down)
Ejemplo n.º 59
0
 def test_it_should_accept_schema_version_options(self):
     self.assertEqual("schema_version_value", CLI.parse(["-m", "schema_version_value"])[0].schema_version)
     self.assertEqual("schema_version_value", CLI.parse(["--migration", "schema_version_value"])[0].schema_version)