diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2018-10-26 01:39:42 +0200 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-10-25 19:39:42 -0400 |
commit | c6525bea9ec3d1d1e73585ca6e3116bb55afb336 (patch) | |
tree | c1b7da006c7ee1ac53854f4b2b6687db2bfd2542 /tests/dbshell | |
parent | 9a88c6dd6aa84a1b35e585faa0058a0996cc7ed7 (diff) | |
download | django-c6525bea9ec3d1d1e73585ca6e3116bb55afb336.tar.gz |
Fixed #29534 -- Made dbshell use rlwrap on Oracle if available.
Diffstat (limited to 'tests/dbshell')
-rw-r--r-- | tests/dbshell/test_oracle.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/dbshell/test_oracle.py b/tests/dbshell/test_oracle.py new file mode 100644 index 0000000000..d236a932ab --- /dev/null +++ b/tests/dbshell/test_oracle.py @@ -0,0 +1,33 @@ +from unittest import mock, skipUnless + +from django.db import connection +from django.db.backends.oracle.client import DatabaseClient +from django.test import SimpleTestCase + + +@skipUnless(connection.vendor == 'oracle', 'Oracle tests') +class OracleDbshellTests(SimpleTestCase): + 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 + + def test_without_rlwrap(self): + self.assertEqual( + self._run_dbshell(rlwrap=False), + ('sqlplus', '-L', connection._connect_string()), + ) + + def test_with_rlwrap(self): + self.assertEqual( + self._run_dbshell(rlwrap=True), + ('/usr/bin/rlwrap', 'sqlplus', '-L', connection._connect_string()), + ) |