MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / test_fetch_token

Method test_fetch_token

tests/auth/test_flows.py:85–117  ·  view source on GitHub ↗
(self, m)

Source from the content-addressed store, hash-verified

83
84 @requests_mock.Mocker()
85 def test_fetch_token(self, m):
86 # mock the token_endpoint
87 code = '123456'
88 expected_params = dict(
89 grant_type='authorization_code', client_id=self.client_id,
90 redirect_uri=self.redirect_uri_oob, code=code)
91
92 def post_body_matcher(request):
93 params = dict(parse_qsl(request.text))
94 return params == expected_params
95
96 m.get(requests_mock.ANY, status_code=404)
97 m.post(requests_mock.ANY, status_code=404)
98 m.post(self.token_endpoint, json=dict(error="error", error_description="bad request"))
99 m.post(self.token_endpoint, additional_matcher=post_body_matcher, json=self.token)
100
101 # reset creds
102 self.creds.clear()
103
104 # make auth request to generate all request params (like PKCE's verifier)
105 flow = AuthFlow(**self.test_args)
106 _ = flow.get_authorization_url()
107 expected_params.update(code_verifier=flow.code_verifier)
108
109 # verify token fetch flow
110 response = flow.fetch_token(code=code)
111 self.assertEqual(response, self.token)
112
113 # verify token proxy to oauth2 session
114 self.assertEqual(flow.token, self.token)
115
116 # verify token saved to creds
117 self.assertEqual(flow.creds[flow.leap_api_endpoint], self.token)
118
119 def test_token_setter(self):
120 flow = AuthFlow(**self.test_args)

Callers

nothing calls this directly

Calls 6

get_authorization_urlMethod · 0.95
fetch_tokenMethod · 0.95
AuthFlowClass · 0.90
clearMethod · 0.80
getMethod · 0.45
postMethod · 0.45

Tested by

no test coverage detected