From ad0ca59ea7416c54be1fa8d101261d7301db32ad Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Wed, 13 Mar 2024 12:38:17 -0400 Subject: [PATCH 1/2] Fix error when issuing TSO commands Signed-off-by: Timothy Johnson --- CHANGELOG.md | 6 ++++++ src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py | 6 +++++- tests/integration/test_zos_tso.py | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ac9872d..660a9a2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to the Zowe Client Python SDK will be documented in this file. +## Recent Changes + +### Bug Fixes + +- Fixed error when issuing TSO commands [#255](https://github.com/zowe/zowe-client-python-sdk/issues/255) + ## `1.0.0-dev14` ### Bug Fixes diff --git a/src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py b/src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py index 76ed950b..2a882f3f 100644 --- a/src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py +++ b/src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py @@ -10,6 +10,8 @@ Copyright Contributors to the Zowe Project. """ +import json + from zowe.core_for_zowe_sdk import SdkApi, constants @@ -126,7 +128,9 @@ def send_tso_message(self, session_key, message): """ custom_args = self._create_custom_request_arguments() custom_args["url"] = "{}/{}".format(self.request_endpoint, str(session_key)) - custom_args["json"] = {"TSO RESPONSE": {"VERSION": "0100", "DATA": str(message)}} + # z/OSMF TSO API requires json to be formatted in specific way without spaces + request_json = {"TSO RESPONSE": {"VERSION": "0100", "DATA": str(message)}} + custom_args["data"] = json.dumps(request_json, separators=(",", ":")) response_json = self.request_handler.perform_request("PUT", custom_args) return response_json["tsoData"] diff --git a/tests/integration/test_zos_tso.py b/tests/integration/test_zos_tso.py index 01f27ab3..5eb2bbef 100644 --- a/tests/integration/test_zos_tso.py +++ b/tests/integration/test_zos_tso.py @@ -1,4 +1,5 @@ """Integration tests for the Zowe Python SDK z/OS Tso package.""" + import unittest from zowe.core_for_zowe_sdk import ProfileManager @@ -17,6 +18,7 @@ def test_issue_command_should_return_valid_response(self): """Executing the issue_command method should return a valid response from TSO""" command_output = self.tso.issue_command("TIME") self.assertIsInstance(command_output, list) + self.assertIn("TIME", command_output[0]) def test_start_tso_session_should_return_a_session_key(self): """Executing the start_tso_session method should return a valid TSO session key""" From 1f7e150b682d7521b67055f34a82810ef9fb62d8 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Wed, 13 Mar 2024 12:51:20 -0400 Subject: [PATCH 2/2] Add unit test for issue tso command Signed-off-by: Timothy Johnson --- tests/unit/test_zos_tso.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_zos_tso.py b/tests/unit/test_zos_tso.py index adb4ece2..3e36d022 100644 --- a/tests/unit/test_zos_tso.py +++ b/tests/unit/test_zos_tso.py @@ -1,16 +1,16 @@ """Unit tests for the Zowe Python SDK z/OS TSO package.""" -import unittest +from unittest import TestCase, mock from zowe.zos_tso_for_zowe_sdk import Tso -class TestTsoClass(unittest.TestCase): +class TestTsoClass(TestCase): """Tso class unit tests.""" def setUp(self): """Setup fixtures for Tso class.""" - self.connection_dict = { + self.test_profile = { "host": "mock-url.com", "user": "Username", "password": "Password", @@ -20,5 +20,16 @@ def setUp(self): def test_object_should_be_instance_of_class(self): """Created object should be instance of Tso class.""" - tso = Tso(self.connection_dict) + tso = Tso(self.test_profile) self.assertIsInstance(tso, Tso) + + @mock.patch("requests.Session.send") + def test_issue_command(self, mock_send_request): + """Test issuing a command sends a request""" + fake_response = {"servletKey": None, "tsoData": "READY"} + mock_send_request.return_value = mock.Mock( + headers={"Content-Type": "application/json"}, status_code=200, json=lambda: fake_response + ) + + Tso(self.test_profile).issue_command("TIME") + self.assertEqual(mock_send_request.call_count, 3)