@@ -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