MCPcopy
hub / github.com/authlib/authlib / test_fetch_token_post

Function test_fetch_token_post

tests/clients/test_requests/test_oauth2_session.py:139–170  ·  view source on GitHub ↗
(token)

Source from the content-addressed store, hash-verified

137
138
139def test_fetch_token_post(token):
140 url = "https://provider.test/token"
141
142 def fake_send(r, **kwargs):
143 assert "code=v" in r.body
144 assert "client_id=" in r.body
145 assert "grant_type=authorization_code" in r.body
146 resp = mock.MagicMock()
147 resp.status_code = 200
148 resp.json = lambda: token
149 return resp
150
151 sess = OAuth2Session(client_id="foo")
152 sess.send = fake_send
153 assert (
154 sess.fetch_token(url, authorization_response="https://provider.test/?code=v")
155 == token
156 )
157
158 sess = OAuth2Session(
159 client_id="foo",
160 token_endpoint_auth_method="none",
161 )
162 sess.send = fake_send
163 token = sess.fetch_token(url, code="v")
164 assert token == token
165
166 error = {"error": "invalid_request"}
167 sess = OAuth2Session(client_id="foo", token=token)
168 sess.send = mock_json_response(error)
169 with pytest.raises(OAuthError):
170 sess.fetch_access_token(url)
171
172
173def test_fetch_token_get(token):

Callers

nothing calls this directly

Calls 4

fetch_access_tokenMethod · 0.95
OAuth2SessionClass · 0.90
mock_json_responseFunction · 0.85
fetch_tokenMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…