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