Skip to content

Commit

Permalink
add test for oauth password flow with client secrets and extra params
Browse files Browse the repository at this point in the history
  • Loading branch information
ekneg54 committed Mar 25, 2024
1 parent c386f19 commit eab348f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/unit/util/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest import mock

import pytest
import requests
import responses
from requests import Session
from responses import matchers
Expand Down Expand Up @@ -653,6 +654,38 @@ def test_get_session_error_handling(self, error_reason):
with pytest.raises(CredentialsBadRequestError, match=error_message):
_ = test.get_session()

@responses.activate
def test_get_session_error_handling_for_status_code_not_400(self):
test = OAuth2ClientFlowCredentials(
endpoint="https://the.endpoint",
client_secret="very secret password",
client_id="allmighty_client_id",
)
responses.add(
responses.POST,
"https://the.endpoint",
json={
"error": "this is a custom application error",
},
status=503,
match=[
matchers.urlencoded_params_matcher(
{
"grant_type": "client_credentials",
}
),
matchers.header_matcher(
{
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic YWxsbWlnaHR5X2NsaWVudF9pZDp2ZXJ5IHNlY3JldCBwYXNzd29yZA==",
}
),
],
)
error_message = r"Service Unavailable for url"
with pytest.raises(requests.HTTPError, match=error_message):
_ = test.get_session()


class TestCredentialsFactory:

Expand Down

0 comments on commit eab348f

Please sign in to comment.