示例#1
0
    def test_execute_list(self, check_output, popen):
        cmd_runner = PSqlCmdRunner("1.2.3.4",
                                   "db_user",
                                   "db_password",
                                   "db_name",
                                   additional_opts="--quick --other-option=1")
        execute_result = cmd_runner.execute([
            "SELECT `column` from `table`;", "SELECT `column2` from `table2`;"
        ])

        check_output.assert_any_call(
            [
                "psql", "--host", "1.2.3.4", "--port", "5432", "--username",
                "db_user", "--quick", "--other-option=1", "--command",
                "SELECT `column` from `table`;"
            ],
            env=SuperdictOf({"PGPASSWORD": "******"}),
        )

        check_output.assert_any_call(
            [
                "psql", "--host", "1.2.3.4", "--port", "5432", "--username",
                "db_user", "--quick", "--other-option=1", "--command",
                "SELECT `column2` from `table2`;"
            ],
            env=SuperdictOf({"PGPASSWORD": "******"}),
        )
示例#2
0
    def test_open_batch_processor_defaults(self, check_output, popen):
        cmd_runner = PSqlCmdRunner(
            "1.2.3.4",
            "db_user",
            "db_password",
            "db_name",
            db_port="5432",
            additional_opts="--quick --other-option=1",
        )
        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(
            [
                "psql",
                "--host",
                "1.2.3.4",
                "--port",
                "5432",
                "--username",
                "db_user",
                "--dbname",
                "db_name",
                "--quiet",
                "--quick",
                "--other-option=1",
            ],
            env=SuperdictOf({"PGPASSWORD": "******"}),
            stdin=subprocess.PIPE,
        )

        # dumper should return the stdin of that process
        assert open_result == popen.return_value.stdin
示例#3
0
    def test_execute(self, check_output, popen):
        """
        execute should execute an arbitrary statement with valid args
        """
        cmd_runner = PSqlCmdRunner(
            "1.2.3.4",
            "db_user",
            "db_password",
            "db_name",
            additional_opts="--quick --other-option=1",
        )
        execute_result = cmd_runner.execute("SELECT `column` from `table`;")

        check_output.assert_called_with(
            [
                "psql",
                "--host",
                "1.2.3.4",
                "--port",
                "5432",
                "--username",
                "db_user",
                "--quick",
                "--other-option=1",
                "--command",
                "SELECT `column` from `table`;",
            ],
            env=SuperdictOf({"PGPASSWORD": "******"}),
        )
示例#4
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 = PSqlCmdRunner(
            "1.2.3.4",
            "db_user",
            "db_password",
            "db_name",
            additional_opts="--quick --other-option=1",
        )
        single_result = cmd_runner.get_single_result("SELECT `column` from `table`;")

        check_output.assert_called_with(
            [
                "psql",
                "--host",
                "1.2.3.4",
                "--port",
                "5432",
                "--username",
                "db_user",
                "--dbname",
                "db_name",
                "-tA",
                "--quick",
                "--other-option=1",
                "--command",
                "SELECT `column` from `table`;",
            ],
            env=SuperdictOf({"PGPASSWORD": "******"}),
        )
        assert single_result == check_output.return_value.decode.return_value
示例#5
0
 def test_cmd_runner_missing_mysql(self):
     with pytest.raises(DependencyError):
         PSqlCmdRunner("1.2.3.4", "user", "password", "name")