2018-10-26 01:39:42 +02:00
|
|
|
from unittest import mock, skipUnless
|
|
|
|
|
|
|
|
from django.db import connection
|
|
|
|
from django.db.backends.oracle.client import DatabaseClient
|
|
|
|
from django.test import SimpleTestCase
|
|
|
|
|
|
|
|
|
2020-10-05 00:25:29 +02:00
|
|
|
@skipUnless(connection.vendor == "oracle", "Requires cx_Oracle to be installed")
|
2018-10-26 01:39:42 +02:00
|
|
|
class OracleDbshellTests(SimpleTestCase):
|
2020-10-05 00:25:29 +02:00
|
|
|
def settings_to_cmd_args_env(self, settings_dict, parameters=None, rlwrap=False):
|
2020-04-14 09:56:40 +02:00
|
|
|
if parameters is None:
|
|
|
|
parameters = []
|
2020-10-05 00:25:29 +02:00
|
|
|
with mock.patch(
|
|
|
|
"shutil.which", return_value="/usr/bin/rlwrap" if rlwrap else None
|
|
|
|
):
|
|
|
|
return DatabaseClient.settings_to_cmd_args_env(settings_dict, parameters)
|
2018-10-26 01:39:42 +02:00
|
|
|
|
|
|
|
def test_without_rlwrap(self):
|
2020-10-05 00:25:29 +02:00
|
|
|
expected_args = [
|
|
|
|
"sqlplus",
|
|
|
|
"-L",
|
|
|
|
connection.client.connect_string(connection.settings_dict),
|
|
|
|
]
|
2018-10-26 01:39:42 +02:00
|
|
|
self.assertEqual(
|
2020-10-05 00:25:29 +02:00
|
|
|
self.settings_to_cmd_args_env(connection.settings_dict, rlwrap=False),
|
|
|
|
(expected_args, None),
|
2018-10-26 01:39:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_with_rlwrap(self):
|
2020-10-05 00:25:29 +02:00
|
|
|
expected_args = [
|
|
|
|
"/usr/bin/rlwrap",
|
|
|
|
"sqlplus",
|
|
|
|
"-L",
|
|
|
|
connection.client.connect_string(connection.settings_dict),
|
|
|
|
]
|
2018-10-26 01:39:42 +02:00
|
|
|
self.assertEqual(
|
2020-10-05 00:25:29 +02:00
|
|
|
self.settings_to_cmd_args_env(connection.settings_dict, rlwrap=True),
|
|
|
|
(expected_args, None),
|
2018-10-26 01:39:42 +02:00
|
|
|
)
|
2020-04-14 09:56:40 +02:00
|
|
|
|
|
|
|
def test_parameters(self):
|
2020-10-05 00:25:29 +02:00
|
|
|
expected_args = [
|
|
|
|
"sqlplus",
|
|
|
|
"-L",
|
|
|
|
connection.client.connect_string(connection.settings_dict),
|
|
|
|
"-HELP",
|
|
|
|
]
|
2020-04-14 09:56:40 +02:00
|
|
|
self.assertEqual(
|
2020-10-05 00:25:29 +02:00
|
|
|
self.settings_to_cmd_args_env(
|
|
|
|
connection.settings_dict,
|
|
|
|
parameters=["-HELP"],
|
|
|
|
),
|
|
|
|
(expected_args, None),
|
2020-04-14 09:56:40 +02:00
|
|
|
)
|