(token)
| 137 | |
| 138 | |
| 139 | def 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 | |
| 173 | def test_fetch_token_get(token): |
nothing calls this directly
no test coverage detected
searching dependent graphs…