Skip to content

Commit 858e96b

Browse files
author
Fabio Grätz
committed
Make test_client_creds_authenticator_with_custom_scopes test work and more specific
Signed-off-by: Fabio Grätz <fabiogratz@googlemail.com>
1 parent 63f0c8e commit 858e96b

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

tests/flytekit/unit/clients/auth/test_authenticator.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,17 @@ def test_device_flow_authenticator(poll_mock: MagicMock, device_mock: MagicMock,
118118
assert authn._creds
119119

120120

121-
@patch("flytekit.clients.auth.token_client.requests")
122-
def test_client_creds_authenticator_with_custom_scopes(mock_requests):
121+
@patch("flytekit.clients.auth.token_client.requests.Session")
122+
def test_client_creds_authenticator_with_custom_scopes(mock_session):
123123
expected_scopes = ["foo", "baz"]
124+
125+
session = MagicMock()
126+
response = MagicMock()
127+
response.status_code = 200
128+
response.json.return_value = json.loads("""{"access_token": "abc", "expires_in": 60}""")
129+
session.post.return_value = response
130+
mock_session.return_value = session
131+
124132
authn = ClientCredentialsAuthenticator(
125133
ENDPOINT,
126134
client_id="client",
@@ -129,11 +137,9 @@ def test_client_creds_authenticator_with_custom_scopes(mock_requests):
129137
scopes=expected_scopes,
130138
verify=True,
131139
)
132-
response = MagicMock()
133-
response.status_code = 200
134-
response.json.return_value = json.loads("""{"access_token": "abc", "expires_in": 60}""")
135-
mock_requests.post.return_value = response
140+
136141
authn.refresh_credentials()
137142

138143
assert authn._creds
144+
assert authn._creds.access_token == "abc"
139145
assert authn._scopes == expected_scopes

0 commit comments

Comments
 (0)