Ejemplo n.º 1
0
    def test_db_execute(self, check_output, popen):
        """
        execute should execute an arbitrary statement with valid args
        """
        cmd_runner = MySqlCmdRunner(
            "1.2.3.4",
            "db_user",
            "db_password",
            "db_name",
            db_port="3306",
            additional_opts="--quick --single-transaction",
        )
        execute_result = cmd_runner.db_execute("SELECT `column` from `table`;")

        check_output.assert_called_with([
            "mysql",
            "-h",
            "1.2.3.4",
            "-P",
            "3306",
            "-u",
            "db_user",
            "-pdb_password",
            "--quick",
            "--single-transaction",
            "db_name",
            "--execute",
            "SELECT `column` from `table`;",
        ])
Ejemplo n.º 2
0
    def test_get_single_result(self, check_output, popen):
        """
        execute should execute an arbitrary statement and return the decoded, no-column result
        """
        cmd_runner = MySqlCmdRunner(
            "1.2.3.4",
            "db_user",
            "db_password",
            "db_name",
            db_port="3306",
            additional_opts="--quick --single-transaction",
        )
        single_result = cmd_runner.get_single_result(
            "SELECT `column` from `table`;")

        check_output.assert_called_with([
            "mysql",
            "-h",
            "1.2.3.4",
            "-P",
            "3306",
            "-u",
            "db_user",
            "-pdb_password",
            "-sN",
            "--quick",
            "--single-transaction",
            "db_name",
            "--execute",
            "SELECT `column` from `table`;",
        ])
        assert single_result == check_output.return_value.decode.return_value
Ejemplo n.º 3
0
    def test_open_batch_processor(self, check_output, popen):
        cmd_runner = MySqlCmdRunner(
            "1.2.3.4",
            "db_user",
            "db_password",
            "db_name",
            db_port="3306",
            additional_opts="--quick --single-transaction",
        )
        open_result = cmd_runner.open_batch_processor()

        # dumper should open a process for the current db dump, piping stdout for processing
        popen.assert_called_with(
            [
                "mysql",
                "-h",
                "1.2.3.4",
                "-P",
                "3306",
                "-u",
                "db_user",
                "-pdb_password",
                "--quick",
                "--single-transaction",
                "db_name",
            ],
            stdin=subprocess.PIPE,
        )

        # dumper should return the stdin of that process
        assert open_result == popen.return_value.stdin
Ejemplo n.º 4
0
    def test_execute(self, check_output, popen):
        """
        execute should execute an arbitrary statement with valid args
        """
        cmd_runner = MySqlCmdRunner("1.2.3.4", "db_user", "db_password",
                                    "db_name")
        execute_result = cmd_runner.execute("SELECT `column` from `table`;")

        check_output.assert_called_with([
            "mysql", "-h", "1.2.3.4", "-P", "3306", "-u", "db_user",
            "-pdb_password", "--execute", "SELECT `column` from `table`;"
        ])
Ejemplo n.º 5
0
    def test_execute_list(self, check_output, popen):
        cmd_runner = MySqlCmdRunner("1.2.3.4", "db_user", "db_password",
                                    "db_name")
        execute_result = cmd_runner.execute([
            "SELECT `column` from `table`;", "SELECT `column2` from `table2`;"
        ])

        check_output.assert_any_call([
            "mysql", "-h", "1.2.3.4", "-P", "3306", "-u", "db_user",
            "-pdb_password", "--execute", "SELECT `column` from `table`;"
        ])

        check_output.assert_any_call([
            "mysql", "-h", "1.2.3.4", "-P", "3306", "-u", "db_user",
            "-pdb_password", "--execute", "SELECT `column2` from `table2`;"
        ])
Ejemplo n.º 6
0
    def test_db_execute_list(self, check_output, popen):
        cmd_runner = MySqlCmdRunner(
            "1.2.3.4",
            "db_user",
            "db_password",
            "db_name",
            db_port="3306",
            additional_opts="--quick --single-transaction",
        )
        execute_result = cmd_runner.db_execute([
            "SELECT `column` from `table`;", "SELECT `column2` from `table2`;"
        ])

        check_output.assert_any_call([
            "mysql",
            "-h",
            "1.2.3.4",
            "-P",
            "3306",
            "-u",
            "db_user",
            "-pdb_password",
            "--quick",
            "--single-transaction",
            "db_name",
            "--execute",
            "SELECT `column` from `table`;",
        ])
        check_output.assert_any_call([
            "mysql",
            "-h",
            "1.2.3.4",
            "-P",
            "3306",
            "-u",
            "db_user",
            "-pdb_password",
            "--quick",
            "--single-transaction",
            "db_name",
            "--execute",
            "SELECT `column2` from `table2`;",
        ])
Ejemplo n.º 7
0
 def test_cmd_runner_missing_mysql(self):
     with pytest.raises(DependencyError):
         MySqlCmdRunner("1.2.3.4", "user", "password", "name")