def test_sigint_handler(self):
        """SIGINT is ignored in Python and passed to psql to abort quries."""
        def _mock_subprocess_call(*args):
            handler = signal.getsignal(signal.SIGINT)
            self.assertEqual(handler, signal.SIG_IGN)

        sigint_handler = signal.getsignal(signal.SIGINT)
        # The default handler isn't SIG_IGN.
        self.assertNotEqual(sigint_handler, signal.SIG_IGN)
        with mock.patch('subprocess.check_call', new=_mock_subprocess_call):
            DatabaseClient.runshell_db({})
        # dbshell restores the original handler.
        self.assertEqual(sigint_handler, signal.getsignal(signal.SIGINT))
    def test_sigint_handler(self):
        """SIGINT is ignored in Python and passed to psql to abort quries."""
        def _mock_subprocess_run(*args, **kwargs):
            handler = signal.getsignal(signal.SIGINT)
            self.assertEqual(handler, signal.SIG_IGN)

        sigint_handler = signal.getsignal(signal.SIGINT)
        # The default handler isn't SIG_IGN.
        self.assertNotEqual(sigint_handler, signal.SIG_IGN)
        with mock.patch('subprocess.run', new=_mock_subprocess_run):
            DatabaseClient.runshell_db({})
        # dbshell restores the original handler.
        self.assertEqual(sigint_handler, signal.getsignal(signal.SIGINT))
Example #3
0
 def _run_it(self, dbinfo):
     """
     That function invokes the runshell command, while mocking
     subprocess.run(). It returns a 2-tuple with:
     - The command line list
     - The the value of the PGPASSWORD environment variable, or None.
     """
     def _mock_subprocess_run(*args, env=os.environ, **kwargs):
         self.subprocess_args = list(*args)
         self.pgpassword = env.get('PGPASSWORD')
         return subprocess.CompletedProcess(self.subprocess_args, 0)
     with mock.patch('subprocess.run', new=_mock_subprocess_run):
         DatabaseClient.runshell_db(dbinfo)
     return self.subprocess_args, self.pgpassword
Example #4
0
 def _run_it(self, dbinfo):
     """
     That function invokes the runshell command, while mocking
     subprocess.run(). It returns a 2-tuple with:
     - The command line list
     - The dictionary of PG* environment variables, or {}.
     """
     def _mock_subprocess_run(*args, env=os.environ, **kwargs):
         self.subprocess_args = list(*args)
         # PostgreSQL environment variables.
         self.pg_env = {key: env[key] for key in env if key.startswith('PG')}
         return subprocess.CompletedProcess(self.subprocess_args, 0)
     with mock.patch('subprocess.run', new=_mock_subprocess_run):
         DatabaseClient.runshell_db(dbinfo)
     return self.subprocess_args, self.pg_env
Example #5
0
    def _run_it(self, dbinfo):
        """
        That function invokes the runshell command, while mocking
        subprocess.run(). It returns a 2-tuple with:
        - The command line list
        - The the value of the PGPASSWORD environment variable, or None.
        """
        def _mock_subprocess_run(*args, env=os.environ, **kwargs):
            self.subprocess_args = list(*args)
            self.pgpassword = env.get('PGPASSWORD')
            return subprocess.CompletedProcess(self.subprocess_args, 0)

        with mock.patch('subprocess.run', new=_mock_subprocess_run):
            DatabaseClient.runshell_db(dbinfo)
        return self.subprocess_args, self.pgpassword
Example #6
0
 def _run_it(self, dbinfo):
     """
     That function invokes the runshell command, while mocking
     subprocess.run(). It returns a 2-tuple with:
     - The command line list
     - The dictionary of PG* environment variables, or {}.
     """
     def _mock_subprocess_run(*args, env=os.environ, **kwargs):
         self.subprocess_args = list(*args)
         # PostgreSQL environment variables.
         self.pg_env = {key: env[key] for key in env if key.startswith('PG')}
         return subprocess.CompletedProcess(self.subprocess_args, 0)
     with mock.patch('subprocess.run', new=_mock_subprocess_run):
         DatabaseClient.runshell_db(dbinfo)
     return self.subprocess_args, self.pg_env
 def _run_it(self, dbinfo):
     """
     That function invokes the runshell command, while mocking
     subprocess.call. It returns a 2-tuple with:
     - The command line list
     - The content of the file pointed by environment PGPASSFILE, or None.
     """
     def _mock_subprocess_call(*args):
         self.subprocess_args = list(*args)
         if 'PGPASSFILE' in os.environ:
             with open(os.environ['PGPASSFILE']) as f:
                 self.pgpass = f.read().strip()  # ignore line endings
         else:
             self.pgpass = None
         return 0
     self.subprocess_args = None
     self.pgpass = None
     with mock.patch('subprocess.call', new=_mock_subprocess_call):
         DatabaseClient.runshell_db(dbinfo)
     return self.subprocess_args, self.pgpass
Example #8
0
    def _run_it(self, dbinfo):
        """
        That function invokes the runshell command, while mocking
        subprocess.call. It returns a 2-tuple with:
        - The command line list
        - The content of the file pointed by environment PGPASSFILE, or None.
        """
        def _mock_subprocess_call(*args):
            self.subprocess_args = list(*args)
            if 'PGPASSFILE' in os.environ:
                with open(os.environ['PGPASSFILE'], 'r') as f:
                    self.pgpass = f.read().strip()  # ignore line endings
            else:
                self.pgpass = None
            return 0

        self.subprocess_args = None
        self.pgpass = None
        with mock.patch('subprocess.call', new=_mock_subprocess_call):
            DatabaseClient.runshell_db(dbinfo)
        return self.subprocess_args, self.pgpass