Skip to content

Commit 5204511

Browse files
committed
chore: a few small adjustments to increase our code coverage
Signed-off-by: Norbert Biczo <[email protected]>
1 parent 85bc3f9 commit 5204511

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

ibm_cloud_sdk_core/base_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,4 +508,4 @@ def _convert_list(val: list) -> None:
508508

509509
@staticmethod
510510
def _encode_path_vars(*args) -> None:
511-
return (requests.utils.quote(x, safe='') for x in args)
511+
return BaseService.encode_path_vars(*args)

test/test_authenticator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ def test_authenticator():
1919
authenticator = TestAuthenticator()
2020
assert authenticator is not None
2121
assert authenticator.authentication_type() == Authenticator.AUTHTYPE_UNKNOWN
22+
assert authenticator.validate() is None
23+
assert authenticator.authenticate(None) is None

test/test_container_token_manager.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,32 @@ def test_retrieve_cr_token_success():
165165
assert cr_token == 'cr-token-1'
166166

167167

168+
def test_retrieve_cr_token_with_no_filename_1_success():
169+
token_manager = ContainerTokenManager()
170+
171+
# Override the constants with the default locations
172+
# just for testing purposes.
173+
token_manager.DEFAULT_CR_TOKEN_FILENAME1 = cr_token_file
174+
token_manager.DEFAULT_CR_TOKEN_FILENAME2 = ''
175+
176+
cr_token = token_manager.retrieve_cr_token()
177+
178+
assert cr_token == 'cr-token-1'
179+
180+
181+
def test_retrieve_cr_token_with_no_filename_2_success():
182+
token_manager = ContainerTokenManager()
183+
184+
# Override the constants with the default locations
185+
# just for testing purposes.
186+
token_manager.DEFAULT_CR_TOKEN_FILENAME1 = ''
187+
token_manager.DEFAULT_CR_TOKEN_FILENAME2 = cr_token_file
188+
189+
cr_token = token_manager.retrieve_cr_token()
190+
191+
assert cr_token == 'cr-token-1'
192+
193+
168194
def test_retrieve_cr_token_fail():
169195
token_manager = ContainerTokenManager(
170196
cr_token_filename='bogus-cr-token-file',

test/test_iam_assume_authenticator.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ def test_iam_assume_authenticator():
3131
assert authenticator.token_manager.scope is None
3232

3333

34+
def test_iam_assume_authenticator_disable_ssl_wrong_type():
35+
with pytest.raises(TypeError) as err:
36+
authenticator = IAMAssumeAuthenticator(
37+
apikey='my_apikey', iam_profile_crn='crn:iam-profile:123', disable_ssl_verification='yes'
38+
)
39+
assert str(err.value) == 'disable_ssl_verification must be a bool'
40+
41+
3442
def test_iam_assume_authenticator_validate_failed():
3543
with pytest.raises(ValueError) as err:
3644
IAMAssumeAuthenticator(None)

test/test_utils.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from ibm_cloud_sdk_core import get_query_param
3030
from ibm_cloud_sdk_core import read_external_sources
3131
from ibm_cloud_sdk_core.authenticators import Authenticator, BasicAuthenticator, IAMAuthenticator
32-
from ibm_cloud_sdk_core.utils import strip_extra_slashes, is_json_mimetype
32+
from ibm_cloud_sdk_core.utils import GzipStream, strip_extra_slashes, is_json_mimetype
3333
from .utils.logger_utils import setup_test_logger
3434

3535
setup_test_logger(logging.ERROR)
@@ -659,3 +659,20 @@ def test_is_json_mimetype():
659659

660660
assert is_json_mimetype('application/json') is True
661661
assert is_json_mimetype('application/json; charset=utf8') is True
662+
663+
664+
def test_GzipStream_open_file():
665+
cr_token_file = os.path.join(os.path.dirname(__file__), '../resources/cr-token.txt')
666+
with open(cr_token_file, 'r') as f:
667+
stream = GzipStream(source=f)
668+
assert stream is not None
669+
670+
671+
def test_GzipStream_open_string():
672+
stream = GzipStream(source='foobar')
673+
assert stream is not None
674+
675+
676+
def test_GzipStream_open_bytes():
677+
stream = GzipStream(source=b'foobar')
678+
assert stream is not None

0 commit comments

Comments
 (0)