From 858e96b15db090efd1b99acb7a0473d5e830788b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Gr=C3=A4tz?= Date: Fri, 25 Aug 2023 17:32:17 +0200 Subject: [PATCH] Make test_client_creds_authenticator_with_custom_scopes test work and more specific MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio Grätz --- .../unit/clients/auth/test_authenticator.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/flytekit/unit/clients/auth/test_authenticator.py b/tests/flytekit/unit/clients/auth/test_authenticator.py index f23019f6078..82ffa654ddb 100644 --- a/tests/flytekit/unit/clients/auth/test_authenticator.py +++ b/tests/flytekit/unit/clients/auth/test_authenticator.py @@ -118,9 +118,17 @@ def test_device_flow_authenticator(poll_mock: MagicMock, device_mock: MagicMock, assert authn._creds -@patch("flytekit.clients.auth.token_client.requests") -def test_client_creds_authenticator_with_custom_scopes(mock_requests): +@patch("flytekit.clients.auth.token_client.requests.Session") +def test_client_creds_authenticator_with_custom_scopes(mock_session): expected_scopes = ["foo", "baz"] + + session = MagicMock() + response = MagicMock() + response.status_code = 200 + response.json.return_value = json.loads("""{"access_token": "abc", "expires_in": 60}""") + session.post.return_value = response + mock_session.return_value = session + authn = ClientCredentialsAuthenticator( ENDPOINT, client_id="client", @@ -129,11 +137,9 @@ def test_client_creds_authenticator_with_custom_scopes(mock_requests): scopes=expected_scopes, verify=True, ) - response = MagicMock() - response.status_code = 200 - response.json.return_value = json.loads("""{"access_token": "abc", "expires_in": 60}""") - mock_requests.post.return_value = response + authn.refresh_credentials() assert authn._creds + assert authn._creds.access_token == "abc" assert authn._scopes == expected_scopes