File: test_mcsp_authenticator_integration.py

package info (click to toggle)
python-ibm-cloud-sdk-core 3.19.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 672 kB
  • sloc: python: 4,428; makefile: 26; sh: 25
file content (28 lines) | stat: -rw-r--r-- 883 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# pylint: disable=missing-docstring
import os

from ibm_cloud_sdk_core import get_authenticator_from_environment

# Note: Only the unit tests are run by default.
#
# In order to test with a live MCSP token server, create file "mcsptest.env" in the project root.
# It should look like this:
#
# 	MCSPTEST_AUTH_URL=<url>   e.g. https://iam.cloud.ibm.com
# 	MCSPTEST_AUTH_TYPE=mcsp
# 	MCSPTEST_APIKEY=<apikey>
#
# Then run this command:
# pytest test_integration/test_mcsp_authenticator_integration.py


def test_mcsp_authenticator():
    os.environ['IBM_CREDENTIALS_FILE'] = 'mcsptest.env'

    authenticator = get_authenticator_from_environment('mcsptest1')
    assert authenticator is not None

    request = {'headers': {}}
    authenticator.authenticate(request)
    assert request['headers']['Authorization'] is not None
    assert 'Bearer' in request['headers']['Authorization']