当前位置: 首页>>代码示例>>Python>>正文


Python GoogleEventsProvider._get_resource_list方法代码示例

本文整理汇总了Python中inbox.events.google.GoogleEventsProvider._get_resource_list方法的典型用法代码示例。如果您正苦于以下问题:Python GoogleEventsProvider._get_resource_list方法的具体用法?Python GoogleEventsProvider._get_resource_list怎么用?Python GoogleEventsProvider._get_resource_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inbox.events.google.GoogleEventsProvider的用法示例。


在下文中一共展示了GoogleEventsProvider._get_resource_list方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_handle_quota_exceeded

# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import _get_resource_list [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']
开发者ID:nohobby,项目名称:sync-engine,代码行数:31,代码来源:test_google_events.py

示例2: test_handle_other_errors

# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import _get_resource_list [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')
开发者ID:nohobby,项目名称:sync-engine,代码行数:19,代码来源:test_google_events.py

示例3: test_handle_api_not_enabled

# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import _get_resource_list [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')
开发者ID:nohobby,项目名称:sync-engine,代码行数:22,代码来源:test_google_events.py

示例4: test_handle_http_401

# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import _get_resource_list [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
开发者ID:nohobby,项目名称:sync-engine,代码行数:19,代码来源:test_google_events.py

示例5: test_handle_internal_server_error

# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import _get_resource_list [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']
开发者ID:rjmcguire,项目名称:sync-engine,代码行数:19,代码来源:test_google_events.py

示例6: test_pagination

# 需要导入模块: from inbox.events.google import GoogleEventsProvider [as 别名]
# 或者: from inbox.events.google.GoogleEventsProvider import _get_resource_list [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']
开发者ID:nohobby,项目名称:sync-engine,代码行数:20,代码来源:test_google_events.py


注:本文中的inbox.events.google.GoogleEventsProvider._get_resource_list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。