Skip to content

Commit

Permalink
chore: a few small adjustments to increase our code coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>
  • Loading branch information
pyrooka committed Oct 15, 2024
1 parent 85bc3f9 commit 5fa39f0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ibm_cloud_sdk_core/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions test/test_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 26 additions & 0 deletions test/test_container_token_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions test/test_iam_assume_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 5fa39f0

Please sign in to comment.