From cb4fff81cef509266d8ad1e16109c5be08a15539 Mon Sep 17 00:00:00 2001 From: pem70 Date: Tue, 2 Jul 2024 11:17:24 -0400 Subject: [PATCH 1/4] Update create Signed-off-by: pem70 --- CHANGELOG.md | 1 + src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a6e197c..46967a25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to the Zowe Client Python SDK will be documented in this fil ### Bug Fixes +- Fixed a bug on `create` in `Datasets` where the target dataset gets created with a different block size when `like` is specified [#295] (https://github.com/zowe/zowe-client-python-sdk/issues/295) - Fixed a bug on `_create_custom_request_arguments` where changes on `custom_args` will stay after the function returns [#299](https://github.com/zowe/zowe-client-python-sdk/issues/299) ## `1.0.0-dev16` 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 32f8230a..c4d5c309 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 @@ -385,6 +385,11 @@ def create(self, dataset_name, options: Optional[DatasetOption] = None): if options.dirblk == 0: self.logger.error("Can't allocate empty directory blocks.") raise ValueError + else: + dsn_attr = self.list(options.like, return_attributes=True)["items"] + for dsn in dsn_attr: + if dsn["dsname"] == options.like.upper(): + options.blksize = int(dsn["blksz"]) custom_args = self._create_custom_request_arguments() custom_args["url"] = "{}ds/{}".format(self._request_endpoint, self._encode_uri_component(dataset_name)) From 6ceb15ceb9a9f857fb2616bd1e926dabb64afba0 Mon Sep 17 00:00:00 2001 From: pem70 Date: Tue, 2 Jul 2024 11:19:27 -0400 Subject: [PATCH 2/4] Update datasets.py Signed-off-by: pem70 --- src/zos_files/zowe/zos_files_for_zowe_sdk/datasets.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 c4d5c309..7b02401f 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 @@ -374,8 +374,8 @@ def create(self, dataset_name, options: Optional[DatasetOption] = None): if options.like is None: if options.primary is None or options.lrecl is None: - self.logger.error("If 'like' is not specified, you must specify 'primary' or 'lrecl'.") - raise ValueError("If 'like' is not specified, you must specify 'primary' or 'lrecl'.") + self.logger.error("If 'like' is not specified, you must specify 'primary' and 'lrecl'.") + raise ValueError("If 'like' is not specified, you must specify 'primary' and 'lrecl'.") if options.dirblk is not None: if options.dsorg == "PS": if options.dirblk != 0: @@ -390,6 +390,7 @@ def create(self, dataset_name, options: Optional[DatasetOption] = None): for dsn in dsn_attr: if dsn["dsname"] == options.like.upper(): options.blksize = int(dsn["blksz"]) + break custom_args = self._create_custom_request_arguments() custom_args["url"] = "{}ds/{}".format(self._request_endpoint, self._encode_uri_component(dataset_name)) From 0e2bf0f5b81a0a48abee80685f2fb491255dc519 Mon Sep 17 00:00:00 2001 From: pem70 Date: Tue, 2 Jul 2024 13:07:44 -0400 Subject: [PATCH 3/4] Update test_create.py Signed-off-by: pem70 --- tests/unit/files/datasets/test_create.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/unit/files/datasets/test_create.py b/tests/unit/files/datasets/test_create.py index f5d1dfeb..2f477f4d 100644 --- a/tests/unit/files/datasets/test_create.py +++ b/tests/unit/files/datasets/test_create.py @@ -27,6 +27,22 @@ def test_create_data_set_accept_valid_recfm(self, mock_send_request): Files(self.test_profile).create_data_set("DSNAME123", options=option) mock_send_request.assert_called() + @mock.patch("requests.Session.send") + def test_create_data_set_with_like(self, mock_send_request: mock.Mock): + """Test if create dataset does accept all accepted record formats""" + + option = DatasetOption(like="test") + + response1 = mock.Mock( + headers={"Content-Type": "application/octet-stream"}, + status_code=200, + content={"items": [{"dsname": "test", "blksz": 123}]}, + ) + response2 = mock.Mock(headers={"Content-Type": "application/json"}, status_code=201) + mock_send_request.side_effect = [response1, response2] + Files(self.test_profile).create_data_set("DSNAME123", options=option) + self.assertEqual(mock_send_request.call_count, 2) + def test_create_data_set_does_not_accept_invalid_recfm(self): """Test if create dataset raises an error for invalid record formats""" with self.assertRaises(KeyError): @@ -38,7 +54,7 @@ def test_create_data_set_raises_error_without_required_arguments(self): option = DatasetOption(alcunit="CYL", dsorg="PO", primary=1, dirblk=25, recfm="FB", blksize=6160) with self.assertRaises(ValueError) as e_info: obj = Files(self.test_profile).create_data_set("DSNAME123", options=option) - self.assertEqual(str(e_info.exception), "If 'like' is not specified, you must specify 'primary' or 'lrecl'.") + self.assertEqual(str(e_info.exception), "If 'like' is not specified, you must specify 'primary' and 'lrecl'.") def test_create_data_set_raises_error_with_invalid_arguments_parameterized(self): """Test not providing valid arguments raises an error""" @@ -117,7 +133,7 @@ def test_create_data_set_parameterized(self): with self.assertRaises(ValueError) as e_info: files_test_profile.create_data_set("DSN", test_case[0]) self.assertEqual( - str(e_info.exception), "If 'like' is not specified, you must specify 'primary' or 'lrecl'." + str(e_info.exception), "If 'like' is not specified, you must specify 'primary' and 'lrecl'." ) @mock.patch("requests.Session.send") From 9cf461544869f1988e37dac1695d24a010f4bb96 Mon Sep 17 00:00:00 2001 From: pem70 Date: Tue, 2 Jul 2024 13:10:38 -0400 Subject: [PATCH 4/4] Update CHANGELOG.md Signed-off-by: pem70 --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46967a25..1b987d6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,20 @@ All notable changes to the Zowe Client Python SDK will be documented in this file. -## `1.0.0-dev17` +## Recent Changes ### Enhancements ### Bug Fixes - Fixed a bug on `create` in `Datasets` where the target dataset gets created with a different block size when `like` is specified [#295] (https://github.com/zowe/zowe-client-python-sdk/issues/295) + +## `1.0.0-dev17` + +### Enhancements + +### Bug Fixes + - Fixed a bug on `_create_custom_request_arguments` where changes on `custom_args` will stay after the function returns [#299](https://github.com/zowe/zowe-client-python-sdk/issues/299) ## `1.0.0-dev16`