summaryrefslogtreecommitdiff
path: root/tests/dbshell/test_oracle.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/dbshell/test_oracle.py')
-rw-r--r--tests/dbshell/test_oracle.py50
1 files changed, 30 insertions, 20 deletions
diff --git a/tests/dbshell/test_oracle.py b/tests/dbshell/test_oracle.py
index 41fbc07455..34e96fb09b 100644
--- a/tests/dbshell/test_oracle.py
+++ b/tests/dbshell/test_oracle.py
@@ -1,4 +1,3 @@
-from subprocess import CompletedProcess
from unittest import mock, skipUnless
from django.db import connection
@@ -6,37 +5,48 @@ from django.db.backends.oracle.client import DatabaseClient
from django.test import SimpleTestCase
-@skipUnless(connection.vendor == 'oracle', 'Oracle tests')
+@skipUnless(connection.vendor == 'oracle', 'Requires cx_Oracle to be installed')
class OracleDbshellTests(SimpleTestCase):
- def _run_dbshell(self, rlwrap=False, parameters=None):
- """Run runshell command and capture its arguments."""
- def _mock_subprocess_run(*args, **kwargs):
- self.subprocess_args = list(*args)
- return CompletedProcess(self.subprocess_args, 0)
-
+ def settings_to_cmd_args_env(self, settings_dict, parameters=None, rlwrap=False):
if parameters is None:
parameters = []
- 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(parameters)
- return self.subprocess_args
+ with mock.patch('shutil.which', return_value='/usr/bin/rlwrap' if rlwrap else None):
+ return DatabaseClient.settings_to_cmd_args_env(settings_dict, parameters)
def test_without_rlwrap(self):
+ expected_args = [
+ 'sqlplus',
+ '-L',
+ connection.client.connect_string(connection.settings_dict),
+ ]
self.assertEqual(
- self._run_dbshell(rlwrap=False),
- ['sqlplus', '-L', connection._connect_string()],
+ self.settings_to_cmd_args_env(connection.settings_dict, rlwrap=False),
+ (expected_args, None),
)
def test_with_rlwrap(self):
+ expected_args = [
+ '/usr/bin/rlwrap',
+ 'sqlplus',
+ '-L',
+ connection.client.connect_string(connection.settings_dict),
+ ]
self.assertEqual(
- self._run_dbshell(rlwrap=True),
- ['/usr/bin/rlwrap', 'sqlplus', '-L', connection._connect_string()],
+ self.settings_to_cmd_args_env(connection.settings_dict, rlwrap=True),
+ (expected_args, None),
)
def test_parameters(self):
+ expected_args = [
+ 'sqlplus',
+ '-L',
+ connection.client.connect_string(connection.settings_dict),
+ '-HELP',
+ ]
self.assertEqual(
- self._run_dbshell(parameters=['-HELP']),
- ['sqlplus', '-L', connection._connect_string(), '-HELP'],
+ self.settings_to_cmd_args_env(
+ connection.settings_dict,
+ parameters=['-HELP'],
+ ),
+ (expected_args, None),
)