Exemplo n.º 1
0
    def _run_dbshell(self, rlwrap=False):
        """Run runshell command and capture its arguments."""
        def _mock_subprocess_call(*args):
            self.subprocess_args = tuple(*args)
            return 0

        client = DatabaseClient(connection)
        self.subprocess_args = None
        with mock.patch('subprocess.call', new=_mock_subprocess_call):
            with mock.patch('shutil.which', return_value='/usr/bin/rlwrap' if rlwrap else None):
                client.runshell()
        return self.subprocess_args
Exemplo n.º 2
0
    def _run_dbshell(self, rlwrap=False):
        """Run runshell command and capture its arguments."""
        def _mock_subprocess_run(*args, **kwargs):
            self.subprocess_args = list(*args)
            return CompletedProcess(self.subprocess_args, 0)

        client = DatabaseClient(connection)
        self.subprocess_args = None
        with mock.patch('subprocess.run', new=_mock_subprocess_run):
            with mock.patch('shutil.which', return_value='/usr/bin/rlwrap' if rlwrap else None):
                client.runshell()
        return self.subprocess_args
Exemplo n.º 3
0
 def test_exec(self):
     client = DatabaseClient(connection)
     run_result = client.runshell(input=b'SELECT * FROM user_tables;',
                                  stdout=PIPE,
                                  stderr=PIPE)
     self.assertTrue(run_result.stdout)
     self.assertFalse(run_result.stderr)