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 9da72c48..b9ff66aa 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 @@ -16,6 +16,7 @@ from zowe.zos_files_for_zowe_sdk import exceptions, constants import os import shutil +import urllib from zowe.zos_files_for_zowe_sdk.constants import zos_file_constants, FileType _ZOWE_FILES_DEFAULT_ENCODING='utf-8' @@ -56,7 +57,7 @@ def __adjust_for_url(self, str_to_adjust): A string with special characters, acceptable for a URL """ - return str_to_adjust.replace("#", "%23") if str_to_adjust is not None else None + return urllib.parse.quote(str_to_adjust) if str_to_adjust is not None else None def list_files(self, path): @@ -129,7 +130,7 @@ def list_dsn(self, name_pattern, return_attributes= False): A JSON with a list of dataset names (and attributes if specified) matching the given pattern. """ custom_args = self._create_custom_request_arguments() - custom_args["params"] = {"dslevel": name_pattern} + custom_args["params"] = {"dslevel": self.__adjust_for_url(name_pattern)} custom_args["url"] = "{}ds".format(self.request_endpoint) diff --git a/tests/unit/test_zos_files.py b/tests/unit/test_zos_files.py index 1a147a2b..713618a9 100644 --- a/tests/unit/test_zos_files.py +++ b/tests/unit/test_zos_files.py @@ -20,6 +20,21 @@ def test_object_should_be_instance_of_class(self): files = Files(self.test_profile) self.assertIsInstance(files, Files) + + def test_adjust_for_url(self): + """Test dataset name is being adjusted to the correct URL parameter""" + + files = Files(self.test_profile) + + actual_not_empty = files._Files__adjust_for_url('MY.DSN@.TEST#.$HERE') + expected_not_empty = 'MY.DSN%40.TEST%23.%24HERE' + self.assertEqual(actual_not_empty, expected_not_empty) + + actual_none = files._Files__adjust_for_url(None) + expected_none = None + self.assertEqual(actual_none, expected_none) + + @mock.patch('requests.Session.send') def test_delete_uss(self, mock_send_request): """Test deleting a directory recursively sends a request""" @@ -74,7 +89,7 @@ def test_unmount_zFS_file_system(self, mock_send_request): @mock.patch('requests.Session.send') def test_list_dsn(self, mock_send_request): - """Test creating a zfs sends a request""" + """Test list DSN sends request""" mock_send_request.return_value = mock.Mock(headers={"Content-Type": "application/json"}, status_code=200) test_values = [ @@ -337,8 +352,9 @@ def test_rename_dataset_member_parametrized(self): files_test_profile.rename_dataset_member(*test_case[0]) custom_args = files_test_profile._create_custom_request_arguments() custom_args["json"] = data - custom_args["url"] = "https://mock-url.com:443/zosmf/restfiles/ds/{}({})".format( - test_case[0][0], test_case[0][2]) + ds_path = "{}({})".format(test_case[0][0], test_case[0][2]) + ds_path_adjusted = files_test_profile._Files__adjust_for_url(ds_path) + custom_args["url"] = "https://mock-url.com:443/zosmf/restfiles/ds/{}".format(ds_path_adjusted) files_test_profile.request_handler.perform_request.assert_called_once_with("PUT", custom_args, expected_code=[200]) else: