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

Standardize response #285

Merged
merged 8 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ 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)
- Standardize `response` output [#266](https://github.com/zowe/zowe-client-python-sdk/issues/266)
pem70 marked this conversation as resolved.
Show resolved Hide resolved

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion samples/SampleFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
# -----------------------------------------------------
print("...content of a file\n")
my_file_content = my_files.get_file_content("/z/tm891807/file.txt")
print(my_file_content["response"])
print(my_file_content)
13 changes: 6 additions & 7 deletions src/core/zowe/core_for_zowe_sdk/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,12 @@ def __normalize_response(self):

Returns
-------
A bytes object if the response content type is application/octet-stream,
a normalized JSON for the request response otherwise
A bytes object at the format based on Content-Type header
pem70 marked this conversation as resolved.
Show resolved Hide resolved
"""
if self.response.headers.get("Content-Type") == "application/octet-stream":
contentType = self.response.headers.get("Content-Type")
if contentType == "application/octet-stream":
return self.response.content
elif contentType and contentType.startswith("application/json"):
return self.response.json()
else:
try:
return self.response.json()
except:
return {"response": self.response.text}
return self.response.text
1 change: 0 additions & 1 deletion src/core/zowe/core_for_zowe_sdk/zosmf_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
os.makedirs(output_dir, exist_ok=True)
output_file = os.path.join(output_dir, job_name, job_id, "jcl.txt")
data_spool_file = self.get_jcl_text(job_correlator)
dataset_content = data_spool_file["response"]
dataset_content = data_spool_file

Check warning on line 405 in src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py

View check run for this annotation

Codecov / codecov/patch

src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py#L405

Added line #L405 was not covered by tests
with open(output_file, "w", encoding="utf-8") as out_file:
out_file.write(dataset_content)

Expand All @@ -416,7 +416,7 @@

output_file = os.path.join(output_dir, job_name, job_id, stepname, ddname)
data_spool_file = self.get_spool_file_contents(job_correlator, spoolfile_id)
dataset_content = data_spool_file["response"]
dataset_content = data_spool_file

Check warning on line 419 in src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py

View check run for this annotation

Codecov / codecov/patch

src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py#L419

Added line #L419 was not covered by tests
with open(output_file, "w", encoding="utf-8") as out_file:
out_file.write(dataset_content)

Expand Down
15 changes: 8 additions & 7 deletions tests/integration/test_zos_files.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Integration tests for the Zowe Python SDK z/OS Files package."""

import json
import os
import unittest
Expand Down Expand Up @@ -66,7 +67,7 @@ def test_list_members_should_return_a_list_of_members(self):
def test_get_dsn_content_should_return_content_from_dataset(self):
"""Executing get_dsn_content should return content from dataset."""
command_output = self.files.get_dsn_content(self.test_member_jcl)
self.assertIsInstance(command_output["response"], str)
self.assertIsInstance(command_output, str)

def test_get_dsn_content_streamed_should_return_response_content(self):
"""Executing get_dsn_content_streamed should return response object from the server."""
Expand All @@ -86,14 +87,14 @@ def test_get_file_content_streamed_should_return_response_content(self):
def test_write_to_dsn_should_be_possible(self):
"""Executing write_to_dsn should be possible."""
command_output = self.files.write_to_dsn(self.test_member_generic, "HELLO WORLD")
self.assertTrue(command_output["response"] == "")
self.assertTrue(command_output == "")

def test_copy_uss_to_dataset_should_be_possible(self):
"""Executing copy_uss_to_dataset should be possible."""
command_output = self.files.copy_uss_to_dataset(
self.files_fixtures["TEST_USS"], self.files_fixtures["TEST_PDS"] + "(TEST2)", replace=True
)
self.assertTrue(command_output["response"] == "")
self.assertTrue(command_output == "")

def test_copy_dataset_or_member_should_be_possible(self):
"""Executing copy_dataset_or_member should be possible."""
Expand All @@ -105,7 +106,7 @@ def test_copy_dataset_or_member_should_be_possible(self):
"replace": True,
}
command_output = self.files.copy_dataset_or_member(**test_case)
self.assertTrue(command_output["response"] == "")
self.assertTrue(command_output == "")

def test_mount_unmount_zfs_file_system(self):
"""Mounting a zfs filesystem should be possible"""
Expand All @@ -119,19 +120,19 @@ def test_mount_unmount_zfs_file_system(self):
command_output = self.files.mount_file_system(
self.test2_zfs_file_system, mount_point, self.mount_zfs_file_system_options
)
self.assertTrue(command_output["response"] == "")
self.assertTrue(command_output == "")

# List a zfs file system
command_output = self.files.list_unix_file_systems(file_system_name=self.test2_zfs_file_system.upper())
self.assertTrue(len(command_output["items"]) > 0)

# Unmount file system
command_output = self.files.unmount_file_system(self.test2_zfs_file_system)
self.assertTrue(command_output["response"] == "")
self.assertTrue(command_output == "")

# Delete file system
command_output = self.files.delete_zFS_file_system(self.test2_zfs_file_system)
self.assertTrue(command_output["response"] == "")
self.assertTrue(command_output == "")

def test_upload_download_delete_dataset(self):
self.files.upload_file_to_dsn(SAMPLE_JCL_FIXTURE_PATH, self.test_ds_upload)
Expand Down
Loading