2018-10-26 07:39:42 +08: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-07-12 14:22:40 +08:00
|
|
|
@skipUnless(connection.vendor == "oracle", "Requires oracledb to be installed")
|
2018-10-26 07:39:42 +08:00
|
|
|
class OracleDbshellTests(SimpleTestCase):
|
2020-10-05 06:25:29 +08:00
|
|
|
def settings_to_cmd_args_env(self, settings_dict, parameters=None, rlwrap=False):
|
2020-04-14 15:56:40 +08:00
|
|
|
if parameters is None:
|
|
|
|
parameters = []
|
2020-10-05 06:25:29 +08: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 07:39:42 +08:00
|
|
|
|
|
|
|
def test_without_rlwrap(self):
|
2020-10-05 06:25:29 +08:00
|
|
|
expected_args = [
|
|
|
|
"sqlplus",
|
|
|
|
"-L",
|
|
|
|
connection.client.connect_string(connection.settings_dict),
|
|
|
|
]
|
2018-10-26 07:39:42 +08:00
|
|
|
self.assertEqual(
|
2020-10-05 06:25:29 +08:00
|
|
|
self.settings_to_cmd_args_env(connection.settings_dict, rlwrap=False),
|
|
|
|
(expected_args, None),
|
2018-10-26 07:39:42 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_with_rlwrap(self):
|
2020-10-05 06:25:29 +08:00
|
|
|
expected_args = [
|
|
|
|
"/usr/bin/rlwrap",
|
|
|
|
"sqlplus",
|
|
|
|
"-L",
|
|
|
|
connection.client.connect_string(connection.settings_dict),
|
|
|
|
]
|
2018-10-26 07:39:42 +08:00
|
|
|
self.assertEqual(
|
2020-10-05 06:25:29 +08:00
|
|
|
self.settings_to_cmd_args_env(connection.settings_dict, rlwrap=True),
|
|
|
|
(expected_args, None),
|
2018-10-26 07:39:42 +08:00
|
|
|
)
|
2020-04-14 15:56:40 +08:00
|
|
|
|
|
|
|
def test_parameters(self):
|
2020-10-05 06:25:29 +08:00
|
|
|
expected_args = [
|
|
|
|
"sqlplus",
|
|
|
|
"-L",
|
|
|
|
connection.client.connect_string(connection.settings_dict),
|
|
|
|
"-HELP",
|
|
|
|
]
|
2020-04-14 15:56:40 +08:00
|
|
|
self.assertEqual(
|
2020-10-05 06:25:29 +08:00
|
|
|
self.settings_to_cmd_args_env(
|
|
|
|
connection.settings_dict,
|
|
|
|
parameters=["-HELP"],
|
|
|
|
),
|
|
|
|
(expected_args, None),
|
2020-04-14 15:56:40 +08:00
|
|
|
)
|