desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'ERROR: Try to share episodes into a viewpoint which user does
not follow.'
| def testShareViewpointNoAccess(self):
| self.assertRaisesHttpError(403, self._tester.ShareExisting, self._cookie2, self._user.private_vp_id, [(self._existing_ep_id, self._photo_ids)])
|
'Share two photos to a new episode in an existing viewpoint.'
| def testShareMultiple(self):
| self._tester.ShareExisting(self._cookie, self._existing_vp_id, [(self._episode_id, self._photo_ids)])
|
'Share photos back into a new episode in the same viewpoint.'
| def testShareBack(self):
| self._tester.ShareExisting(self._cookie, self._existing_vp_id, [(self._existing_ep_id, self._photo_ids2)])
|
'Share empty episode list.'
| def testShareNoEpisodes(self):
| self._tester.ShareExisting(self._cookie, self._existing_vp_id, [])
|
'Share photos from multiple episodes.'
| def testShareMultipleEpisodes(self):
| self._tester.ShareExisting(self._cookie, self._existing_vp_id, [(self._episode_id, self._photo_ids), (self._existing_ep_id, self._photo_ids2)])
|
'Share same photos from same source episode to same target episode
in new viewpoint.'
| def testShareDuplicatePhotos(self):
| share_list = [{'existing_episode_id': self._episode_id2, 'new_episode_id': self._existing_ep_id, 'photo_ids': self._photo_ids2}]
self._tester.ShareExisting(self._cookie, self._existing_vp_id, share_list)
self._tester.ShareExisting(self._cookie, self._existing_vp_id, share_list)
|
'Share different photos from same source episode to same target
episode in new viewpoint.'
| def testShareSameEpisode(self):
| (vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids[:1])], [self._user2.user_id])
share_list = [{'existing_episode_id': self._episode_id, 'new_episode_id': ep_ids[0], 'photo_ids': self._photo_ids[1:]}]
self._tester.ShareExisting(self._cookie, vp_id, share_list)
|
'Share photos that were previously unshared (unshare attribute should be removed).'
| def testShareAfterUnshare(self):
| def _CountUnsharedPhotos(ep_id):
response_dict = self._tester.QueryEpisodes(self._cookie, [self._tester.CreateEpisodeSelection(ep_id)])
return len([ph_dict for ph_dict in response_dict['episodes'][0]['photos'] if (('labels' in ph_dict) and ('unshared' in ph_dict['labels']))])
self._tester.Unshar... |
'Share into the same viewpoint with another user.'
| def testShareDifferentUser(self):
| ep_ph_ids = self._UploadOneEpisode(self._cookie2, 5)
self._tester.ShareExisting(self._cookie2, self._existing_vp_id, [ep_ph_ids])
|
'Share multiple photos to same target episode in new viewpoint.'
| def testShareToSameEpisode(self):
| timestamp = time.time()
new_episode_id = Episode.ConstructEpisodeId(timestamp, self._device_ids[0], self._test_id)
self._test_id += 1
share_dict1 = {'existing_episode_id': self._existing_ep_id, 'new_episode_id': new_episode_id, 'photo_ids': self._photo_ids2[:1]}
share_dict2 = {'existing_episode_id':... |
'Share photos to a viewpoint with an unrevivable removed follower.'
| def testUnrevivable(self):
| self._tester.RemoveFollowers(self._cookie, self._existing_vp_id, [self._user2.user_id])
self._tester.ShareExisting(self._cookie, self._existing_vp_id, [(self._episode_id, self._photo_ids)])
response_dict = self._tester.QueryFollowed(self._cookie2)
self.assertIn(Follower.REMOVED, response_dict['viewpoint... |
'Force op failure in order to test idempotency.'
| @mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True)
def testIdempotency(self):
| self._tester.Unshare(self._cookie, self._existing_vp_id, [(self._existing_ep_id, self._photo_ids2)])
self._tester.RemoveViewpoint(self._cookie2, self._existing_vp_id)
self._tester.ShareExisting(self._cookie, self._existing_vp_id, [(self._episode_id, self._photo_ids)])
share_dict = {'existing_episode_id'... |
'ERROR: Try to share to the same episode from multiple parent episodes.'
| def testShareFromMultipleParents(self):
| share_dict = {'existing_episode_id': self._episode_id, 'new_episode_id': self._existing_ep_id, 'photo_ids': self._photo_ids}
self.assertRaisesHttpError(400, self._tester.ShareExisting, self._cookie, self._existing_vp_id, [share_dict])
|
'ERROR: Try to share the same photo multiple times to same episode.'
| def testShareSamePhotoSameEpisode(self):
| timestamp = time.time()
new_episode_id = Episode.ConstructEpisodeId(timestamp, self._device_ids[0], self._test_id)
self._test_id += 1
share_dict = {'existing_episode_id': self._episode_id, 'new_episode_id': new_episode_id, 'photo_ids': self._photo_ids}
self.assertRaisesHttpError(400, self._tester.Sh... |
'ERROR: Try to share photos to existing episode that is not in the target viewpoint.'
| def testWrongViewpoint(self):
| timestamp = time.time()
new_episode_id = Episode.ConstructEpisodeId(timestamp, self._device_ids[0], self._test_id)
self._test_id += 1
share_dict = {'existing_episode_id': self._episode_id, 'new_episode_id': self._episode_id2, 'photo_ids': self._photo_ids}
self.assertRaisesHttpError(400, self._tester... |
'ERROR: Try to create an episode using a device id that is different
than the one in the user cookie.'
| def testWrongDeviceId(self):
| share_list = [self._tester.CreateCopyDict(self._cookie2, self._episode_id, self._photo_ids)]
self.assertRaisesHttpError(403, self._tester.ShareExisting, self._cookie, self._existing_vp_id, share_list)
|
'Share_existing after unsharing everything in a viewpoint. This exercises the new selection
of a cover_photo during share_existing.'
| def testSetCoverPhoto(self):
| from viewfinder.backend.db.viewpoint import Viewpoint
viewpoint = self._RunAsync(Viewpoint.Query, self._client, self._existing_vp_id, col_names=None)
self.assertEqual(viewpoint.cover_photo['episode_id'], self._existing_ep_id)
self.assertEqual(viewpoint.cover_photo['photo_id'], sorted(self._photo_ids2)[0... |
'Test share_existing when auto-save is enabled by follower(s).'
| def testAutoSave(self):
| self._UpdateOrAllocateDBObject(User, user_id=self._user3.user_id, asset_id_seq=1000)
(vp_id, ep_id) = self._ShareSimpleTestAssets([self._user2.user_id, self._user3.user_id])
(upload_ep_id1, upload_ph_ids1) = self._UploadOneEpisode(self._cookie3, 2)
(upload_ep_id2, upload_ph_ids2) = self._UploadOneEpisod... |
'Enable auto-save, then remove the follower, then share to the viewpoint.'
| def testRemovedFollowerAutoSave(self):
| self._tester.UpdateFollower(self._cookie2, self._existing_vp_id, labels=[Follower.CONTRIBUTE, Follower.AUTOSAVE])
self._tester.RemoveViewpoint(self._cookie2, self._existing_vp_id)
self._tester.ShareExisting(self._cookie, self._existing_vp_id, [(self._episode_id, self._photo_ids[:1])])
self.assertEqual(s... |
'Remove photos from default and shared viewpoints.'
| def testRemovePhotos(self):
| (ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 9)
self._OldRemovePhotos(self._cookie, [(ep_id, ph_ids[::2])])
(vp_id, new_ep_ids) = self._tester.ShareNew(self._cookie, [(ep_id, ph_ids[1::2])], [self._user2.user_id])
self._OldRemovePhotos(self._cookie, [(new_ep_ids[0], ph_ids[1::2])])
|
'Remove photos from multiple episodes.'
| def testRemoveMultipleEpisodes(self):
| ep_ph_ids_list = self._UploadMultipleEpisodes(self._cookie, 17)
(vp_id, new_ep_ids) = self._tester.ShareNew(self._cookie, ep_ph_ids_list, [self._user3.user_id])
ep_ph_ids_list2 = [(new_ep_id, ph_ids[::3]) for (new_ep_id, (old_ep_id, ph_ids)) in zip(new_ep_ids, ep_ph_ids_list)[::2]]
self._OldRemovePhotos... |
'Remove the same photos multiple times.'
| def testRemoveDuplicatePhotos(self):
| (ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 3)
self._OldRemovePhotos(self._cookie, [(ep_id, ph_ids)])
self._OldRemovePhotos(self._cookie, [(ep_id, ph_ids)])
self._OldRemovePhotos(self._cookie, [(ep_id, (ph_ids + ph_ids))])
|
'Force op failure in order to test idempotency.'
| @mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True)
def testIdempotency(self):
| (ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 2)
self._OldRemovePhotos(self._cookie, [(ep_id, ph_ids[:1])])
self._OldRemovePhotos(self._cookie, [(ep_id, ph_ids)])
(ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 2)
(vp_id, new_ep_ids) = self._tester.ShareNew(self._cookie, [(ep_id, ph_... |
'ERROR: Remove from an episode without a POST entry.'
| def testRemoveNonExistingPhoto(self):
| (ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 3)
self.assertRaisesHttpError(400, self._OldRemovePhotos, self._cookie, [(ep_id, ['punknown'])])
|
'ERROR: Remove from a non-existing episode.'
| def testRemoveFromNonExistingEpisode(self):
| (ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 3)
self.assertRaisesHttpError(400, self._OldRemovePhotos, self._cookie, [('eunknown', ph_ids)])
|
'ERROR: Ensure that only photos visible to the user can be removed.'
| def testRemovePhotosAccess(self):
| (ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 1)
self.assertRaisesHttpError(403, self._OldRemovePhotos, self._cookie2, [(ep_id, ph_ids)])
(vp_id, new_ep_ids) = self._tester.ShareNew(self._cookie, [(ep_id, ph_ids)], [self._user2.user_id])
self.assertRaisesHttpError(403, self._OldRemovePhotos, se... |
'remove_photos: Removes photos from a user\'s personal library in older clients.
"ep_ph_ids_list" is a list of tuples in this format:
[(episode, [photo_id, ...]), ...]'
| def _OldRemovePhotos(self, user_cookie, ep_ph_ids_list):
| request_dict = {'episodes': [{'episode_id': episode_id, 'photo_ids': photo_ids} for (episode_id, photo_ids) in ep_ph_ids_list]}
_TestOldRemovePhotos(self._tester, user_cookie, request_dict)
|
'Test creation of a prospective user.'
| def testProspectiveUser(self):
| (user, vp_id, ep_id) = self._CreateProspectiveUser()
self.assertEqual(user.asset_id_seq, 1)
settings = self._RunAsync(AccountSettings.QueryByUser, self._client, user.user_id, None)
self.assertEqual(settings.email_alerts, AccountSettings.EMAIL_ON_SHARE_NEW)
self.assertEqual(settings.sms_alerts, Accou... |
'Test that users that are part of the "Welcome to Viewfinder" conversation are created.'
| @mock.patch.object(system_users, 'NARRATOR_USER', None)
def testWelcomeUsers(self):
| def _TestUser(email):
identity = self._RunAsync(Identity.Query, self._client, ('Email:%s' % email), None)
self.assertEqual(identity.authority, 'Viewfinder')
user = self._RunAsync(User.Query, self._client, identity.user_id, None)
self.assertTrue(user.IsRegistered())
self.asser... |
'Test that welcome conversation is created for new users.'
| @mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True)
@mock.patch.object(system_users, 'NARRATOR_USER', None)
def testWelcomeConversation(self):
| self._validate = False
validator = self._tester.validator
self._RunAsync(CreateSystemUsers, self._client)
request_dict = {'activity': self._tester.CreateActivityDict(self._cookie), 'viewpoint_id': self._vp_id, 'contacts': self._tester.CreateContactDicts(['Email:prospective@emailscrubbed.com', 'Email:pro... |
'Test basic unlinking of identities.'
| def testUnlinkIdentity(self):
| self._tester.LinkFacebookUser({'id': 100}, user_cookie=self._cookie)
self.assertEqual(len(self._tester.ListIdentities(self._cookie)), 2)
self._tester.UnlinkIdentity(self._cookie, 'FacebookGraph:100')
self._tester.UnlinkIdentity(self._cookie, 'FacebookGraph:100')
self.assertEqual(len(self._tester.Lis... |
'Test unlinking identity that is referenced by contacts.'
| def testUnlinkContacts(self):
| for i in xrange(3):
contact_dict = Contact.CreateContactDict(self._users[i].user_id, [('FacebookGraph:100', None)], util._TEST_TIME, Contact.FACEBOOK, rank=i)
self._UpdateOrAllocateDBObject(Contact, **contact_dict)
self._tester.LinkFacebookUser({'id': 100}, user_cookie=self._cookie)
response... |
'Link an identity to a different user after unlinking it.'
| def testLinkAfterUnlink(self):
| self._tester.LinkFacebookUser({'id': 100}, user_cookie=self._cookie)
self._tester.UnlinkIdentity(self._cookie, 'FacebookGraph:100')
self._tester.LinkFacebookUser({'id': 100}, user_cookie=self._cookie2)
self.assertEqual(len(self._tester.ListIdentities(self._cookie2)), 2)
|
'ERROR: Try to unlink an identity that exists, but is not bound to any user.'
| def testUnlinkUnboundIdentity(self):
| identity_key = 'Email:new.user@emailscrubbed.com'
self._UpdateOrAllocateDBObject(Identity, key=identity_key)
self.assertRaisesHttpError(403, self._tester.UnlinkIdentity, self._cookie, identity_key)
|
'ERROR: Try to unlink identity using non-canonical form.'
| def testNonCanonicalId(self):
| self.assertRaisesHttpError(400, self._tester.UnlinkIdentity, self._cookie, 'Email:User1@Yahoo.com')
|
'ERROR: Verify the last authorized identity cannot be unlinked.'
| def testUnlinkLastAuthorizedIdentity(self):
| self.assertRaisesHttpError(403, self._tester.UnlinkIdentity, self._cookie, 'Email:user1@emailscrubbed.com')
|
'ERROR: Verify identity cannot be unlinked without permission.'
| def testUnlinkIdentityWithoutPermission(self):
| self._tester.LinkFacebookUser({'id': 100}, user_cookie=self._cookie)
self.assertRaisesHttpError(403, self._tester.UnlinkIdentity, self._cookie2, 'FacebookGraph:100')
|
'ERROR: Try to unlink identity with unknown scheme.'
| def testUnknownScheme(self):
| self.assertRaisesHttpError(400, self._tester.UnlinkIdentity, self._cookie, 'Unknown:foo')
|
'Tests various viewpoint queries.'
| def testQueryViewpoints(self):
| cookie = self._cookies[0]
self._CreateQueryAssets()
self._all_viewpoints = self._validator.QueryModelObjects(Viewpoint)
vp_count = len(self._all_viewpoints)
self._QueryViewpoints(cookie, self._CreateViewpointSelection([]))
self._QueryViewpoints(cookie, self._CreateViewpointSelection([2]))
se... |
'Shares a subset of episodes with another user and ensures that
only that subset can be retrieved. The service_tester is already
doing this, but correct access control is so important that it
justifies redundant testing.'
| def testEpisodeAccess(self):
| ep_ph_ids_list = self._UploadMultipleEpisodes(self._cookie, num_photos=37)
(vp_id, ep_ids) = self._tester.ShareNew(self._cookie, ep_ph_ids_list[::2], [self._user2.user_id])
selection = self._tester.CreateViewpointSelection(self._user.private_vp_id)
response_dict = self._QueryViewpoints(self._cookie2, [s... |
'Tests that a prospective user does not have access to the content of more than a single
viewpoint and any system viewpoints.'
| def testProspectiveUser(self):
| self._CreateSimpleTestAssets()
(prospective_user, vp_id, ep_id) = self._CreateProspectiveUser()
prospective_cookie = self._tester.GetSecureUserCookie(user_id=prospective_user.user_id, device_id=prospective_user.webapp_dev_id, user_name=None, viewpoint_id=vp_id)
(vp_id2, ep_ids2) = self._tester.ShareNew(... |
'Tests that users who have permanently left the viewpoint are reported correctly.'
| def testRemovedUsers(self):
| self._CreateSimpleTestAssets()
(vp_id, _) = self._ShareSimpleTestAssets([self._user2.user_id, self._user3.user_id])
selection = self._tester.CreateViewpointSelection(vp_id)
self._tester.RemoveViewpoint(self._cookie2, vp_id)
response_dict = self._QueryViewpoints(self._cookie, [selection])
self.as... |
'Given a list of indexes into self._all_viewpoints, return a
selection of the indexed viewpoints that can be passed to
QueryViewpoints.'
| def _CreateViewpointSelection(self, vp_index_list, limit=None, **kwargs):
| return [self._tester.CreateViewpointSelection(self._all_viewpoints[i].viewpoint_id, **kwargs) for i in vp_index_list]
|
'Sends a viewpoint query request using "request_dict". If "fetch_all"
is true, then queries are repeated in case of limits. The "callback"
is invoked when either there are no more viewpoints to query, or a single
query was made and "fetch_all" was specified as False.'
| def _QueryViewpoints(self, cookie, vp_select_list, limit=None, fetch_all=False):
| while True:
response_dict = self._tester.QueryViewpoints(cookie, vp_select_list, limit=limit)
if fetch_all:
response_vp_dict = {vp_dict['viewpoint_id']: vp_dict for vp_dict in response_dict['viewpoints']}
for vp_select in vp_select_list:
response_vp = response... |
'Fetch all contacts via query_contacts.'
| def testQueryContacts(self):
| self._CreateContacts()
response_dict = self._tester.QueryContacts(self._cookie)
self.assertEqual(response_dict['num_contacts'], len(self._contacts))
|
'Fetch contacts via query_contacts with a limit.'
| def testQueryContactsWithLimit(self):
| self._CreateContacts()
response_dict = self._tester.QueryContacts(self._cookie, limit=1)
self.assertEqual(response_dict['num_contacts'], 1)
first_contact = response_dict['contacts'][0]
self.assertTrue(('last_key' in response_dict))
response_dict = self._tester.QueryContacts(self._cookie, start_k... |
'Fetch a contact with no corresponding identity object.'
| def testQueryContactNoIdentity(self):
| self._CreateContact([('Local:1', None)], no_identity=True)
response_dict = self._tester.QueryContacts(self._cookie)
contact_dict = {'identities_properties': [('Local:1', None)], 'contact_source': Contact.GMAIL}
contact_dict['contact_id'] = Contact.CalculateContactId(contact_dict)
contact_dict['ident... |
'Fetch a contact that is bound to a user.'
| def testQueryBoundContact(self):
| self._CreateContact([('Local:1', None, 100)])
response_dict = self._tester.QueryContacts(self._cookie)
contact_dict = {'identities_properties': [('Local:1', None)], 'contact_source': Contact.GMAIL}
contact_dict['contact_id'] = Contact.CalculateContactId(contact_dict)
contact_dict['identities'] = [{'... |
'Creates a number of test contacts. Invokes callback on completion.'
| def _CreateContacts(self):
| self._contacts = [{'name': 'Georgina Cantwell', 'rank': 1, 'identities_properties': [('Local:1', None)]}, {'name': 'Brett Eisenman', 'rank': 2, 'identities_properties': [('Local:2', None, 6)]}, {'name': 'Philip Gaucher', 'rank': 3, 'identities_properties': [('Local:3', None)], 'no_identity': True}, {'name'... |
'Fetch events from a named calendar by year.'
| def testGetCalendar(self):
| response_dict = self._SendRequest('get_calendar', self._cookie, {'calendars': [{'calendar_id': 'EnglishHolidays.ics', 'year': 2009}, {'calendar_id': 'FrenchHolidays.ics', 'year': 2008}]})
cals = response_dict['calendars']
self.assertEqual(len(cals), 2)
self.assertTrue(any([(ev['name'] == u'Boxing Day... |
'Fetch holidays for en_US locale.'
| def testGetHolidaysByLocale_en_US(self):
| self._UpdateOrAllocateDBObject(User, user_id=self._user.user_id, locale='en_US')
response_dict = self._SendRequest('get_calendar', self._cookie, {'calendars': [{'calendar_id': 'holidays', 'year': 2012}]})
cals = response_dict['calendars']
self.assertEqual(len(cals), 1)
for ev_name in [u"President's ... |
'Fetch all holidays for en_US locale for last decade.'
| def testGetAllHolidays_en_US(self):
| self._UpdateOrAllocateDBObject(User, user_id=self._user.user_id, locale='en_US')
response_dict = self._SendRequest('get_calendar', self._cookie, {'calendars': [{'calendar_id': 'holidays', 'year': year} for year in range(2002, 2013)]})
cals = response_dict['calendars']
self.assertEqual(len(cals), 11)
|
'Fetch holidays for year 2012 with Chinese/China locale.'
| def testGetHolidaysByLocale_zh_CN(self):
| self._UpdateOrAllocateDBObject(User, user_id=self._user.user_id, locale='zh_CN')
response_dict = self._SendRequest('get_calendar', self._cookie, {'calendars': [{'calendar_id': 'holidays', 'year': 2012}]})
cals = response_dict['calendars']
self.assertEqual(len(cals), 1)
chinese_ny = [ev for ev in cal... |
'Test sequences of adding and removing a contact.'
| def testAddRemoveContact(self):
| contact_dict = {'contact_source': Contact.MANUAL, 'identities': [{'identity': 'Email:mike@host.com', 'description': 'home'}], 'name': 'Mike Purtell', 'given_name': 'Mike', 'family_name': 'Purtell', 'rank': 42}
self._tester.UploadContacts(self._cookie, [contact_dict])
result = self._tester.QueryContacts(s... |
'Variation on above test which forces op failure in order to test idempotency.'
| @mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True)
def testIdempotency(self):
| contact_dict = {'contact_source': Contact.MANUAL, 'identities': [{'identity': 'Email:mike@host.com', 'description': 'home'}], 'name': 'Mike Purtell', 'given_name': 'Mike', 'family_name': 'Purtell', 'rank': 42}
self._tester.UploadContacts(self._cookie, [contact_dict])
result = self._tester.QueryContacts(s... |
'Try to remove some contacts that don\'t exist and expect a no-op.'
| def testRemoveNonExistingContacts(self):
| remove_contacts = ['ip:lkjasdlfkjasdf', 'm:lkjasdlfkj']
self._tester.RemoveContacts(self._cookie, remove_contacts)
|
'Test exceeding removed contact limit and observe reset notification as well as deletion of all removed
contacts.'
| @mock.patch.object(Contact, 'MAX_CONTACTS_LIMIT', 2)
@mock.patch.object(Contact, 'MAX_REMOVED_CONTACTS_LIMIT', 2)
@mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True)
def testMaxRemovedContactsLimit(self):
| def _CheckExpected(total_present_contact_row_count, total_removed_contact_row_count, reset_removed_contacts_notification):
actual_present_count = 0
actual_removed_count = 0
all_contact_rows = self._RunAsync(Contact.RangeQuery, self._client, self._user.user_id, range_desc=None, limit=100, col... |
'Test fetch of single contact.'
| def testSingleContact(self):
| contacts = self._TestFetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 200, 'name': 'Rachel Kimball'}]})
self.assertEqual(contacts[0].identities_properties[0], ['FacebookGraph:200', None])
self.assertEqual(contacts[0].name, 'Rachel Kimball')
contacts = self._TestFetchCon... |
'Test fetch of contacts using an identity with an authority that we don\'t support.'
| def testSingleContactWithUnsupportedAuthority(self):
| identity_key = ('Email:' + self._user.email)
identity = self._RunAsync(Identity.Query, self._client, identity_key, None)
identity.access_token = '123'
self._RunAsync(identity.Update, self._client)
self._validator.ValidateUpdateDBObject(Identity, **identity._asdict())
self._FetchContacts(identity... |
'Test fetch of multiple contacts.'
| def testMultipleContacts(self):
| contacts = self._TestFetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 200, 'name': 'Rachel Kimball'}, {'id': 300, 'name': 'Mike Purtell'}, {'id': 400, 'name': 'Matt Tracy'}]})
self.assertEqual(len(contacts), 3)
contacts = self._TestFetchContacts(self._andy_google, self._... |
'Fetch a contact with just an invalid phone number and observe that the contact isn\'t fetched.
This is because we only accept fetched contacts that have at least one valid identity.'
| def testInvalidPhoneNumbers(self):
| contacts = self._TestFetchContacts(self._andy_google, self._andy_user.user_id, self._CreateGoogleContactFeed([{'phones': [('1fss3193770219', None)], 'name': 'J. Smith'}]))
self.assertEqual(len(contacts), 0)
|
'Check mapping of Google\'s wellknown contact relations.'
| def testGMailRelField(self):
| feed = self._CreateGoogleContactFeed([{'emails': [('mike@emailscrubbed.com', None)], 'name': 'Mike Purtell'}, {'phones': [('+13191234567', 'Work')], 'name': 'J. Smith'}, {'phones': [('+13195550210', 'cabin')], 'name': 'K. Smith'}])
self.assertEqual(feed['feed']['entry'][0]['gd$email'][0]['rel'], 'http:... |
'Test fetch of no contacts.'
| def testNoContacts(self):
| contacts = self._TestFetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': []}, {'data': []})
self.assertEqual(len(contacts), 0)
contacts = self._TestFetchContacts(self._andy_google, self._andy_user.user_id, self._CreateGoogleContactFeed([]))
self.assertEqual(len(contacts), 0)
contact... |
'Test fetching contacts that don\'t have any identities.
These identities should get skipped during fetch.'
| def testContactsWithoutIdentities(self):
| contacts = self._TestFetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'name': 'Rachel Kimball'}, {'name': 'Rachel Kimball III'}]})
self.assertEqual(len(contacts), 0)
contacts = self._TestFetchContacts(self._andy_google, self._andy_user.user_id, self._CreateGoogleContactFeed([{... |
'Test fetch with duplicate contacts.'
| def testDuplicateContacts(self):
| self._FetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 200, 'name': 'Rachel Kimball'}, {'id': 200, 'name': 'Rachel Kimball'}]})
self._AssertContactCounts(self._andy_user.user_id, 1, 0)
self._FetchContacts(self._andy_google, self._andy_user.user_id, self._CreateGoogleContact... |
'Test fetching contact #1, then contact #2.'
| def testSerialContacts(self):
| self._TestFetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 200, 'name': 'Rachel Kimball'}]})
self._TestFetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 300, 'name': 'Mike Purtell'}]})
self._TestFetchContacts(self._andy_google, self._andy_user.use... |
'Test same contact fetched twice.'
| def testSameContact(self):
| self._TestFetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 200, 'name': 'Rachel Kimball'}]})
self._TestFetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 200, 'name': 'Rachel Kimball'}]})
self._TestFetchContacts(self._andy_google, self._andy_user.u... |
'Test fetching contacts, then same contacts with new names.'
| def testRenamedContacts(self):
| contacts = self._TestFetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 200, 'name': 'Andrew Kimball'}, {'id': 300, 'name': 'Spencer Kimball', 'first_name': 'Spencer'}, {'id': 400, 'name': 'Kathryn Kimball', 'last_name': 'Kimball'}, {'id': 500, 'name': 'Michael Purtell'}, {'id'... |
'Test contact without name.'
| def testMissingName(self):
| contacts = self._TestFetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 200}, {'id': 300, 'name': 'Mike Purtell'}]})
self.assertEqual(len(contacts), 1)
contacts = self._TestFetchContacts(self._andy_google, self._andy_user.user_id, {'feed': {'entry': [{'gd$email': [{'primary': Tr... |
'Test multiple pages of contacts.'
| def testPaging(self):
| with mock.patch('tornado.httpclient.AsyncHTTPClient', MockAsyncHTTPClient()) as mock_client:
photos_dict = {'data': [{'created_time': '2013-01-01 00:00:00', 'from': {'id': 200}}, {'created_time': '2013-01-01 00:00:00', 'from': {'id': 200}}, {'created_time': '2013-01-01 00:00:00', 'from': {'id': 200... |
'Test ranking of person who posted photos.'
| def testPosterRanking(self):
| util._TEST_TIME = time.mktime((2013, 1, 2, 0, 0, 0, 0, 0, 0))
self._TestFetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 200, 'name': 'Rachel Kimball', 'rank': 3}, {'id': 300, 'name': 'Mike Purtell', 'rank': 2}, {'id': 400, 'name': 'Matt Tracy', 'rank': 1}, {'id': 500, 'name... |
'Test ranking of people tagged in photos.'
| def testTaggedRanking(self):
| util._TEST_TIME = time.mktime((2013, 1, 2, 0, 0, 0, 0, 0, 0))
self._TestFetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 200, 'name': 'Rachel Kimball', 'rank': 0}, {'id': 300, 'name': 'Mike Purtell', 'rank': 1}, {'id': 400, 'name': 'Matt Tracy', 'rank': 2}]}, {'data': [{'tag... |
'Test ranking of people who liked photos.'
| def testLikedRanking(self):
| util._TEST_TIME = time.mktime((2013, 1, 2, 0, 0, 0, 0, 0, 0))
self._TestFetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 200, 'name': 'Rachel Kimball', 'rank': 0}, {'id': 300, 'name': 'Mike Purtell', 'rank': 2}, {'id': 400, 'name': 'Matt Tracy', 'rank': 1}, {'id': 500, 'name... |
'Test Google responses containing multiple contact emails.'
| def testMultipleEmails(self):
| feed = {'feed': {'entry': [{'gd$email': [{'address': 'mike@emailscrubbed.com'}]}, {'gd$email': [{'address': 'andy@emailscrubbed.com'}, {'primary': True, 'address': 'kimball.andy@emailscrubbed.com'}]}, {'gd$email': []}, {}], 'openSearch$startIndex': {'$t': '1'}, 'openSearch$totalResults': {'$t': '2'}}}
contacts ... |
'ERROR: Test errors on fetch attempts.'
| def testFetchErrors(self):
| def _RunFetchContactsOperationDirect(identity_key, user_id):
'Invokes the FetchContacts operation for the specified user.'
op = Operation(user_id, Operation.ConstructOperationId(Device.SYSTEM, 1))
op.timestamp = util._TEST_TIME
with EnterOpContext(op):
... |
'Try various sequences of fetches to hit total contacts limit.'
| @mock.patch.object(Contact, 'MAX_CONTACTS_LIMIT', 2)
@mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True)
def testMaxContactsLimit(self):
| self._FetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 200, 'name': 'Andrew Kimball'}]})
util._TEST_TIME += 1
self._AssertContactCounts(self._andy_user.user_id, 1, 0)
self._FetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 600, 'name': 'Peter ... |
'Try various sequences of fetches to hit total contacts limit.'
| @mock.patch.object(Contact, 'MAX_REMOVED_CONTACTS_LIMIT', 2)
@mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True)
def testRemovedContactsReset(self):
| self._FetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 200, 'name': 'Andrew Kimball'}]})
util._TEST_TIME += 1
self._AssertContactCounts(self._andy_user.user_id, 1, 0)
self._FetchContacts(self._andy_facebook, self._andy_user.user_id, {'data': [{'id': 600, 'name': 'Peter ... |
'Checks that the number present and removed contacts, for the given user, matches what\'s expected.'
| def _AssertContactCounts(self, user_id, expected_present_count, expected_removed_count):
| contacts = self._RunAsync(Contact.RangeQuery, self._client, user_id, None, 1000, None)
actual_removed_count = len([c for c in contacts if c.IsRemoved()])
actual_present_count = (len(contacts) - actual_removed_count)
if (expected_present_count != actual_present_count):
self.assertEqual(expected_p... |
'Create simple Google contact field containing list of contacts with a dict containing
the following optional fields:
{\'email\': [(\'andy@emailscrubbed.com\', type), ...], # First one will be primary.
\'phones\': [(\'+13191234567\', type), ...],
\'name\': \'Andy Kimball\',
\'given_name\': \'Andy\',
\'family_name\': \... | def _CreateGoogleContactFeed(self, contact_list):
| feed = {'feed': {'entry': [], 'openSearch$startIndex': {'$t': '1'}, 'openSearch$totalResults': {'$t': str(len(contact_list))}}}
for contact in contact_list:
gd_name = {}
if ('name' in contact):
gd_name['gd$fullName'] = {'$t': contact['name']}
if ('given_name' in contact):
... |
'Fetches contacts from mocked Facebook or Google service.'
| def _FetchContacts(self, identity_key, user_id, people_dict, photos_dict=None):
| with mock.patch('tornado.httpclient.AsyncHTTPClient', MockAsyncHTTPClient()) as mock_client:
photos_dict = (photos_dict or {'data': []})
self._AddMockJSONResponse(mock_client, 'https://graph.facebook.com/me/photos\\?', photos_dict)
self._AddMockJSONResponse(mock_client, 'https://graph.facebo... |
'Invokes the FetchContacts operation for the specified user.'
| def _RunFetchContactsOperation(self, identity_key, user_id):
| request = {'key': identity_key, 'user_id': user_id, 'headers': {'synchronous': True}}
self._RunAsync(Operation.CreateAndExecute, self._client, user_id, Device.SYSTEM, 'FetchContactsOperation.Execute', request)
|
'Adds a mapping entry to the mock client such that requests to "url" will return an HTTP
response containing the JSON-formatted "response_dict".'
| def _AddMockJSONResponse(self, mock_client, url, response_dict):
| def _CreateResponse(request):
return httpclient.HTTPResponse(request, 200, headers={'Content-Type': 'application/json'}, buffer=StringIO(json.dumps(response_dict)))
mock_client.map(url, _CreateResponse)
|
'Validates that corresponding contacts have been created for the people described in
"people_dict". Returns the list of contact objects.'
| def _ValidateContacts(self, identity_key, user_id, people_dict):
| contacts = []
if ('FacebookGraph:' in identity_key):
contact_source = Contact.FACEBOOK
for data in people_dict['data']:
if (('name' in data) and data.has_key('id')):
contacts.append(self._ValidateOneContact(user_id, [(('FacebookGraph:' + str(data.get('id'))), None)], ... |
'Validates that the specified contact has been created, and any previous contacts with
same identity have been deleted. Returns the contact that should exist.'
| def _ValidateOneContact(self, user_id, identities_properties, contact_source, name, given_name, family_name, rank=None):
| contact_dict = Contact.CreateContactDict(user_id, identities_properties, util._TEST_TIME, contact_source, name=name, given_name=given_name, family_name=family_name, rank=rank)
predicate = (lambda contact: (contact_dict['contact_id'] == contact.contact_id))
old_contacts = self._validator.QueryModelObjects(Co... |
'Runs the fetch contacts operation and validates that it creates, updates, and deletes the
expected objects. Returns the list of contacts that should have been created/updated.'
| def _TestFetchContacts(self, identity_key, user_id, people_dict, photos_dict=None):
| self._FetchContacts(identity_key, user_id, people_dict, photos_dict)
contacts = self._ValidateContacts(identity_key, user_id, people_dict)
self._validator.ValidateUpdateDBObject(Identity, key=identity_key, last_fetch=util._TEST_TIME)
util._TEST_TIME += 1
return contacts
|
'Test empty HTTP Content-Type header.'
| def testEmptyContentType(self):
| request_dict = {'headers': {'version': message.MAX_SUPPORTED_MESSAGE_VERSION}}
response = self._RunAsync(self._tester.http_client.fetch, self._tester.GetUrl('/service/query_followed'), method='POST', body=json.dumps(request_dict), headers={'Content-Type': '', 'X-Xsrftoken': 'fake_xsrf', 'Cookie': ('user=%s;_xsr... |
'Ensure that various fields in cookie returned by service handler are correct.'
| def testCookie(self):
| now = time.time()
request_dict = {'headers': {'version': message.MAX_SUPPORTED_MESSAGE_VERSION}}
response = self._RunAsync(self._tester.http_client.fetch, self._tester.GetUrl('/service/query_followed'), method='POST', body=json.dumps(request_dict), headers={'Content-Type': 'application/json', 'Cookie': ('us... |
'Test that error returned by the service handler is properly formed.'
| def testErrorFormat(self):
| request_dict = {'headers': {'version': message.MAX_SUPPORTED_MESSAGE_VERSION}}
response = self._RunAsync(self._tester.http_client.fetch, self._tester.GetUrl('/service/add_followers'), method='POST', body=json.dumps(request_dict), headers={'Content-Type': 'application/json', 'X-Xsrftoken': 'fake_xsrf', 'Cookie':... |
'Test construction of assets using a different device than the calling device.'
| def testAssetIdAltDevice(self):
| ep_dict = self._CreateEpisodeDict(self._cookie)
ep_dict['episode_id'] = Episode.ConstructEpisodeId(time.time(), self._device_ids[2], self._test_id)
self._test_id += 1
ph_dict = self._CreatePhotoDict(self._cookie)
ph_dict['photo_id'] = Photo.ConstructPhotoId(time.time(), self._device_ids[2], self._te... |
'Tests various followed queries.'
| def testQueryFollowed(self):
| self._CreateQueryAssets()
start_key = self._tester.QueryFollowed(self._cookie, limit=1)['last_key']
for user in self._users:
cookie = self._GetSecureUserCookie(user)
self._tester.QueryFollowed(cookie)
self._tester.QueryFollowed(cookie, limit=1)
self._tester.QueryFollowed(cook... |
'Validate that the most recently updated viewpoints are first in
the Followed table.'
| def testOrder(self):
| (episode_id, photo_ids) = self._UploadOneEpisode(self._cookie, 2)
util._TEST_TIME += constants.SECONDS_PER_DAY
act_dict = self._tester.CreateActivityDict(self._cookie)
act_dict['timestamp'] += constants.SECONDS_PER_DAY
vp_dict = self._CreateViewpointDict(self._cookie)
self._tester.ShareNew(self.... |
'Tests that a prospective user can access metadata for all followed viewpoints.'
| def testProspectiveUser(self):
| self._CreateSimpleTestAssets()
(prospective_user, vp_id, ep_id) = self._CreateProspectiveUser()
prospective_cookie = self._tester.GetSecureUserCookie(user_id=prospective_user.user_id, device_id=prospective_user.webapp_dev_id, user_name=None, viewpoint_id=vp_id)
(vp_id2, ep_ids2) = self._tester.ShareNew(... |
'Tests that user who has been removed from a viewpoint can see limited metadata.'
| def testRemovedUser(self):
| self._CreateSimpleTestAssets()
(vp_id, _) = self._ShareSimpleTestAssets([self._user2.user_id])
self._tester.RemoveViewpoint(self._cookie2, vp_id)
response_dict = self._tester.QueryFollowed(self._cookie2)
self.assertEqual(len(response_dict['viewpoints']), 2)
for attr_name in response_dict['viewpo... |
'Test that correct alerts are sent for various operations.'
| def testAlerts(self):
| (vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids)], [self._user2.user_id])
notification = TestService.Instance().GetNotifications('device2')[0]
self.assertEqual(notification, {'sound': 'default', 'expiry': None, 'badge': 1, 'extra': {'v': vp_id}, 'alert': u'user1 ... |
'Verify the alert email for various activity types.'
| def testAlertEmail(self):
| def _Test(client_id, timestamp, vp_dict, episode_id, ph_dict):
ep_dict = {'new_episode_id': episode_id, 'photo_ids': ([ph_dict['photo_id']] if (ph_dict is not None) else [])}
activity_id = Activity.ConstructActivityId(timestamp, 1, client_id)
activity = self._RunAsync(Activity.CreateShareNew... |
'Verify the alert text for various activity types.'
| def testAlertText(self):
| def _Test(expected_text, activity_func, client_id, sharer, viewpoint, *args, **kwargs):
timestamp = time.time()
activity_id = Activity.ConstructActivityId(timestamp, 1, client_id)
activity = self._RunAsync(activity_func, self._client, sharer.user_id, 'v0', activity_id, timestamp, 0, *args, *... |
'Verify the alert SMS message for various activity types.'
| def testAlertSMS(self):
| def _Test(title=None, has_photos=True):
ep_dict = {'new_episode_id': 'e0', 'photo_ids': (['p0'] if has_photos else [])}
activity = self._RunAsync(Activity.CreateShareNew, self._client, user_id=self._test_user.user_id, viewpoint_id='v0', activity_id='a0', timestamp=time.time(), update_seq=0, ep_dicts... |
'Creates a web server which handles /service requests.'
| def get_app(self):
| options.options.localdb = True
options.options.fileobjstore = True
options.options.localdb_dir = ''
options.options.devbox = True
options.options.domain = 'goviewfinder.com'
options.options.short_domain = 'short.goviewfinder.com'
secrets.InitSecretsForTest()
object_store.InitObjectStore(... |
'Fail unless an exception of type HTTPError is raised by callableObj
when invoked with arguments "args" and "kwargs", and unless the status
code is equal to "status_code".'
| def assertRaisesHttpError(self, status_code, callableObj, *args, **kwargs):
| with self.assertRaises(httpclient.HTTPError) as cm:
callableObj(*args, **kwargs)
self.assertEqual(cm.exception.code, status_code)
return cm.exception
|
'"Query for all viewpoints, episodes, and photos in order to make
sure they\'re configured and associated properly with one another.'
| def _ValidateAssets(self):
| logging.info('Validating all viewpoint assets from the vantage point of every test user...')
for cookie in self._cookies:
self._tester.QueryFollowed(cookie)
self._tester.QueryUsers(cookie, [u.user_id for u in self._users])
vp_select_list = [self._tester.C... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.