本文整理匯總了Python中fitbit.Fitbit.make_request方法的典型用法代碼示例。如果您正苦於以下問題:Python Fitbit.make_request方法的具體用法?Python Fitbit.make_request怎麽用?Python Fitbit.make_request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類fitbit.Fitbit
的用法示例。
在下文中一共展示了Fitbit.make_request方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_auto_refresh_token_exception
# 需要導入模塊: from fitbit import Fitbit [as 別名]
# 或者: from fitbit.Fitbit import make_request [as 別名]
def test_auto_refresh_token_exception(self):
"""Test of auto_refresh with Unauthorized exception"""
# 1. first call to _request causes a HTTPUnauthorized
# 2. the token_refresh call is faked
# 3. the second call to _request returns a valid value
refresh_cb = mock.MagicMock()
kwargs = copy.copy(self.client_kwargs)
kwargs.update({
'access_token': 'fake_access_token',
'refresh_token': 'fake_refresh_token',
'refresh_cb': refresh_cb,
})
fb = Fitbit(**kwargs)
profile_url = Fitbit.API_ENDPOINT + '/1/user/-/profile.json'
with requests_mock.mock() as m:
m.get(profile_url, [{
'text': json.dumps({
"errors": [{
"errorType": "expired_token",
"message": "Access token expired:"
}]
}),
'status_code': 401
}, {
'text': '{"user":{"aboutMe": "python-fitbit developer"}}',
'status_code': 200
}])
token = {
'access_token': 'fake_return_access_token',
'refresh_token': 'fake_return_refresh_token'
}
m.post(fb.client.refresh_token_url, text=json.dumps(token))
retval = fb.make_request(profile_url)
self.assertEqual(m.request_history[1].path, '/oauth2/token')
self.assertEqual(
m.request_history[1].headers['Authorization'],
_basic_auth_str(
self.client_kwargs['client_id'],
self.client_kwargs['client_secret']
)
)
self.assertEqual(retval['user']['aboutMe'], "python-fitbit developer")
self.assertEqual("fake_return_access_token", token['access_token'])
self.assertEqual("fake_return_refresh_token", token['refresh_token'])
refresh_cb.assert_called_once_with(token)