Debian Codegraph @

test_integration/test_mcsp_authenticator_integration.py

raw
1 # pylint: disable=missing-docstring
2 import logging
3 import os
4
5 from test.utils.logger_utils import setup_test_logger
6 from ibm_cloud_sdk_core import get_authenticator_from_environment
7
8 setup_test_logger(logging.WARNING)
9
10 # Note: Only the unit tests are run by default.
11 #
12 # In order to test with a live MCSP token server, create file "mcsptest.env" in the project root.
13 # It should look like this:
14 #
15 # MCSPTEST1_AUTH_URL=<url> e.g. https://iam.cloud.ibm.com
16 # MCSPTEST1_AUTH_TYPE=mcsp
17 # MCSPTEST1_APIKEY=<apikey>
18 #
19 # Then run this command:
20 # pytest test_integration/test_mcsp_authenticator_integration.py
21
22
23 def test_mcsp_authenticator():
24 os.environ['IBM_CREDENTIALS_FILE'] = 'mcsptest.env'
25
26 authenticator = get_authenticator_from_environment('mcsptest1')
27 assert authenticator is not None
28
29 request = {'headers': {}}
30 authenticator.authenticate(request)
31 assert request['headers']['Authorization'] is not None
32 assert 'Bearer' in request['headers']['Authorization']