Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when issuing TSO commands #257

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

### Enhancements
Expand Down
6 changes: 5 additions & 1 deletion src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
Copyright Contributors to the Zowe Project.
"""

import json

from zowe.core_for_zowe_sdk import SdkApi, constants


Expand Down Expand Up @@ -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"]

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/test_zos_tso.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"""
Expand Down
19 changes: 15 additions & 4 deletions tests/unit/test_zos_tso.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change the test description to something like should ... ?

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)