def _step1_get_device_and_user_codes_helper(
self, extra_headers=None, user_agent=None, default_http=False,
content=None):
flow = client.OAuth2WebServerFlow('CID', scope='foo',
user_agent=user_agent)
device_code = 'bfc06756-062e-430f-9f0f-460ca44724e5'
user_code = '5faf2780-fc83-11e5-9bc2-00c2c63e5792'
ver_url = 'http://foo.bar'
if content is None:
content = json.dumps({
'device_code': device_code,
'user_code': user_code,
'verification_url': ver_url,
})
http = http_mock.HttpMockSequence([
({'status': http_client.OK}, content),
])
if default_http:
with mock.patch('oauth2client.transport.get_http_object',
return_value=http) as new_http:
result = flow.step1_get_device_and_user_codes()
# Check the mock was called.
new_http.assert_called_once_with()
else:
result = flow.step1_get_device_and_user_codes(http=http)
expected = client.DeviceFlowInfo(
device_code, user_code, None, ver_url, None)
self.assertEqual(result, expected)
self.assertEqual(len(http.requests), 1)
info = http.requests[0]
self.assertEqual(info['uri'], oauth2client.GOOGLE_DEVICE_URI)
expected_body = {
'client_id': [flow.client_id],
'scope': [flow.scope],
}
self.assertEqual(urllib.parse.parse_qs(info['body']), expected_body)
headers = {'content-type': 'application/x-www-form-urlencoded'}
if extra_headers is not None:
headers.update(extra_headers)
self.assertEqual(info['headers'], headers)
评论列表
文章目录