From b686e9af9150ef1f1989e0b8151f72070c985104 Mon Sep 17 00:00:00 2001 From: pem70 Date: Wed, 5 Jun 2024 08:49:50 -0400 Subject: [PATCH 01/12] Fix bug on `issue_command` Signed-off-by: pem70 --- .vscode/settings.json | 3 ++- src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index b378a106..028f87d3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,6 +17,7 @@ "./src/zos_console", "./src/zos_files", "./src/zos_jobs", - "./src/zosmf" + "./src/zosmf", + "./src/zos_tso" ], } 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 53e273c8..8cbf7eec 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 @@ -61,6 +61,11 @@ def issue_command(self, command): session_key = self.start_tso_session() command_output = self.send_tso_message(session_key, command) tso_messages = self.retrieve_tso_messages(command_output) + while not any("TSO PROMPT" in message for message in command_output) or not tso_messages: + custom_args = self._create_custom_request_arguments() + custom_args["url"] = "{}/{}".format(self.request_endpoint, session_key) + command_output = self.request_handler.perform_request("GET", custom_args)["tsoData"] + tso_messages += self.retrieve_tso_messages(command_output) self.end_tso_session(session_key) return tso_messages From 4107faa9b6162ef34d4d6458a840c466d6c67062 Mon Sep 17 00:00:00 2001 From: pem70 Date: Wed, 5 Jun 2024 10:35:22 -0400 Subject: [PATCH 02/12] updated tso unit tests Signed-off-by: pem70 --- src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py | 1 - tests/unit/test_zos_tso.py | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) 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 8cbf7eec..761230b5 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 @@ -11,7 +11,6 @@ """ import json - from zowe.core_for_zowe_sdk import SdkApi, constants diff --git a/tests/unit/test_zos_tso.py b/tests/unit/test_zos_tso.py index 3e36d022..2d2fac29 100644 --- a/tests/unit/test_zos_tso.py +++ b/tests/unit/test_zos_tso.py @@ -26,7 +26,11 @@ def test_object_should_be_instance_of_class(self): @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"} + message = {"TSO MESSAGE": { + "DATA": "READY" + } + } + fake_response = {"servletKey": None, "tsoData": ["TSO PROMPT", message]} mock_send_request.return_value = mock.Mock( headers={"Content-Type": "application/json"}, status_code=200, json=lambda: fake_response ) From dc89d514b9096b239a3f5dd674d5df17a1d8116a Mon Sep 17 00:00:00 2001 From: pem70 Date: Wed, 5 Jun 2024 10:40:36 -0400 Subject: [PATCH 03/12] Update CHANGELOG.md Signed-off-by: pem70 --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 369d069f..5134eb84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,12 @@ All notable changes to the Zowe Client Python SDK will be documented in this fil ### Enhancements - Added classes for handling `Datasets`, `USSFiles`, and `FileSystems` in favor of the single Files class. [#264](https://github.com/zowe/zowe-client-python-sdk/issues/264) -- Refactor testings into proper folders and files and add more tests [#265](https://github.com/zowe/zowe-client-python-sdk/issues/265) -- Fix the bug on `upload_file_to_dsn`. [#104](https://github.com/zowe/zowe-client-python-sdk/issues/104) +- Refactored testings into proper folders and files and add more tests [#265](https://github.com/zowe/zowe-client-python-sdk/issues/265) +- Fixed the bug on `upload_file_to_dsn` [#104](https://github.com/zowe/zowe-client-python-sdk/issues/104) + +### Bug Fixes + +- Fixed truncated responses when issuing TSO commands [#260](https://github.com/zowe/zowe-client-python-sdk/issues/260) ## `1.0.0-dev15` From 8daa8a886eab92459cb702580e35ba8b79791780 Mon Sep 17 00:00:00 2001 From: pem70 Date: Wed, 5 Jun 2024 13:06:47 -0400 Subject: [PATCH 04/12] Update `issue_command` test Signed-off-by: pem70 --- tests/unit/test_zos_tso.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/unit/test_zos_tso.py b/tests/unit/test_zos_tso.py index 2d2fac29..27567e56 100644 --- a/tests/unit/test_zos_tso.py +++ b/tests/unit/test_zos_tso.py @@ -26,14 +26,24 @@ def test_object_should_be_instance_of_class(self): @mock.patch("requests.Session.send") def test_issue_command(self, mock_send_request): """Test issuing a command sends a request""" + expected = ['READY', 'GO'] message = {"TSO MESSAGE": { - "DATA": "READY" + "DATA": expected[0] } } - fake_response = {"servletKey": None, "tsoData": ["TSO PROMPT", message]} - 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) + message2 = {"TSO MESSAGE": { + "DATA": expected[1] + } + } + fake_responses = [ + mock.Mock(headers={"Content-Type": "application/json"}, status_code=200, json=lambda: {"servletKey": None, "tsoData": [ message]}), + mock.Mock(headers={"Content-Type": "application/json"}, status_code=200, json=lambda: {"servletKey": None, "tsoData": [ message]}), + mock.Mock(headers={"Content-Type": "application/json"}, status_code=200, json=lambda: {"servletKey": None, "tsoData": ["TSO PROMPT", message2]}), + mock.Mock(headers={"Content-Type": "application/json"}, status_code=200, json=lambda: {"servletKey": None, "tsoData": [ message]}), + ] + + mock_send_request.side_effect = fake_responses + + result = Tso(self.test_profile).issue_command("TIME") + self.assertEqual(result, expected) + self.assertEqual(mock_send_request.call_count, 4) From a72ef46087d8b1490d66181f3da3d4f4baf4393a Mon Sep 17 00:00:00 2001 From: pem70 Date: Wed, 5 Jun 2024 13:18:59 -0400 Subject: [PATCH 05/12] Update changelog and logger class Signed-off-by: pem70 --- CHANGELOG.md | 1 + src/core/zowe/core_for_zowe_sdk/logger.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5134eb84..c2a86d0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to the Zowe Client Python SDK will be documented in this fil ### Enhancements +- Added logger class to core SDK [#185](https://github.com/zowe/zowe-client-python-sdk/issues/185) - Added classes for handling `Datasets`, `USSFiles`, and `FileSystems` in favor of the single Files class. [#264](https://github.com/zowe/zowe-client-python-sdk/issues/264) - Refactored testings into proper folders and files and add more tests [#265](https://github.com/zowe/zowe-client-python-sdk/issues/265) - Fixed the bug on `upload_file_to_dsn` [#104](https://github.com/zowe/zowe-client-python-sdk/issues/104) diff --git a/src/core/zowe/core_for_zowe_sdk/logger.py b/src/core/zowe/core_for_zowe_sdk/logger.py index 25666ce9..c8909934 100644 --- a/src/core/zowe/core_for_zowe_sdk/logger.py +++ b/src/core/zowe/core_for_zowe_sdk/logger.py @@ -15,11 +15,11 @@ class Log: datefmt="%m/%d/%Y %I:%M:%S %p", ) - loggers = [] + loggers = set() @staticmethod def registerLogger(name: str): logger = logging.getLogger(name) - Log.loggers.append(logger) + Log.loggers.add(logger) return logger @staticmethod From f1b0c57c40888bfe227bb7365dfb5bdf9a4a0ec2 Mon Sep 17 00:00:00 2001 From: pem70 Date: Wed, 5 Jun 2024 13:22:08 -0400 Subject: [PATCH 06/12] Update test_delete.py Signed-off-by: pem70 --- tests/unit/files/datasets/test_delete.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/files/datasets/test_delete.py b/tests/unit/files/datasets/test_delete.py index 1422be9f..460879c4 100644 --- a/tests/unit/files/datasets/test_delete.py +++ b/tests/unit/files/datasets/test_delete.py @@ -26,7 +26,7 @@ def test_delete(self, mock_send_request): mock_send_request.assert_called_once() @mock.patch("requests.Session.send") - def test_delete(self, mock_send_request): + def test_delete_pram(self, mock_send_request): """Test list members sends request""" self.files_instance = Files(self.test_profile) mock_send_request.return_value = mock.Mock(headers={"Content-Type": "application/json"}, status_code=200) From 69788de991b355495e7c02f1a6eb52b914e086b9 Mon Sep 17 00:00:00 2001 From: pem70 Date: Wed, 5 Jun 2024 14:41:15 -0400 Subject: [PATCH 07/12] Update broken integration tests Signed-off-by: pem70 --- src/zos_files/zowe/zos_files_for_zowe_sdk/files.py | 2 +- src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py | 2 +- tests/integration/fixtures/sample.jcl.tmp | 5 ----- tests/integration/test_zos_files.py | 1 - 4 files changed, 2 insertions(+), 8 deletions(-) delete mode 100644 tests/integration/fixtures/sample.jcl.tmp diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py index dc68597b..c76e5e39 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py @@ -121,7 +121,7 @@ def get_dsn_binary_content(self, dataset_name, with_prefixes=False): def get_dsn_binary_content_streamed(self, dataset_name, with_prefixes=False): """Deprecated function. Please use ds.get_binary_content() instead""" - return self.ds.get_binary_content(dataset_name, with_prefixes, stream=True) + return self.ds.get_binary_content(dataset_name, stream=True, with_prefixes=with_prefixes) def write_to_dsn(self, dataset_name, data, encoding=_ZOWE_FILES_DEFAULT_ENCODING): """Deprecated function. Please use ds.write() instead""" diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py index 9175af4d..b464fb02 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py @@ -155,7 +155,7 @@ def upload(self, input_file, filepath_name, encoding=_ZOWE_FILES_DEFAULT_ENCODIN """Upload contents of a given file and uploads it to UNIX file""" if os.path.isfile(input_file): with open(input_file, "r", encoding="utf-8") as in_file: - response_json = self.write(filepath_name, in_file) + response_json = self.write(filepath_name, in_file.read()) else: self.logger.error(f"File {input_file} not found.") raise FileNotFound(input_file) \ No newline at end of file diff --git a/tests/integration/fixtures/sample.jcl.tmp b/tests/integration/fixtures/sample.jcl.tmp deleted file mode 100644 index 39020987..00000000 --- a/tests/integration/fixtures/sample.jcl.tmp +++ /dev/null @@ -1,5 +0,0 @@ -//IEFBR14T JOB (AUTOMATION),CLASS=A,MSGCLASS=0, - -// MSGLEVEL=(1,1),REGION=0M,NOTIFY=&SYSUID - -//STEP1 EXEC PGM=IEFBR14 diff --git a/tests/integration/test_zos_files.py b/tests/integration/test_zos_files.py index 14592936..88195390 100644 --- a/tests/integration/test_zos_files.py +++ b/tests/integration/test_zos_files.py @@ -149,7 +149,6 @@ def test_upload_download_delete_dataset(self): def test_upload_download_delete_uss(self): self.files.upload_file_to_uss(SAMPLE_JCL_FIXTURE_PATH, self.test_uss_upload) self.files.download_uss(self.test_uss_upload, SAMPLE_JCL_FIXTURE_PATH + ".tmp") - with open(SAMPLE_JCL_FIXTURE_PATH, "r") as in_file: old_file_content = in_file.read() with open(SAMPLE_JCL_FIXTURE_PATH + ".tmp", "r") as in_file: From 85d84c827aed11a6ba3293a65f469117dfb40ccf Mon Sep 17 00:00:00 2001 From: pem70 Date: Thu, 6 Jun 2024 13:34:00 -0400 Subject: [PATCH 08/12] Change _ZOWE_FILES_DEFAULT_ENCODING to a constant Signed-off-by: pem70 --- src/zos_files/zowe/zos_files_for_zowe_sdk/constants.py | 1 + src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py | 4 ++-- src/zos_files/zowe/zos_files_for_zowe_sdk/file_system.py | 2 +- src/zos_files/zowe/zos_files_for_zowe_sdk/files.py | 4 ++-- src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py | 3 ++- tests/unit/files/datasets/test_rename.py | 4 ++-- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/constants.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/constants.py index 4e7e7942..5f8268d6 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/constants.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/constants.py @@ -12,6 +12,7 @@ zos_file_constants = { "MaxAllocationQuantity": 16777215, + "ZoweFilesDefaultEncoding": "utf-8", } from enum import Enum diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py index 436406f9..8e867355 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py @@ -14,9 +14,9 @@ from zowe.core_for_zowe_sdk import SdkApi from zowe.core_for_zowe_sdk.exceptions import FileNotFound -from zowe.zos_files_for_zowe_sdk.constants import FileType +from zowe.zos_files_for_zowe_sdk.constants import FileType, zos_file_constants -_ZOWE_FILES_DEFAULT_ENCODING = "utf-8" +_ZOWE_FILES_DEFAULT_ENCODING = zos_file_constants["ZoweFilesDefaultEncoding"] class Datasets(SdkApi): """ diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/file_system.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/file_system.py index c05263b7..844f8bc9 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/file_system.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/file_system.py @@ -14,7 +14,7 @@ from zowe.core_for_zowe_sdk import SdkApi from zowe.zos_files_for_zowe_sdk import constants, exceptions -_ZOWE_FILES_DEFAULT_ENCODING = "utf-8" +_ZOWE_FILES_DEFAULT_ENCODING = constants.zos_file_constants["ZoweFilesDefaultEncoding"] class FileSystems(SdkApi): diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py index c76e5e39..92f7a5ac 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/files.py @@ -12,12 +12,12 @@ from zowe.core_for_zowe_sdk import SdkApi -from zowe.zos_files_for_zowe_sdk.constants import FileType +from zowe.zos_files_for_zowe_sdk.constants import FileType, zos_file_constants from .datasets import Datasets from .uss import USSFiles from .file_system import FileSystems -_ZOWE_FILES_DEFAULT_ENCODING = "utf-8" +_ZOWE_FILES_DEFAULT_ENCODING = zos_file_constants["ZoweFilesDefaultEncoding"] class Files(SdkApi): diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py index b464fb02..6162ce97 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py @@ -14,8 +14,9 @@ from zowe.core_for_zowe_sdk import SdkApi from zowe.core_for_zowe_sdk.exceptions import FileNotFound +from zowe.zos_files_for_zowe_sdk.constants import zos_file_constants -_ZOWE_FILES_DEFAULT_ENCODING = "utf-8" +_ZOWE_FILES_DEFAULT_ENCODING = zos_file_constants["ZoweFilesDefaultEncoding"] class USSFiles(SdkApi): """ diff --git a/tests/unit/files/datasets/test_rename.py b/tests/unit/files/datasets/test_rename.py index 2c42b16d..c3a70b49 100644 --- a/tests/unit/files/datasets/test_rename.py +++ b/tests/unit/files/datasets/test_rename.py @@ -25,7 +25,7 @@ def test_rename_dataset(self, mock_send_request): Files(self.test_profile).rename_dataset("MY.OLD.DSN", "MY.NEW.DSN") mock_send_request.assert_called_once() - def test_rename_dataset_parametrized(self): + def test_rename_dataset_parameterized(self): """Test renaming a dataset with different values""" test_values = [ (("DSN.OLD", "DSN.NEW"), True), @@ -68,7 +68,7 @@ def test_rename_dataset_member_raises_exception(self): Files(self.test_profile).rename_dataset_member("MY.DS.NAME", "MEMBER1", "MEMBER1N", "RANDOM") self.assertEqual(str(e_info.exception), "Invalid value for enq.") - def test_rename_dataset_member_parametrized(self): + def test_rename_dataset_member_parameterized(self): """Test renaming a dataset member with different values""" test_values = [ (("DSN", "MBROLD$", "MBRNEW$", "EXCLU"), True), From 3de32d1db55a57c75f6958409f4898c08036283d Mon Sep 17 00:00:00 2001 From: pem70 Date: Fri, 7 Jun 2024 10:32:11 -0400 Subject: [PATCH 09/12] Revert "Merge branch 'convert_windows_line_ending' into TSO" This reverts commit 2326a4089265a18a119a4eea9e97a4b459942efa, reversing changes made to 85d84c827aed11a6ba3293a65f469117dfb40ccf. Signed-off-by: pem70 --- CHANGELOG.md | 1 - src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py | 1 + tests/unit/files/constants.py | 7 ------- tests/unit/files/datasets/test_copy.py | 13 ++++++++++--- tests/unit/files/datasets/test_create.py | 13 ++++++++++--- tests/unit/files/datasets/test_delete.py | 15 +++++++++++---- tests/unit/files/datasets/test_get.py | 13 ++++++++++--- tests/unit/files/datasets/test_list.py | 14 +++++++++++--- tests/unit/files/datasets/test_migrate.py | 13 ++++++++++--- tests/unit/files/datasets/test_rename.py | 12 +++++++++--- tests/unit/files/datasets/test_write.py | 13 ++++++++++--- .../unit/files/file_systems/test_file_systems.py | 13 ++++++++++--- tests/unit/files/uss/test_uss.py | 13 ++++++++++--- tests/unit/test_zos_console.py | 10 ++++++++-- tests/unit/test_zos_jobs.py | 10 ++++++++-- tests/unit/test_zos_tso.py | 10 ++++++++-- tests/unit/test_zosmf.py | 10 ++++++++-- 17 files changed, 134 insertions(+), 47 deletions(-) delete mode 100644 tests/unit/files/constants.py diff --git a/CHANGELOG.md b/CHANGELOG.md index e0ef7f66..c2a86d0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,6 @@ All notable changes to the Zowe Client Python SDK will be documented in this fil ### Enhancements -- Added logger class to core SDK [#185](https://github.com/zowe/zowe-client-python-sdk/issues/185) - Added logger class to core SDK [#185](https://github.com/zowe/zowe-client-python-sdk/issues/185) - Added classes for handling `Datasets`, `USSFiles`, and `FileSystems` in favor of the single Files class. [#264](https://github.com/zowe/zowe-client-python-sdk/issues/264) - Refactored testings into proper folders and files and add more tests [#265](https://github.com/zowe/zowe-client-python-sdk/issues/265) diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py index abcc3d17..6162ce97 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py @@ -125,6 +125,7 @@ def get_content(self, filepath_name): A JSON with the contents of the specified USS file """ custom_args = self._create_custom_request_arguments() + # custom_args["params"] = {"filepath-name": filepath_name} custom_args["url"] = "{}fs{}".format(self.request_endpoint, filepath_name) response_json = self.request_handler.perform_request("GET", custom_args) return response_json diff --git a/tests/unit/files/constants.py b/tests/unit/files/constants.py deleted file mode 100644 index ea00e7ac..00000000 --- a/tests/unit/files/constants.py +++ /dev/null @@ -1,7 +0,0 @@ -profile = { - "host": "mock-url.com", - "user": "Username", - "password": "Password", - "port": 443, - "rejectUnauthorized": True, - } \ No newline at end of file diff --git a/tests/unit/files/datasets/test_copy.py b/tests/unit/files/datasets/test_copy.py index ab86119b..2e229d31 100644 --- a/tests/unit/files/datasets/test_copy.py +++ b/tests/unit/files/datasets/test_copy.py @@ -1,6 +1,7 @@ +import re from unittest import TestCase, mock -from zowe.zos_files_for_zowe_sdk import Files -from unit.files.constants import profile + +from zowe.zos_files_for_zowe_sdk import Files, exceptions, Datasets class TestCreateClass(TestCase): @@ -8,7 +9,13 @@ class TestCreateClass(TestCase): def setUp(self): """Setup fixtures for File class.""" - self.test_profile = profile + self.test_profile = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } @mock.patch("requests.Session.send") def test_copy_uss_to_dataset(self, mock_send_request): diff --git a/tests/unit/files/datasets/test_create.py b/tests/unit/files/datasets/test_create.py index 5a3b4554..d8d9f44f 100644 --- a/tests/unit/files/datasets/test_create.py +++ b/tests/unit/files/datasets/test_create.py @@ -1,6 +1,7 @@ +import re from unittest import TestCase, mock -from zowe.zos_files_for_zowe_sdk import Files -from unit.files.constants import profile + +from zowe.zos_files_for_zowe_sdk import Files, exceptions, Datasets class TestCreateClass(TestCase): @@ -8,7 +9,13 @@ class TestCreateClass(TestCase): def setUp(self): """Setup fixtures for File class.""" - self.test_profile = profile + self.test_profile = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } @mock.patch("requests.Session.send") def test_create_data_set_accept_valid_recfm(self, mock_send_request): diff --git a/tests/unit/files/datasets/test_delete.py b/tests/unit/files/datasets/test_delete.py index 5e6b9739..460879c4 100644 --- a/tests/unit/files/datasets/test_delete.py +++ b/tests/unit/files/datasets/test_delete.py @@ -1,6 +1,7 @@ +import re from unittest import TestCase, mock -from zowe.zos_files_for_zowe_sdk import Files -from unit.files.constants import profile + +from zowe.zos_files_for_zowe_sdk import Files, exceptions, Datasets class TestDeleteClass(TestCase): @@ -8,7 +9,13 @@ class TestDeleteClass(TestCase): def setUp(self): """Setup fixtures for File class.""" - self.test_profile = profile + self.test_profile = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } @mock.patch("requests.Session.send") def test_delete(self, mock_send_request): @@ -19,7 +26,7 @@ def test_delete(self, mock_send_request): mock_send_request.assert_called_once() @mock.patch("requests.Session.send") - def test_delete_param(self, mock_send_request): + def test_delete_pram(self, mock_send_request): """Test list members sends request""" self.files_instance = Files(self.test_profile) mock_send_request.return_value = mock.Mock(headers={"Content-Type": "application/json"}, status_code=200) diff --git a/tests/unit/files/datasets/test_get.py b/tests/unit/files/datasets/test_get.py index 6bd24dcd..46438b62 100644 --- a/tests/unit/files/datasets/test_get.py +++ b/tests/unit/files/datasets/test_get.py @@ -1,6 +1,7 @@ +import re from unittest import TestCase, mock -from zowe.zos_files_for_zowe_sdk import Files -from unit.files.constants import profile + +from zowe.zos_files_for_zowe_sdk import Files, exceptions, Datasets class TestGetClass(TestCase): @@ -8,7 +9,13 @@ class TestGetClass(TestCase): def setUp(self): """Setup fixtures for File class.""" - self.test_profile = profile + self.test_profile = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } @mock.patch("requests.Session.send") def test_get(self, mock_send_request): diff --git a/tests/unit/files/datasets/test_list.py b/tests/unit/files/datasets/test_list.py index 06f77904..3e6d1349 100644 --- a/tests/unit/files/datasets/test_list.py +++ b/tests/unit/files/datasets/test_list.py @@ -1,6 +1,8 @@ +"""Unit tests for the Zowe Python SDK z/OS Files package.""" +import re from unittest import TestCase, mock -from zowe.zos_files_for_zowe_sdk import Files -from unit.files.constants import profile + +from zowe.zos_files_for_zowe_sdk import Files, exceptions, Datasets class TestFilesClass(TestCase): @@ -8,7 +10,13 @@ class TestFilesClass(TestCase): def setUp(self): """Setup fixtures for File class.""" - self.test_profile = profile + self.test_profile = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } @mock.patch("requests.Session.send") def test_list_dsn(self, mock_send_request): diff --git a/tests/unit/files/datasets/test_migrate.py b/tests/unit/files/datasets/test_migrate.py index 27c7128d..413911ba 100644 --- a/tests/unit/files/datasets/test_migrate.py +++ b/tests/unit/files/datasets/test_migrate.py @@ -1,6 +1,7 @@ +import re from unittest import TestCase, mock -from zowe.zos_files_for_zowe_sdk import Files -from unit.files.constants import profile + +from zowe.zos_files_for_zowe_sdk import Files, exceptions, Datasets class TestCreateClass(TestCase): @@ -8,7 +9,13 @@ class TestCreateClass(TestCase): def setUp(self): """Setup fixtures for File class.""" - self.test_profile = profile + self.test_profile = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } @mock.patch("requests.Session.send") def test_recall_migrated_dataset(self, mock_send_request): diff --git a/tests/unit/files/datasets/test_rename.py b/tests/unit/files/datasets/test_rename.py index ec6818c9..c3a70b49 100644 --- a/tests/unit/files/datasets/test_rename.py +++ b/tests/unit/files/datasets/test_rename.py @@ -1,7 +1,7 @@ import re from unittest import TestCase, mock -from zowe.zos_files_for_zowe_sdk import Files -from unit.files.constants import profile + +from zowe.zos_files_for_zowe_sdk import Files, exceptions, Datasets class TestCreateClass(TestCase): @@ -9,7 +9,13 @@ class TestCreateClass(TestCase): def setUp(self): """Setup fixtures for File class.""" - self.test_profile = profile + self.test_profile = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } @mock.patch("requests.Session.send") def test_rename_dataset(self, mock_send_request): diff --git a/tests/unit/files/datasets/test_write.py b/tests/unit/files/datasets/test_write.py index 0f478bbd..1f0c84b2 100644 --- a/tests/unit/files/datasets/test_write.py +++ b/tests/unit/files/datasets/test_write.py @@ -1,6 +1,7 @@ +import re from unittest import TestCase, mock -from zowe.zos_files_for_zowe_sdk import Files -from unit.files.constants import profile + +from zowe.zos_files_for_zowe_sdk import Files, exceptions, Datasets class TestWriteClass(TestCase): @@ -8,7 +9,13 @@ class TestWriteClass(TestCase): def setUp(self): """Setup fixtures for File class.""" - self.test_profile = profile + self.test_profile = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } @mock.patch("requests.Session.send") def test_write(self, mock_send_request): diff --git a/tests/unit/files/file_systems/test_file_systems.py b/tests/unit/files/file_systems/test_file_systems.py index 8783e2cb..9e49596b 100644 --- a/tests/unit/files/file_systems/test_file_systems.py +++ b/tests/unit/files/file_systems/test_file_systems.py @@ -1,7 +1,8 @@ """Unit tests for the Zowe Python SDK z/OS Files package.""" +import re from unittest import TestCase, mock -from zowe.zos_files_for_zowe_sdk import Files, exceptions -from unit.files.constants import profile + +from zowe.zos_files_for_zowe_sdk import Files, exceptions, Datasets class TestFilesClass(TestCase): @@ -9,7 +10,13 @@ class TestFilesClass(TestCase): def setUp(self): """Setup fixtures for File class.""" - self.test_profile = profile + self.test_profile = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } @mock.patch("requests.Session.send") def test_create_zFS_file_system(self, mock_send_request): diff --git a/tests/unit/files/uss/test_uss.py b/tests/unit/files/uss/test_uss.py index 299f142f..3a9ab204 100644 --- a/tests/unit/files/uss/test_uss.py +++ b/tests/unit/files/uss/test_uss.py @@ -1,7 +1,8 @@ """Unit tests for the Zowe Python SDK z/OS Files package.""" +import re from unittest import TestCase, mock -from zowe.zos_files_for_zowe_sdk import Files -from unit.files.constants import profile + +from zowe.zos_files_for_zowe_sdk import Files, exceptions, Datasets class TestFilesClass(TestCase): @@ -9,7 +10,13 @@ class TestFilesClass(TestCase): def setUp(self): """Setup fixtures for File class.""" - self.test_profile = profile + self.test_profile = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } @mock.patch("requests.Session.send") def test_delete_uss(self, mock_send_request): diff --git a/tests/unit/test_zos_console.py b/tests/unit/test_zos_console.py index 252d7ab5..52e05ac2 100644 --- a/tests/unit/test_zos_console.py +++ b/tests/unit/test_zos_console.py @@ -2,7 +2,7 @@ import unittest from unittest import mock -from unit.files.constants import profile + from zowe.zos_console_for_zowe_sdk import Console @@ -11,7 +11,13 @@ class TestConsoleClass(unittest.TestCase): def setUp(self): """Setup fixtures for Console class.""" - self.session_details = profile + self.session_details = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } def test_object_should_be_instance_of_class(self): """Created object should be instance of Console class.""" diff --git a/tests/unit/test_zos_jobs.py b/tests/unit/test_zos_jobs.py index ed102001..5bb93528 100644 --- a/tests/unit/test_zos_jobs.py +++ b/tests/unit/test_zos_jobs.py @@ -1,7 +1,7 @@ """Unit tests for the Zowe Python SDK z/OS Jobs package.""" from unittest import TestCase, mock -from unit.files.constants import profile + from zowe.zos_jobs_for_zowe_sdk import Jobs @@ -10,7 +10,13 @@ class TestJobsClass(TestCase): def setUp(self): """Setup fixtures for Jobs class.""" - self.test_profile = profile + self.test_profile = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } def test_object_should_be_instance_of_class(self): """Created object should be instance of Jobs class.""" diff --git a/tests/unit/test_zos_tso.py b/tests/unit/test_zos_tso.py index ab3e1da8..27567e56 100644 --- a/tests/unit/test_zos_tso.py +++ b/tests/unit/test_zos_tso.py @@ -1,7 +1,7 @@ """Unit tests for the Zowe Python SDK z/OS TSO package.""" from unittest import TestCase, mock -from unit.files.constants import profile + from zowe.zos_tso_for_zowe_sdk import Tso @@ -10,7 +10,13 @@ class TestTsoClass(TestCase): def setUp(self): """Setup fixtures for Tso class.""" - self.test_profile = profile + self.test_profile = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } def test_object_should_be_instance_of_class(self): """Created object should be instance of Tso class.""" diff --git a/tests/unit/test_zosmf.py b/tests/unit/test_zosmf.py index b133664e..91a81e10 100644 --- a/tests/unit/test_zosmf.py +++ b/tests/unit/test_zosmf.py @@ -2,7 +2,7 @@ import unittest from unittest import mock -from unit.files.constants import profile + from zowe.zosmf_for_zowe_sdk import Zosmf @@ -11,7 +11,13 @@ class TestZosmfClass(unittest.TestCase): def setUp(self): """Setup fixtures for Zosmf class.""" - self.connection_dict = profile + self.connection_dict = { + "host": "mock-url.com", + "user": "Username", + "password": "Password", + "port": 443, + "rejectUnauthorized": True, + } def test_object_should_be_instance_of_class(self): """Created object should be instance of Zosmf class.""" From d1c72c81aec0aa3db4d0709f0129c096098b03aa Mon Sep 17 00:00:00 2001 From: pem70 Date: Fri, 7 Jun 2024 10:34:16 -0400 Subject: [PATCH 10/12] Update uss.py Signed-off-by: pem70 --- src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py b/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py index 6162ce97..abcc3d17 100644 --- a/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py +++ b/src/zos_files/zowe/zos_files_for_zowe_sdk/uss.py @@ -125,7 +125,6 @@ def get_content(self, filepath_name): A JSON with the contents of the specified USS file """ custom_args = self._create_custom_request_arguments() - # custom_args["params"] = {"filepath-name": filepath_name} custom_args["url"] = "{}fs{}".format(self.request_endpoint, filepath_name) response_json = self.request_handler.perform_request("GET", custom_args) return response_json From 0e0d4f41edf3b607d68204d4158f33fd1f8502d2 Mon Sep 17 00:00:00 2001 From: pem70 Date: Tue, 11 Jun 2024 13:20:43 -0400 Subject: [PATCH 11/12] Update changelog and remove duplicate lines Signed-off-by: pem70 --- CHANGELOG.md | 2 +- src/core/zowe/core_for_zowe_sdk/zosmf_profile.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2a86d0a..2db54991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to the Zowe Client Python SDK will be documented in this fil - Added logger class to core SDK [#185](https://github.com/zowe/zowe-client-python-sdk/issues/185) - Added classes for handling `Datasets`, `USSFiles`, and `FileSystems` in favor of the single Files class. [#264](https://github.com/zowe/zowe-client-python-sdk/issues/264) -- Refactored testings into proper folders and files and add more tests [#265](https://github.com/zowe/zowe-client-python-sdk/issues/265) +- Refactored tests into proper folders and files [#265](https://github.com/zowe/zowe-client-python-sdk/issues/265) - Fixed the bug on `upload_file_to_dsn` [#104](https://github.com/zowe/zowe-client-python-sdk/issues/104) ### Bug Fixes diff --git a/src/core/zowe/core_for_zowe_sdk/zosmf_profile.py b/src/core/zowe/core_for_zowe_sdk/zosmf_profile.py index 623ffa35..2df61390 100644 --- a/src/core/zowe/core_for_zowe_sdk/zosmf_profile.py +++ b/src/core/zowe/core_for_zowe_sdk/zosmf_profile.py @@ -54,7 +54,6 @@ def __init__(self, profile_name): """ self.profile_name = profile_name self.__logger = Log.registerLogger(__name__) - self.__logger = Log.registerLogger(__name__) @property def profiles_dir(self): From f580bd64cf3806d193fdd42ed1eaa96c549cbde7 Mon Sep 17 00:00:00 2001 From: pem70 Date: Mon, 17 Jun 2024 09:07:45 -0400 Subject: [PATCH 12/12] Resolved comments Signed-off-by: pem70 --- CHANGELOG.md | 2 +- src/zos_tso/zowe/zos_tso_for_zowe_sdk/tso.py | 13 +++++++++---- tests/unit/files/datasets/test_delete.py | 12 +++--------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2db54991..69162e72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,11 +9,11 @@ All notable changes to the Zowe Client Python SDK will be documented in this fil - Added logger class to core SDK [#185](https://github.com/zowe/zowe-client-python-sdk/issues/185) - Added classes for handling `Datasets`, `USSFiles`, and `FileSystems` in favor of the single Files class. [#264](https://github.com/zowe/zowe-client-python-sdk/issues/264) - Refactored tests into proper folders and files [#265](https://github.com/zowe/zowe-client-python-sdk/issues/265) -- Fixed the bug on `upload_file_to_dsn` [#104](https://github.com/zowe/zowe-client-python-sdk/issues/104) ### Bug Fixes - Fixed truncated responses when issuing TSO commands [#260](https://github.com/zowe/zowe-client-python-sdk/issues/260) +- Fixed a bug on `upload_file_to_dsn` where it would not properly convert line endings on Windows. [#104](https://github.com/zowe/zowe-client-python-sdk/issues/104) ## `1.0.0-dev15` 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 761230b5..91cdf772 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 @@ -11,6 +11,7 @@ """ import json + from zowe.core_for_zowe_sdk import SdkApi, constants @@ -61,10 +62,8 @@ def issue_command(self, command): command_output = self.send_tso_message(session_key, command) tso_messages = self.retrieve_tso_messages(command_output) while not any("TSO PROMPT" in message for message in command_output) or not tso_messages: - custom_args = self._create_custom_request_arguments() - custom_args["url"] = "{}/{}".format(self.request_endpoint, session_key) - command_output = self.request_handler.perform_request("GET", custom_args)["tsoData"] - tso_messages += self.retrieve_tso_messages(command_output) + command_output = self.__get_tso_data(session_key) + tso_messages += self.retrieve_tso_messages(command_output) self.end_tso_session(session_key) return tso_messages @@ -206,3 +205,9 @@ def retrieve_tso_messages(self, response_json): A list containing the TSO response messages """ return [message["TSO MESSAGE"]["DATA"] for message in response_json if "TSO MESSAGE" in message] + + def __get_tso_data(self, session_key): + custom_args = self._create_custom_request_arguments() + custom_args["url"] = "{}/{}".format(self.request_endpoint, session_key) + command_output = self.request_handler.perform_request("GET", custom_args)["tsoData"] + return command_output diff --git a/tests/unit/files/datasets/test_delete.py b/tests/unit/files/datasets/test_delete.py index 460879c4..4ce6c520 100644 --- a/tests/unit/files/datasets/test_delete.py +++ b/tests/unit/files/datasets/test_delete.py @@ -1,7 +1,7 @@ import re from unittest import TestCase, mock -from zowe.zos_files_for_zowe_sdk import Files, exceptions, Datasets +from zowe.zos_files_for_zowe_sdk import Datasets, Files, exceptions class TestDeleteClass(TestCase): @@ -26,18 +26,13 @@ def test_delete(self, mock_send_request): mock_send_request.assert_called_once() @mock.patch("requests.Session.send") - def test_delete_pram(self, mock_send_request): + def test_delete_param(self, mock_send_request): """Test list members sends request""" self.files_instance = Files(self.test_profile) mock_send_request.return_value = mock.Mock(headers={"Content-Type": "application/json"}, status_code=200) mock_send_request.return_value.json.return_value = {} - test_cases = [ - ("MY.PDS", 1000, "m1"), - ("MY.C", 100, "m2"), - ("MY.D", 1000, "member"), - ("MY.E", 500, "extended") - ] + test_cases = [("MY.PDS", 1000, "m1"), ("MY.C", 100, "m2"), ("MY.D", 1000, "member"), ("MY.E", 500, "extended")] for dataset_name, volume, member_name in test_cases: result = self.files_instance.delete_data_set(dataset_name, volume, member_name) @@ -45,4 +40,3 @@ def test_delete_pram(self, mock_send_request): mock_send_request.assert_called() prepared_request = mock_send_request.call_args[0][0] self.assertEqual(prepared_request.method, "DELETE") -