本文整理汇总了Python中inbox.events.google.GoogleEventsProvider._get_access_token方法的典型用法代码示例。如果您正苦于以下问题:Python GoogleEventsProvider._get_access_token方法的具体用法?Python GoogleEventsProvider._get_access_token怎么用?Python GoogleEventsProvider._get_access_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inbox.events.google.GoogleEventsProvider
的用法示例。
在下文中一共展示了GoogleEventsProvider._get_access_token方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_handle_quota_exceeded
# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import _get_access_token [as 别名]
def test_handle_quota_exceeded():
first_response = requests.Response()
first_response.status_code = 403
first_response._content = json.dumps({
'error': {
'errors': [
{'domain': 'usageLimits',
'reason': 'userRateLimitExceeded',
'message': 'User Rate Limit Exceeded'}
],
'code': 403,
'message': 'User Rate Limit Exceeded'
}
})
second_response = requests.Response()
second_response.status_code = 200
second_response._content = json.dumps({
'items': ['A', 'B', 'C']
})
requests.get = mock.Mock(side_effect=[first_response, second_response])
gevent.sleep = mock.Mock()
provider = GoogleEventsProvider(1, 1)
provider._get_access_token = mock.Mock(return_value='token')
items = provider._get_resource_list('https://googleapis.com/testurl')
# Check that we slept, then retried.
assert gevent.sleep.called
assert items == ['A', 'B', 'C']
示例2: test_handle_other_errors
# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import _get_access_token [as 别名]
def test_handle_other_errors():
response = requests.Response()
response.status_code = 403
response._content = "This is not the JSON you're looking for"
requests.get = mock.Mock(return_value=response)
provider = GoogleEventsProvider(1, 1)
provider._get_access_token = mock.Mock(return_value='token')
with pytest.raises(requests.exceptions.HTTPError):
provider._get_resource_list('https://googleapis.com/testurl')
response = requests.Response()
response.status_code = 404
requests.get = mock.Mock(return_value=response)
provider = GoogleEventsProvider(1, 1)
provider._get_access_token = mock.Mock(return_value='token')
with pytest.raises(requests.exceptions.HTTPError):
provider._get_resource_list('https://googleapis.com/testurl')
示例3: test_handle_http_401
# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import _get_access_token [as 别名]
def test_handle_http_401():
first_response = requests.Response()
first_response.status_code = 401
second_response = requests.Response()
second_response.status_code = 200
second_response._content = json.dumps({
'items': ['A', 'B', 'C']
})
requests.get = mock.Mock(side_effect=[first_response, second_response])
provider = GoogleEventsProvider(1, 1)
provider._get_access_token = mock.Mock(return_value='token')
items = provider._get_resource_list('https://googleapis.com/testurl')
assert items == ['A', 'B', 'C']
# Check that we actually refreshed the access token
assert len(provider._get_access_token.mock_calls) == 2
示例4: test_handle_internal_server_error
# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import _get_access_token [as 别名]
def test_handle_internal_server_error(patched_gevent_sleep):
first_response = requests.Response()
first_response.status_code = 503
second_response = requests.Response()
second_response.status_code = 200
second_response._content = json.dumps({
'items': ['A', 'B', 'C']
})
requests.get = mock.Mock(side_effect=[first_response, second_response])
provider = GoogleEventsProvider(1, 1)
provider._get_access_token = mock.Mock(return_value='token')
items = provider._get_resource_list('https://googleapis.com/testurl')
# Check that we slept, then retried.
assert gevent.sleep.called
assert items == ['A', 'B', 'C']
示例5: test_pagination
# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import _get_access_token [as 别名]
def test_pagination():
first_response = requests.Response()
first_response.status_code = 200
first_response._content = json.dumps({
'items': ['A', 'B', 'C'],
'nextPageToken': 'CjkKKzlhb2tkZjNpZTMwNjhtZThllU'
})
second_response = requests.Response()
second_response.status_code = 200
second_response._content = json.dumps({
'items': ['D', 'E']
})
requests.get = mock.Mock(side_effect=[first_response, second_response])
provider = GoogleEventsProvider(1, 1)
provider._get_access_token = mock.Mock(return_value='token')
items = provider._get_resource_list('https://googleapis.com/testurl')
assert items == ['A', 'B', 'C', 'D', 'E']
示例6: test_handle_api_not_enabled
# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import _get_access_token [as 别名]
def test_handle_api_not_enabled():
response = requests.Response()
response.status_code = 403
response._content = json.dumps({
'error': {
'code': 403,
'message': 'Access Not Configured.',
'errors': [
{'domain': 'usageLimits', 'message': 'Access Not Configured',
'reason': 'accessNotConfigured',
'extendedHelp': 'https://console.developers.google.com'}
]
}
})
requests.get = mock.Mock(return_value=response)
provider = GoogleEventsProvider(1, 1)
provider._get_access_token = mock.Mock(return_value='token')
with pytest.raises(AccessNotEnabledError):
provider._get_resource_list('https://googleapis.com/testurl')