From 4f43a68ebc0882d38cc7fc863d44a0fb8b437fac Mon Sep 17 00:00:00 2001 From: Uladzislau Date: Thu, 23 Nov 2023 15:49:54 +0100 Subject: [PATCH] GH-231 Now 'issue_command' can use custom console name Signed-off-by: Uladzislau --- CHANGELOG.md | 1 + .../zowe/zos_console_for_zowe_sdk/console.py | 1 + tests/unit/test_zos_console.py | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b72a180..953034a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to the Zowe Client Python SDK will be documented in this fil ### Bug Fixes - Fixed Secrets SDK requiring LD_LIBRARY_PATH to be defined when installed from wheel on Linux [#229](https://github.com/zowe/zowe-client-python-sdk/issues/229) +- Fixed 'issue_command' Console API function to provide custom console name [#231](https://github.com/zowe/zowe-client-python-sdk/issues/231) ## `1.0.0-dev11` diff --git a/src/zos_console/zowe/zos_console_for_zowe_sdk/console.py b/src/zos_console/zowe/zos_console_for_zowe_sdk/console.py index 67365eb4..59817c86 100644 --- a/src/zos_console/zowe/zos_console_for_zowe_sdk/console.py +++ b/src/zos_console/zowe/zos_console_for_zowe_sdk/console.py @@ -40,6 +40,7 @@ def issue_command(self, command, console=None): A JSON containing the response from the console command """ custom_args = self._create_custom_request_arguments() + custom_args["url"] = self.request_endpoint.replace("defcn", console or "defcn") request_body = {"cmd": command} custom_args["json"] = request_body response_json = self.request_handler.perform_request("PUT", custom_args) diff --git a/tests/unit/test_zos_console.py b/tests/unit/test_zos_console.py index d6e1d320..52e05ac2 100644 --- a/tests/unit/test_zos_console.py +++ b/tests/unit/test_zos_console.py @@ -24,6 +24,26 @@ def test_object_should_be_instance_of_class(self): console = Console(self.session_details) self.assertIsInstance(console, Console) + @mock.patch("requests.Session.send") + def test_issue_command_makes_request_to_the_default_console(self, mock_send): + """Issued command should be sent to the correct default console name if no name is specified""" + is_console_name_correct = False + def send_request_side_effect(self, **other_args): + assert "/defcn" in self.url + return mock.Mock(headers={"Content-type": "application/json"}, status_code=200) + mock_send.side_effect = send_request_side_effect + Console(self.session_details).issue_command("TESTCMD") + + @mock.patch("requests.Session.send") + def test_issue_command_makes_request_to_the_custom_console(self, mock_send): + """Issued command should be sent to the correct custom console name if the console name is specified""" + is_console_name_correct = False + def send_request_side_effect(self, **other_args): + assert "/TESTCNSL" in self.url + return mock.Mock(headers={"Content-type": "application/json"}, status_code=200) + mock_send.side_effect = send_request_side_effect + Console(self.session_details).issue_command("TESTCMD", "TESTCNSL") + @mock.patch("requests.Session.send") def test_get_response_should_return_messages(self, mock_send_request): """Getting z/OS Console response messages on sending a response key"""