Skip to content

Commit c253261

Browse files
committed
chore: fix token file path in tests
1 parent 80006d7 commit c253261

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

test/test_container_token_manager.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pylint: disable=missing-docstring
22
import json
3+
import os
34
import time
45
from urllib.parse import parse_qs
56

@@ -13,11 +14,12 @@
1314
TEST_ACCESS_TOKEN_1 = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImhlbGxvIiwicm9sZSI6InVzZXIiLCJwZXJtaXNzaW9ucyI6WyJhZG1pbmlzdHJhdG9yIiwiZGVwbG95bWVudF9hZG1pbiJdLCJzdWIiOiJoZWxsbyIsImlzcyI6IkpvaG4iLCJhdWQiOiJEU1giLCJ1aWQiOiI5OTkiLCJpYXQiOjE1NjAyNzcwNTEsImV4cCI6MTU2MDI4MTgxOSwianRpIjoiMDRkMjBiMjUtZWUyZC00MDBmLTg2MjMtOGNkODA3MGI1NDY4In0.cIodB4I6CCcX8vfIImz7Cytux3GpWyObt9Gkur5g1QI'
1415
TEST_ACCESS_TOKEN_2 = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6IjIzMDQ5ODE1MWMyMTRiNzg4ZGQ5N2YyMmI4NTQxMGE1In0.eyJ1c2VybmFtZSI6ImR1bW15Iiwicm9sZSI6IkFkbWluIiwicGVybWlzc2lvbnMiOlsiYWRtaW5pc3RyYXRvciIsIm1hbmFnZV9jYXRhbG9nIl0sInN1YiI6ImFkbWluIiwiaXNzIjoic3NzIiwiYXVkIjoic3NzIiwidWlkIjoic3NzIiwiaWF0IjozNjAwLCJleHAiOjE2MjgwMDcwODF9.zvUDpgqWIWs7S1CuKv40ERw1IZ5FqSFqQXsrwZJyfRM'
1516
TEST_REFRESH_TOKEN = 'Xj7Gle500MachEOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImhlbGxvIiwicm9sZSI6InVzZXIiLCJwZXJtaXNzaW9ucyI6WyJhZG1pbmlzdHJhdG9yIiwiZGVwbG95bWVudF9hZG1pbiJdLCJzdWIiOiJoZWxsbyIsImlzcyI6IkpvaG4iLCJhdWQiOiJEU1giLCJ1aWQiOiI5OTkiLCJpYXQiOjE1NjAyNzcwNTEsImV4cCI6MTU2MDI4MTgxOSwianRpIjoiMDRkMjBiMjUtZWUyZC00MDBmLTg2MjMtOGNkODA3MGI1NDY4In0.cIodB4I6CCcX8vfIImz7Cytux3GpWyObt9Gkur5g1QI'
16-
MOCK_CR_TOKEN_FILE = './resources/cr-token.txt'
1717
MOCK_IAM_PROFILE_NAME = 'iam-user-123'
1818
MOCK_CLIENT_ID = 'client-id-1'
1919
MOCK_CLIENT_SECRET = 'client-secret-1'
2020

21+
cr_token_file = os.path.join(os.path.dirname(__file__), '../resources/cr-token.txt')
22+
2123

2224
def _get_current_time() -> int:
2325
return int(time.time())
@@ -81,7 +83,7 @@ def test_request_token_auth_default():
8183
iam_url = "https://iam.cloud.ibm.com/identity/token"
8284

8385
token_manager = ContainerTokenManager(
84-
cr_token_filename=MOCK_CR_TOKEN_FILE,
86+
cr_token_filename=cr_token_file,
8587
iam_profile_name=MOCK_IAM_PROFILE_NAME,
8688
)
8789
token_manager.request_token()
@@ -96,7 +98,7 @@ def test_request_token_auth_default():
9698
def test_request_token_auth_in_ctor():
9799
default_auth_header = 'Basic Yng6Yng='
98100
token_manager = ContainerTokenManager(
99-
cr_token_filename=MOCK_CR_TOKEN_FILE,
101+
cr_token_filename=cr_token_file,
100102
iam_profile_name=MOCK_IAM_PROFILE_NAME,
101103
client_id='foo',
102104
client_secret='bar')
@@ -113,7 +115,7 @@ def test_request_token_auth_in_ctor():
113115
def test_request_token_auth_in_ctor_with_scope():
114116
default_auth_header = 'Basic Yng6Yng='
115117
token_manager = ContainerTokenManager(
116-
cr_token_filename=MOCK_CR_TOKEN_FILE,
118+
cr_token_filename=cr_token_file,
117119
iam_profile_name=MOCK_IAM_PROFILE_NAME,
118120
client_id='foo',
119121
client_secret='bar',
@@ -129,7 +131,7 @@ def test_request_token_auth_in_ctor_with_scope():
129131

130132
def test_retrieve_cr_token_success():
131133
token_manager = ContainerTokenManager(
132-
cr_token_filename=MOCK_CR_TOKEN_FILE,
134+
cr_token_filename=cr_token_file,
133135
)
134136

135137
cr_token = token_manager.retrieve_cr_token()
@@ -151,7 +153,7 @@ def test_retrieve_cr_token_success_fail():
151153
@mock_iam_response
152154
def test_get_token_success():
153155
token_manager = ContainerTokenManager(
154-
cr_token_filename=MOCK_CR_TOKEN_FILE,
156+
cr_token_filename=cr_token_file,
155157
iam_profile_name=MOCK_IAM_PROFILE_NAME,
156158
)
157159

@@ -182,7 +184,7 @@ def test_get_token_success():
182184
@mock_iam_response
183185
def test_request_token_success():
184186
token_manager = ContainerTokenManager(
185-
cr_token_filename=MOCK_CR_TOKEN_FILE,
187+
cr_token_filename=cr_token_file,
186188
iam_profile_name=MOCK_IAM_PROFILE_NAME,
187189
)
188190

@@ -193,7 +195,7 @@ def test_request_token_success():
193195
@mock_iam_response
194196
def test_authenticate_success():
195197
authenticator = ContainerAuthenticator(
196-
cr_token_filename=MOCK_CR_TOKEN_FILE,
198+
cr_token_filename=cr_token_file,
197199
iam_profile_name='iam-user-123')
198200

199201
request = {'headers': {}}
@@ -234,7 +236,7 @@ def test_authenticate_fail_no_cr_token():
234236
@mock_iam_response
235237
def test_authenticate_fail_iam():
236238
authenticator = ContainerAuthenticator(
237-
cr_token_filename=MOCK_CR_TOKEN_FILE,
239+
cr_token_filename=cr_token_file,
238240
iam_profile_name='iam-user-123',
239241
scope='status-bad-request')
240242

@@ -249,7 +251,7 @@ def test_authenticate_fail_iam():
249251
@mock_iam_response
250252
def test_client_id_and_secret():
251253
token_manager = ContainerTokenManager(
252-
cr_token_filename=MOCK_CR_TOKEN_FILE,
254+
cr_token_filename=cr_token_file,
253255
iam_profile_name=MOCK_IAM_PROFILE_NAME,
254256
)
255257

0 commit comments

Comments
 (0)