diff --git a/ibm_cloud_sdk_core/base_service.py b/ibm_cloud_sdk_core/base_service.py index 08509c1..636e514 100644 --- a/ibm_cloud_sdk_core/base_service.py +++ b/ibm_cloud_sdk_core/base_service.py @@ -508,4 +508,4 @@ def _convert_list(val: list) -> None: @staticmethod def _encode_path_vars(*args) -> None: - return (requests.utils.quote(x, safe='') for x in args) + return BaseService.encode_path_vars(*args) diff --git a/test/test_authenticator.py b/test/test_authenticator.py index 10131c0..3c8c609 100644 --- a/test/test_authenticator.py +++ b/test/test_authenticator.py @@ -19,3 +19,5 @@ def test_authenticator(): authenticator = TestAuthenticator() assert authenticator is not None assert authenticator.authentication_type() == Authenticator.AUTHTYPE_UNKNOWN + assert authenticator.validate() is None + assert authenticator.authenticate(None) is None diff --git a/test/test_container_token_manager.py b/test/test_container_token_manager.py index 824e1ce..97ea5f2 100644 --- a/test/test_container_token_manager.py +++ b/test/test_container_token_manager.py @@ -165,6 +165,32 @@ def test_retrieve_cr_token_success(): assert cr_token == 'cr-token-1' +def test_retrieve_cr_token_with_no_filename_1_success(): + token_manager = ContainerTokenManager() + + # Override the constants with the default locations + # just for testing purposes. + setattr(token_manager, 'DEFAULT_CR_TOKEN_FILENAME1', cr_token_file) + setattr(token_manager, 'DEFAULT_CR_TOKEN_FILENAME2', '') + + cr_token = token_manager.retrieve_cr_token() + + assert cr_token == 'cr-token-1' + + +def test_retrieve_cr_token_with_no_filename_2_success(): + token_manager = ContainerTokenManager() + + # Override the constants with the default locations + # just for testing purposes. + setattr(token_manager, 'DEFAULT_CR_TOKEN_FILENAME1', '') + setattr(token_manager, 'DEFAULT_CR_TOKEN_FILENAME2', cr_token_file) + + cr_token = token_manager.retrieve_cr_token() + + assert cr_token == 'cr-token-1' + + def test_retrieve_cr_token_fail(): token_manager = ContainerTokenManager( cr_token_filename='bogus-cr-token-file', diff --git a/test/test_iam_assume_authenticator.py b/test/test_iam_assume_authenticator.py index 8b3667c..2788761 100644 --- a/test/test_iam_assume_authenticator.py +++ b/test/test_iam_assume_authenticator.py @@ -31,6 +31,14 @@ def test_iam_assume_authenticator(): assert authenticator.token_manager.scope is None +def test_iam_assume_authenticator_disable_ssl_wrong_type(): + with pytest.raises(TypeError) as err: + IAMAssumeAuthenticator( + apikey='my_apikey', iam_profile_crn='crn:iam-profile:123', disable_ssl_verification='yes' + ) + assert str(err.value) == 'disable_ssl_verification must be a bool' + + def test_iam_assume_authenticator_validate_failed(): with pytest.raises(ValueError) as err: IAMAssumeAuthenticator(None) diff --git a/test/test_utils.py b/test/test_utils.py index 7e181a5..fed34ff 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -29,7 +29,7 @@ from ibm_cloud_sdk_core import get_query_param from ibm_cloud_sdk_core import read_external_sources from ibm_cloud_sdk_core.authenticators import Authenticator, BasicAuthenticator, IAMAuthenticator -from ibm_cloud_sdk_core.utils import strip_extra_slashes, is_json_mimetype +from ibm_cloud_sdk_core.utils import GzipStream, strip_extra_slashes, is_json_mimetype from .utils.logger_utils import setup_test_logger setup_test_logger(logging.ERROR) @@ -659,3 +659,20 @@ def test_is_json_mimetype(): assert is_json_mimetype('application/json') is True assert is_json_mimetype('application/json; charset=utf8') is True + + +def test_gzip_stream_open_file(): + cr_token_file = os.path.join(os.path.dirname(__file__), '../resources/cr-token.txt') + with open(cr_token_file, 'r', encoding='utf-8') as f: + stream = GzipStream(source=f) + assert stream is not None + + +def test_gzip_stream_open_string(): + stream = GzipStream(source='foobar') + assert stream is not None + + +def test_gzip_stream_open_bytes(): + stream = GzipStream(source=b'foobar') + assert stream is not None