diff options
author | Adam Johnson <me@adamj.eu> | 2020-04-14 08:56:40 +0100 |
---|---|---|
committer | Adam Johnson <me@adamj.eu> | 2020-04-14 14:02:51 +0100 |
commit | 5b884d45ac5b76234eca614d90c83b347294c332 (patch) | |
tree | ae2fcde4aa7a1fed16661e711dbab785d5b66d89 /tests/dbshell/test_postgresql.py | |
parent | 8e8c3f964e23e669fc563a74750e51abba4c2e3a (diff) | |
download | django-5b884d45ac5b76234eca614d90c83b347294c332.tar.gz |
Fixed #29501 -- Allowed dbshell to pass options to underlying tool.
Diffstat (limited to 'tests/dbshell/test_postgresql.py')
-rw-r--r-- | tests/dbshell/test_postgresql.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/tests/dbshell/test_postgresql.py b/tests/dbshell/test_postgresql.py index 7047283bb3..6de60eaef2 100644 --- a/tests/dbshell/test_postgresql.py +++ b/tests/dbshell/test_postgresql.py @@ -9,7 +9,7 @@ from django.test import SimpleTestCase class PostgreSqlDbshellCommandTestCase(SimpleTestCase): - def _run_it(self, dbinfo): + def _run_it(self, dbinfo, parameters=None): """ That function invokes the runshell command, while mocking subprocess.run(). It returns a 2-tuple with: @@ -21,8 +21,11 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase): # PostgreSQL environment variables. self.pg_env = {key: env[key] for key in env if key.startswith('PG')} return subprocess.CompletedProcess(self.subprocess_args, 0) + + if parameters is None: + parameters = [] with mock.patch('subprocess.run', new=_mock_subprocess_run): - DatabaseClient.runshell_db(dbinfo) + DatabaseClient.runshell_db(dbinfo, parameters) return self.subprocess_args, self.pg_env def test_basic(self): @@ -104,6 +107,12 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase): ) ) + def test_parameters(self): + self.assertEqual( + self._run_it({'database': 'dbname'}, ['--help']), + (['psql', 'dbname', '--help'], {}), + ) + def test_sigint_handler(self): """SIGINT is ignored in Python and passed to psql to abort queries.""" def _mock_subprocess_run(*args, **kwargs): @@ -114,6 +123,6 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase): # 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({}) + DatabaseClient.runshell_db({}, []) # dbshell restores the original handler. self.assertEqual(sigint_handler, signal.getsignal(signal.SIGINT)) |