Skip to content

Commit 699b2dc

Browse files
committed
Add _obtain_token(..., post=lambda ...) so you don't need to patch
1 parent 329ba0f commit 699b2dc

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

oauth2cli/oauth2.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ def _obtain_token( # The verb "obtain" is influenced by OAUTH2 RFC 6749
108108
data=None, # All relevant data, which will go into the http body
109109
headers=None, # a dict to be sent as request headers
110110
timeout=None,
111+
post=None, # A callable to replace requests.post(), for testing.
112+
# Such as: lambda url, **kwargs:
113+
# Mock(status_code=200, json=Mock(return_value={}))
111114
**kwargs # Relay all extra parameters to underlying requests
112115
): # Returns the json object came from the OAUTH2 response
113116
_data = {'client_id': self.client_id, 'grant_type': grant_type}
@@ -133,7 +136,7 @@ def _obtain_token( # The verb "obtain" is influenced by OAUTH2 RFC 6749
133136
raise ValueError("token_endpoint not found in configuration")
134137
_headers = {'Accept': 'application/json'}
135138
_headers.update(headers or {})
136-
resp = self.session.post(
139+
resp = (post or self.session.post)(
137140
self.configuration["token_endpoint"],
138141
headers=_headers, params=params, data=_data, auth=auth,
139142
timeout=timeout or self.timeout,

0 commit comments

Comments
 (0)