本文整理汇总了Python中inbox.events.google.GoogleEventsProvider类的典型用法代码示例。如果您正苦于以下问题:Python GoogleEventsProvider类的具体用法?Python GoogleEventsProvider怎么用?Python GoogleEventsProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GoogleEventsProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_handle_quota_exceeded
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: remote_create_event
def remote_create_event(account, event, db_session, extra_args):
provider = GoogleEventsProvider(account.id, account.namespace.id)
result = provider.create_remote_event(event, **extra_args)
# The events crud API assigns a random uid to an event when creating it.
# We need to update it to the value returned by the Google calendar API.
event.uid = result['id']
db_session.commit()
示例3: EventSync
class EventSync(BaseSyncMonitor):
"""Per-account event sync engine."""
def __init__(self, email_address, provider_name, account_id, namespace_id,
poll_frequency=300):
bind_context(self, 'eventsync', account_id)
# Only Google for now, can easily parametrize by provider later.
self.provider = GoogleEventsProvider(account_id, namespace_id)
BaseSyncMonitor.__init__(self,
account_id,
namespace_id,
email_address,
EVENT_SYNC_FOLDER_ID,
EVENT_SYNC_FOLDER_NAME,
provider_name,
poll_frequency=poll_frequency)
def sync(self):
"""Query a remote provider for updates and persist them to the
database. This function runs every `self.poll_frequency`.
"""
self.log.info('syncing events')
# Get a timestamp before polling, so that we don't subsequently miss
# remote updates that happen while the poll loop is executing.
sync_timestamp = datetime.utcnow()
with session_scope() as db_session:
account = db_session.query(Account).get(self.account_id)
last_sync = account.last_synced_events
try:
deleted_uids, calendar_changes = self.provider.sync_calendars()
except AccessNotEnabledError:
self.log.warning(
'Access to provider calendar API not enabled; bypassing sync')
return
with session_scope() as db_session:
handle_calendar_deletes(self.namespace_id, deleted_uids,
self.log, db_session)
calendar_uids_and_ids = handle_calendar_updates(self.namespace_id,
calendar_changes,
self.log,
db_session)
db_session.commit()
for (uid, id_) in calendar_uids_and_ids:
deleted_uids, event_changes = self.provider.sync_events(
uid, sync_from_time=last_sync)
with session_scope() as db_session:
handle_event_deletes(self.namespace_id, id_, deleted_uids,
self.log, db_session)
handle_event_updates(self.namespace_id, id_, event_changes,
self.log, db_session)
db_session.commit()
with session_scope() as db_session:
account = db_session.query(Account).get(self.account_id)
account.last_synced_events = sync_timestamp
db_session.commit()
示例4: remote_create_event
def remote_create_event(account, event, db_session):
provider = GoogleEventsProvider(account.id, account.namespace.id)
dump = provider.dump_event(event)
service = provider._get_google_service()
result = service.events().insert(calendarId=event.calendar.name,
body=dump).execute()
# The events crud API assigns a random uid to an event when creating it.
# We need to update it to the value returned by the Google calendar API.
event.uid = result['id']
db_session.commit()
示例5: test_handle_unparseable_dates
def test_handle_unparseable_dates():
raw_response = [{
'id': '20140615_60o30dr564o30c1g60o30dr4ck',
'start': {'date': '0000-01-01'},
'end': {'date': '0000-01-02'},
'summary': 'test'
}]
provider = GoogleEventsProvider(1, 1)
provider._get_raw_events = mock.MagicMock(
return_value=raw_response)
updates = provider.sync_events('uid', 1)
assert len(updates) == 0
示例6: test_cancelled_override_creation
def test_cancelled_override_creation():
# With showDeleted=True, we receive cancelled events (including instances
# of recurring events) as full event objects, with status = 'cancelled'.
# Test that we save this as a RecurringEventOverride rather than trying
# to delete the UID.
raw_response = [{
'created': '2012-10-09T22:35:50.000Z',
'creator': {
'displayName': 'Eben Freeman',
'email': '[email protected]',
'self': True
},
'end': {'dateTime': '2012-10-22T19:00:00-07:00'},
'etag': '"2806773858144000"',
'htmlLink': 'https://www.google.com/calendar/event?eid=FOO',
'iCalUID': '[email protected]',
'id': 'tn7krk4cekt8ag3pk6gapqqbro_20121022T170000Z',
'kind': 'calendar#event',
'organizer': {
'displayName': 'Eben Freeman',
'email': '[email protected]om',
'self': True
},
'attendees': [
{'displayName': 'MITOC BOD',
'email': '[email protected]',
'responseStatus': 'accepted'},
{'displayName': 'Eben Freeman',
'email': '[email protected]',
'responseStatus': 'accepted'}
],
'originalStartTime': {
'dateTime': '2012-10-22T17:00:00-07:00',
'timeZone': 'America/Los_Angeles'
},
'recurringEventId': 'tn7krk4cekt8ag3pk6gapqqbro',
'reminders': {'useDefault': True},
'sequence': 0,
'start': {'dateTime': '2012-10-22T18:00:00-07:00',
'timeZone': 'America/Los_Angeles'},
'status': 'cancelled',
'summary': 'BOD Meeting',
}]
provider = GoogleEventsProvider(1, 1)
provider._get_raw_events = mock.MagicMock(
return_value=raw_response)
updates = provider.sync_events('uid', 1)
assert updates[0].cancelled is True
示例7: test_handle_internal_server_error
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']
示例8: test_handle_http_401
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
示例9: test_pagination
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']
示例10: test_handle_api_not_enabled
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')
示例11: __init__
def __init__(self, email_address, provider_name, account_id, namespace_id,
poll_frequency=POLL_FREQUENCY):
bind_context(self, 'eventsync', account_id)
# Only Google for now, can easily parametrize by provider later.
self.provider = GoogleEventsProvider(account_id, namespace_id)
BaseSyncMonitor.__init__(self,
account_id,
namespace_id,
email_address,
EVENT_SYNC_FOLDER_ID,
EVENT_SYNC_FOLDER_NAME,
provider_name,
poll_frequency=poll_frequency)
示例12: test_handle_other_errors
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')
示例13: remote_delete_event
def remote_delete_event(account, event, db_session):
provider = GoogleEventsProvider(account.id, account.namespace.id)
service = provider._get_google_service()
service.events().delete(calendarId=event.calendar.name,
eventId=event.uid).execute()
示例14: remote_update_event
def remote_update_event(account, event, db_session):
provider = GoogleEventsProvider(account.id, account.namespace.id)
dump = provider.dump_event(event)
service = provider._get_google_service()
service.events().update(calendarId=event.calendar.name,
eventId=event.uid, body=dump).execute()
示例15: remote_create
def remote_create(account, event, db_session):
provider = GoogleEventsProvider(account.id, account.namespace.id)
dump = provider.dump_event(event)
service = provider._get_google_service()
service.events().insert(calendarId='primary', body=dump).execute()