Skip to content

Commit

Permalink
zoweGH-211 Unit tests update, changed adjustment to use urllib.parse.…
Browse files Browse the repository at this point in the history
…quote

Signed-off-by: Uladzislau <[email protected]>
  • Loading branch information
KUGDev committed Sep 5, 2023
1 parent c94e957 commit a2dd403
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/zos_files/zowe/zos_files_for_zowe_sdk/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)


Expand Down
22 changes: 19 additions & 3 deletions tests/unit/test_zos_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]#.$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"""
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a2dd403

Please sign in to comment.