desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Add a follower after having removed it.'
def testAddAfterRemoveFollower(self):
self._tester.UpdateFollower(self._cookie2, self._vp_id, labels=[Follower.CONTRIBUTE, Follower.MUTED]) self._tester.RemoveFollowers(self._cookie, self._vp_id, [self._user2.user_id]) self._tester.AddFollowers(self._cookie, self._vp_id, [self._user2.user_id]) response_dict = self._tester.QueryFollowed(self...
'Force op failure in order to test idempotency.'
@mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True) def testIdempotency(self):
self._tester.RemoveViewpoint(self._cookie2, self._vp_id) self._tester.AddFollowers(self._cookie, self._vp_id, ['Local:identity1', {'identity': 'Local:identity2', 'name': 'Andy Kimball'}, 'Email:extra.user1@emailscrubbed.com', self._extra_users[1].user_id])
'ERROR: Try to use non-canonical contact identities.'
def testNonCanonicalId(self):
self.assertRaisesHttpError(400, self._tester.AddFollowers, self._cookie, self._user.private_vp_id, ['Email:EXTRA.USER1@emailscrubbed.com']) self.assertRaisesHttpError(400, self._tester.AddFollowers, self._cookie, self._user.private_vp_id, ['Phone:123-456-7890']) self.assertRaisesHttpError(400, self._tester....
'Add empty set of followers.'
def testEmptyFollowers(self):
self._tester.AddFollowers(self._cookie, self._user.private_vp_id, [])
'ERROR: Try to add follower to viewpoint that is not followed.'
def testNotFollower(self):
self.assertRaisesHttpError(403, self._tester.AddFollowers, self._cookie3, self._vp_id, ['Email:extra.user1@emailscrubbed.com'])
'ERROR: Try to add follower to viewpoint without CONTRIBUTOR rights.'
def testNotContributor(self):
self._skip_validation_for.append('Accounting') self._UpdateOrAllocateDBObject(Follower, viewpoint_id=self._vp_id, user_id=self._user3.user_id, viewed_seq=0) self.assertRaisesHttpError(403, self._tester.AddFollowers, self._cookie3, self._vp_id, ['Email:extra.user1@emailscrubbed.com'])
'ERROR: Try to add followers to viewpoint without CONTRIBUTOR rights.'
def testNotContributorAndProspectiveAdd(self):
self._skip_validation_for.append('Accounting') self._UpdateOrAllocateDBObject(Follower, viewpoint_id=self._vp_id, user_id=self._user3.user_id, viewed_seq=0) self.assertRaisesHttpError(403, self._tester.AddFollowers, self._cookie3, self._vp_id, [{'identity': 'Local:identity2', 'name': 'Andy Kimball'}, 'Em...
'Test add followers with various identity schemes.'
def testIdentitySchemes(self):
self._tester.AddFollowers(self._cookie, self._user.private_vp_id, ['Local:identity2', 'Email:extra.user1@emailscrubbed.com', 'Phone:+14251234567', 'FacebookGraph:123', 'VF:456'])
'Verify that an unrecognized contact will result in the creation of a prospective user, which will then be added as a follower.'
def testProspectiveAdd(self):
self._tester.AddFollowers(self._cookie, self._user.private_vp_id, ['Local:identity1'])
'Verify adding each kind of identity as a prospective user.'
def testProspectiveAddIdentities(self):
self._tester.AddFollowers(self._cookie, self._user.private_vp_id, ['Local:identity1', {'identity': 'Email:andy@emailscrubbed.com', 'name': 'Andy Kimball'}, 'FacebookGraph:123', 'Phone:+442083661177'])
'Verify that multiple unrecognized contacts will result in the creation of prospective users.'
def testMultipleProspectiveAdds(self):
self._tester.AddFollowers(self._cookie, self._user.private_vp_id, ['Local:identity1', {'identity': 'Local:identity2', 'name': 'Andy Kimball'}, 'Email:andy@emailscrubbed.com', {'identity': 'Phone:+14161234567', 'name': 'Someone'}])
'Verify that unrecognized contacts mixed with existing users can be added as followers.'
def testMixedProspectiveAdds(self):
self._tester.AddFollowers(self._cookie, self._user.private_vp_id, ['Local:identity1', {'identity': 'Local:identity2', 'name': 'Andy Kimball'}, 'Email:extra.user1@emailscrubbed.com', self._extra_users[1].user_id])
'Add prospective users in sequence.'
def testSequenceProspectiveAdds(self):
self._tester.AddFollowers(self._cookie, self._vp_id, ['Email:test@test.com', self._user3.user_id]) self.assertEqual(len(TestEmailManager.Instance().emails['user3@emailscrubbed.com']), 1) self._tester.AddFollowers(self._cookie, self._vp_id, ['Email:test@test.com']) self.assertEqual(len(TestEmailManager.I...
'ERROR: Try to add contact with invalid user id.'
def testInvalidUserId(self):
self.assertRaisesHttpError(400, self._tester.AddFollowers, self._cookie, self._user.private_vp_id, [1000])
'ERROR: Try to add contact with unknown identity format.'
def testUnknownIdentityFormat(self):
self.assertRaisesHttpError(400, self._tester.AddFollowers, self._cookie, self._user.private_vp_id, ['Unknown:foo']) self.assertRaisesHttpError(400, self._tester.AddFollowers, self._cookie, self._user.private_vp_id, ['Phone:123-456-7890']) self.assertRaisesHttpError(400, self._tester.AddFollowers, self._cook...
'Add a follower on day 2, add another on day 3, then third on day 1.'
def testAddsAcrossDays(self):
self._tester.AddFollowers(self._cookie, self._vp_id, [{'identity': 'Email:user1@emailscrubbed.com'}]) act_dict = self._tester.CreateActivityDict(self._cookie) act_dict['timestamp'] += constants.SECONDS_PER_DAY self._tester.AddFollowers(self._cookie, self._vp_id, [{'identity': 'Email:user1@emailscrubbed....
'Try to exceed limit on number of followers on a viewpoint and observe that error is raised.'
def testExceedAddFollowersLimit(self):
with mock.patch.object(Viewpoint, 'MAX_FOLLOWERS', (len(self._extra_users) + 1)): contacts = [{'user_id': extra_user.user_id} for extra_user in self._extra_users] self._tester.AddFollowers(self._cookie, self._user.private_vp_id, contacts) self.assertRaisesHttpError(403, self._tester.AddFollo...
'Creates a new episode and photo and updates both.'
def testUpdateEpisode(self):
timestamp = time.time() episode_id = Episode.ConstructEpisodeId(timestamp, self._device_ids[0], 100) ep_dict = {'episode_id': episode_id, 'timestamp': timestamp, 'title': 'Episode Title'} photo_id = Photo.ConstructPhotoId(timestamp, self._device_ids[0], 100) ph_dict = {'aspect_ratio': 1.3333, 'ti...
'Updates an episode that was created as part of a share.'
def testUpdateSharedEpisode(self):
self._tester.UpdateEpisode(self._cookie, self._ep_id, title='Changed title')
'Update an episode in a viewpoint with an unrevivable removed follower.'
def testUnrevivable(self):
self._tester.RemoveFollowers(self._cookie, self._vp_id, [self._user2.user_id]) self._tester.UpdateEpisode(self._cookie, self._ep_id, title='Changed title') response_dict = self._tester.QueryFollowed(self._cookie2) self.assertIn(Follower.REMOVED, response_dict['viewpoints'][0]['labels']) self.asse...
'Force op failure in order to test idempotency.'
@mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True) def testIdempotency(self):
self._tester.RemoveViewpoint(self._cookie2, self._vp_id) self._tester.UpdateEpisode(self._cookie, self._ep_id, title='Changed title')
'ERROR: Try to update an episode that does not exist.'
def testUpdateInvalidEpisode(self):
self.assertRaisesHttpError(400, self._tester.UpdateEpisode, self._cookie, 'totally unknown, invalid, etc')
'ERROR: Try to update a read-only episode attribute.'
def testUpdateReadOnlyAttribute(self):
self.assertRaisesHttpError(400, self._tester.UpdateEpisode, self._cookie, self._episode_id, viewpoint_id='v-invalid')
'ERROR: Try to update an episode in a viewpoint that the user does not follow.'
def testUpdateViewpointNotFollowed(self):
self.assertRaisesHttpError(403, self._tester.UpdateEpisode, self._cookie2, self._episode_id)
'ERROR: Try to update an episode that user did not create.'
def testUpdateEpisodeNotOwned(self):
(vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids)], [self._user2.user_id]) self.assertRaisesHttpError(403, self._tester.UpdateEpisode, self._cookie2, ep_ids[0])
'Test successful register of web user.'
def testRegisterWebUser(self):
self._tester.RegisterGoogleUser(self._google_user_dict) self.assertRaisesHttpError(403, self._tester.RegisterGoogleUser, self._google_user_dict, self._mobile_device_dict)
'Test successful register of mobile user.'
def testRegisterMobileUser(self):
self._tester.RegisterGoogleUser(self._google_user_dict, self._mobile_device_dict) self.assertRaisesHttpError(403, self._tester.RegisterGoogleUser, self._google_user_dict)
'Test successful login of web user.'
def testLoginWebUser(self):
(user, device_id) = self._tester.RegisterGoogleUser(self._google_user_dict) (user2, device_id2) = self._tester.LoginGoogleUser(self._google_user_dict) self.assertEqual(user.user_id, user2.user_id) self.assertEqual(device_id, device_id2) self._tester.LoginGoogleUser(self._google_user_dict, self._mobi...
'Test successful login of mobile user.'
def testLoginMobileUser(self):
(user, device_id) = self._tester.RegisterGoogleUser(self._google_user_dict) (user2, device_id2) = self._tester.LoginGoogleUser(self._google_user_dict, self._mobile_device_dict) self.assertEqual(user.user_id, user2.user_id) self.assertNotEqual(device_id, device_id2) self._tester.LoginGoogleUser(self....
'Test successful link of web user.'
def testLinkWebUser(self):
(user, device_id) = self._tester.RegisterGoogleUser(self._google_user_dict, self._mobile_device_dict) cookie = self._GetSecureUserCookie(user, device_id) (user2, device_id2) = self._tester.LinkGoogleUser(self._google_user2_dict, user_cookie=cookie) self.assertEqual(user.user_id, user2.user_id) self....
'Test successful link of mobile user.'
def testLinkMobileUser(self):
(user, device_id) = self._tester.RegisterGoogleUser(self._google_user_dict) cookie = self._GetSecureUserCookie(user, device_id) self._tester.LinkGoogleUser(self._google_user2_dict, self._mobile_device_dict, user_cookie=cookie) self._tester.LinkGoogleUser(self._google_user2_dict, user_cookie=cookie) ...
'Test that identity key is canonicalized during import from Google.'
def testNonCanonicalId(self):
(user, device_id) = self._tester.RegisterGoogleUser(self._google_user_dict, self._mobile_device_dict) self._google_user_dict['email'] = self._google_user_dict['email'].upper() (user2, device_id2) = self._tester.LoginGoogleUser(self._google_user_dict, self._mobile_device_dict) self.assertEqual(user.user_...
'ERROR: Try to login with Google identity that is not linked to a Viewfinder account.'
def testLoginNoExist(self):
self.assertRaisesHttpError(403, self._tester.LoginGoogleUser, self._google_user_dict) self.assertRaisesHttpError(403, self._tester.LoginGoogleUser, self._google_user_dict, self._mobile_device_dict)
'ERROR: Try to register an unverified email address.'
def testUnverifiedEmail(self):
self._google_user_dict['verified_email'] = False self.assertRaisesHttpError(403, self._tester.RegisterGoogleUser, self._google_user_dict, self._mobile_device_dict)
'ERROR: Test error on missing Google refresh token.'
def testMissingRefreshToken(self):
self.assertRaisesHttpError(400, auth_test._SendAuthRequest, self._tester, self.get_url('/register/google'), 'POST', request_dict=auth_test._CreateRegisterRequest(self._mobile_device_dict))
'Assign different asset keys to the same photo from different users.'
def testUpdateUserPhoto(self):
(episode_id, photo_id) = self._UploadEpisodeWithPhoto() self._tester.UpdateUserPhoto(self._cookie, photo_id, asset_keys=['a/#asset-key-1']) self._tester.UpdateUserPhoto(self._cookie2, photo_id, asset_keys=['a/#asset-key-2']) self.assertEqual([], self._tester.QueryEpisodes(self._cookie2, [{'episode_id': ...
'Change the asset keys associated with a user/photo.'
def testReplaceUserPhoto(self):
(episode_id, photo_id) = self._UploadEpisodeWithPhoto() self._tester.UpdateUserPhoto(self._cookie, photo_id, asset_keys=['a/#asset-key-1']) self.assertEqual(self._GetAssetKeys(self._cookie, episode_id), ['a/#asset-key-1']) self._tester.UpdateUserPhoto(self._cookie, photo_id, asset_keys=['a/#asset-key-1'...
'Create episode with photo and upload. Returns: photo_id of created photo.'
def _UploadEpisodeWithPhoto(self):
timestamp = time.time() episode_id = Episode.ConstructEpisodeId(timestamp, self._device_ids[0], 100) ep_dict = {'episode_id': episode_id, 'timestamp': timestamp, 'title': 'Episode Title'} photo_id = Photo.ConstructPhotoId(timestamp, self._device_ids[0], 100) ph_dict = {'aspect_ratio': 1.3333, 'ti...
'Deletes all objects that were created in the context of the model. If validate=True, then validates all objects before the cleanup. "skip_validation_for" is a list of string names of validation checks to skip.'
def Cleanup(self, validate=False, skip_validation_for=None):
if validate: if (skip_validation_for is not None): if ('Alerts' not in skip_validation_for): self._ValidateAlerts() if ('Accounting' not in skip_validation_for): self.validator.ValidateAccounting() self.validator.Cleanup(validate=validate)
'add_followers: Adds contacts as followers of an existing viewpoint. The format of "contacts" is described in the header to CreateContactDicts.'
def AddFollowers(self, user_cookie, viewpoint_id, contacts, act_dict=None):
request_dict = {'activity': (act_dict or self.CreateActivityDict(user_cookie)), 'viewpoint_id': viewpoint_id, 'contacts': self.CreateContactDicts(contacts)} from viewfinder.backend.www.test.add_followers_test import _TestAddFollowers _TestAddFollowers(self, user_cookie, request_dict)
'build_archive: build archive of all of user content and prepare it for download.'
def BuildArchive(self, user_cookie):
from viewfinder.backend.www.test.build_archive_test import _TestBuildArchive return _TestBuildArchive(self, user_cookie)
'hide_photos: Hides photos from a user\'s personal library or inbox view. "ep_ph_ids_list" is a list of tuples in this format: [(episode, [photo_id, ...]), ...]'
def HidePhotos(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]} from viewfinder.backend.www.test.hide_photos_test import _TestHidePhotos _TestHidePhotos(self, user_cookie, request_dict)
'list_identities: Lists all identities that are linked to the requesting user. This is embedded in the query_users response when querying self. Returns a list of the identity keys.'
def ListIdentities(self, user_cookie):
(user_id, device_id) = self.GetIdsFromCookie(user_cookie) response_dict = self.QueryUsers(user_cookie, [user_id]) private = response_dict['users'][0]['private'] return [ident_dict['identity'] for ident_dict in private['user_identities']]
'merge_accounts: Merges assets from a source user account into the target user account, or links a source identity to the target user account.'
def MergeAccounts(self, user_cookie, source_user_cookie=None, source_identity_dict=None, act_dict=None):
from viewfinder.backend.www.test.merge_accounts_test import _TestMergeAccounts request_dict = {'activity': (act_dict or self.CreateActivityDict(user_cookie))} util.SetIfNotNone(request_dict, 'source_user_cookie', source_user_cookie) util.SetIfNotNone(request_dict, 'source_identity', source_identity_dict...
'post_comment: Adds a new comment to a viewpoint. Additional comment fields can be passed in "cm_dict". Returns the id of the new comment.'
def PostComment(self, user_cookie, viewpoint_id, message, act_dict=None, **cm_dict):
(user_id, device_id) = self.GetIdsFromCookie(user_cookie) timestamp = time.time() comment_id = Comment.ConstructCommentId(timestamp, device_id, self._test_id) self._test_id += 1 request_dict = {'activity': (act_dict or self.CreateActivityDict(user_cookie)), 'comment_id': comment_id, 'timestamp': tim...
'query_contacts: Returns all contact metadata requested by the user.'
def QueryContacts(self, user_cookie, limit=None, start_key=None):
request_dict = {} util.SetIfNotNone(request_dict, 'limit', limit) util.SetIfNotNone(request_dict, 'start_key', start_key) from viewfinder.backend.www.test.query_contacts_test import _TestQueryContacts return _TestQueryContacts(self, user_cookie, request_dict)
'query_episodes: Returns all episode metadata and collections requested by the user. "ep_select_list" is a list of episode selection dicts, such as generated by CreateEpisodeSelection.'
def QueryEpisodes(self, user_cookie, ep_select_list, photo_limit=None):
request_dict = {'episodes': ep_select_list} util.SetIfNotNone(request_dict, 'photo_limit', photo_limit) from viewfinder.backend.www.test.query_episodes_test import _TestQueryEpisodes return _TestQueryEpisodes(self, user_cookie, request_dict)
'query_followed: Returns metadata of all viewpoints followed by the user.'
def QueryFollowed(self, user_cookie, limit=None, start_key=None):
request_dict = {} util.SetIfNotNone(request_dict, 'limit', limit) util.SetIfNotNone(request_dict, 'start_key', start_key) from viewfinder.backend.www.test.query_followed_test import _TestQueryFollowed return _TestQueryFollowed(self, user_cookie, request_dict)
'query_notifications: Returns notifications for the requesting user.'
def QueryNotifications(self, user_cookie, limit=None, start_key=None, scan_forward=None, max_long_poll=None):
request_dict = {} util.SetIfNotNone(request_dict, 'limit', limit) util.SetIfNotNone(request_dict, 'start_key', start_key) util.SetIfNotNone(request_dict, 'scan_forward', scan_forward) util.SetIfNotNone(request_dict, 'max_long_poll', max_long_poll) from viewfinder.backend.www.test.query_notificat...
'query_users: Returns all user/friend metadata requested by the user.'
def QueryUsers(self, user_cookie, user_ids):
from viewfinder.backend.www.test.query_users_test import _TestQueryUsers return _TestQueryUsers(self, user_cookie, {'user_ids': user_ids})
'query_viewpoints: Returns all viewpoint metadata and collections requested by the user. "vp_select_list" is a list of viewpoint selection dicts, such as generated by CreateViewpointSelection.'
def QueryViewpoints(self, user_cookie, vp_select_list, limit=None):
request_dict = {'viewpoints': vp_select_list} util.SetIfNotNone(request_dict, 'limit', limit) from viewfinder.backend.www.test.query_viewpoints_test import _TestQueryViewpoints return _TestQueryViewpoints(self, user_cookie, request_dict)
'remove_contacts: Removes contacts from a user\'s server based contacts container.'
def RemoveContacts(self, user_cookie, contacts_list):
request_dict = {'contacts': contacts_list} from viewfinder.backend.www.test.remove_contacts_test import _TestRemoveContacts return _TestRemoveContacts(self, user_cookie, request_dict)
'remove_followers: Remove followers from an existing viewpoint.'
def RemoveFollowers(self, user_cookie, viewpoint_id, remove_ids, act_dict=None):
request_dict = {'activity': (act_dict or self.CreateActivityDict(user_cookie)), 'viewpoint_id': viewpoint_id, 'remove_ids': remove_ids} from viewfinder.backend.www.test.remove_followers_test import _TestRemoveFollowers _TestRemoveFollowers(self, user_cookie, request_dict)
'remove_photos: Removes photos from a user\'s personal library. "ep_ph_ids_list" is a list of tuples in this format: [(episode, [photo_id, ...]), ...]'
def RemovePhotos(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]} from viewfinder.backend.www.test.remove_photos_test import _TestRemovePhotos _TestRemovePhotos(self, user_cookie, request_dict)
'remove_viewpoint: Remove a viewpoint from a user\'s inbox.'
def RemoveViewpoint(self, user_cookie, viewpoint_id):
request_dict = {'viewpoint_id': viewpoint_id} from viewfinder.backend.www.test.remove_viewpoint_test import _TestRemoveViewpoint _TestRemoveViewpoint(self, user_cookie, request_dict)
'save_photos: Saves photos to the user\'s default viewpoint. See header to _CreateCopyDictList for details on format for "save_list". Returns a list of the new episode ids.'
def SavePhotos(self, user_cookie, ep_save_list=None, viewpoint_ids=None, act_dict=None):
request_dict = {'activity': (act_dict or self.CreateActivityDict(user_cookie))} if (ep_save_list is not None): request_dict['episodes'] = self._CreateCopyDictList(user_cookie, ep_save_list) util.SetIfNotNone(request_dict, 'viewpoint_ids', viewpoint_ids) from viewfinder.backend.www.test.save_phot...
'share_existing: Shares photos with the followers of an existing viewpoint. See header to _CreateCopyDictList for details on format for "share_list". Returns a list of the new episode ids.'
def ShareExisting(self, user_cookie, viewpoint_id, share_list, act_dict=None):
request_dict = {'activity': (act_dict or self.CreateActivityDict(user_cookie)), 'viewpoint_id': viewpoint_id, 'episodes': self._CreateCopyDictList(user_cookie, share_list)} from viewfinder.backend.www.test.share_existing_test import _TestShareExisting _TestShareExisting(self, user_cookie, request_dict) ...
'share_existing: Shares photos with other users by adding them as followers to a new viewpoint to which the photos are added. See header to _CreateCopyDictList for details on format for "share_list". The format of "contacts" is described in the header to CreateContactDicts. The attributes in "vp_dict" are used to creat...
def ShareNew(self, user_cookie, share_list, contacts, act_dict=None, **vp_dict):
(user_id, device_id) = self.GetIdsFromCookie(user_cookie) viewpoint_id = vp_dict.get('viewpoint_id', Viewpoint.ConstructViewpointId(device_id, self._test_id)) self._test_id += 1 request_dict = {'activity': (act_dict or self.CreateActivityDict(user_cookie)), 'viewpoint': {'viewpoint_id': viewpoint_id, 't...
'terminate_account: Terminates a user account.'
def TerminateAccount(self, user_cookie):
from viewfinder.backend.www.test.terminate_account_test import _TestTerminateAccount _TestTerminateAccount(self, user_cookie, {})
'unlink_identity: Unlinks an identity that is currently associated with the requesting user\'s Viewfinder account.'
def UnlinkIdentity(self, user_cookie, identity_key):
from viewfinder.backend.www.test.unlink_identity_test import _TestUnlinkIdentity _TestUnlinkIdentity(self, user_cookie, {'identity': identity_key})
'unshare: Recursively unshares photos that were previously shared with other users. "ep_ph_ids_list" is a list of tuples in this format: [(episode, [photo_id, ...]), ...]'
def Unshare(self, user_cookie, viewpoint_id, ep_ph_ids_list, act_dict=None):
request_dict = {'activity': (act_dict or self.CreateActivityDict(user_cookie)), 'viewpoint_id': viewpoint_id, 'episodes': [{'episode_id': episode_id, 'photo_ids': photo_ids} for (episode_id, photo_ids) in ep_ph_ids_list]} from viewfinder.backend.www.test.unshare_test import _TestUnshare _TestUnshare(self, u...
'update_device: Updates existing device\'s metadata. The attributes in "device_dict" are used to update the device.'
def UpdateDevice(self, user_cookie, device_id, **dev_dict):
request_dict = {'device_dict': {'device_id': device_id, 'device_uuid': '5DE5D5B8-7413-4B59-BB72-BD5E5F86C1AF', 'test_udid': '7d527095d4e0539aba40c852547db5da00000000'}} request_dict['device_dict'].update(dev_dict) from viewfinder.backend.www.test.update_device_test import _TestUpdateDevice _TestUpdateDe...
'update_episode: Updates existing episode\'s metadata. The attributes in "ep_dict" are used to update the episode.'
def UpdateEpisode(self, user_cookie, episode_id, act_dict=None, **ep_dict):
request_dict = {'activity': (act_dict or self.CreateActivityDict(user_cookie)), 'episode_id': episode_id} request_dict.update(ep_dict) from viewfinder.backend.www.test.update_episode_test import _TestUpdateEpisode _TestUpdateEpisode(self, user_cookie, request_dict)
'update_follower: Updates existing follower\'s metadata. The attributes in "foll_dict" are used to update the follower.'
def UpdateFollower(self, user_cookie, viewpoint_id, act_dict=None, **foll_dict):
request_dict = {'follower': {'viewpoint_id': viewpoint_id}} request_dict['follower'].update(foll_dict) from viewfinder.backend.www.test.update_follower_test import _TestUpdateFollower _TestUpdateFollower(self, user_cookie, request_dict)
'update_friend: Updates metadata about a friend. The attributes in "friend_dict" are used to update the friend.'
def UpdateFriend(self, user_cookie, **friend_dict):
request_dict = {'friend': friend_dict} from viewfinder.backend.www.test.update_friend_test import _TestUpdateFriend _TestUpdateFriend(self, user_cookie, request_dict)
'update_photo: Updates existing photo\'s metadata. The attributes in "ph_dict" are used to update the photo.'
def UpdatePhoto(self, user_cookie, photo_id, act_dict=None, **ph_dict):
request_dict = {'activity': (act_dict or self.CreateActivityDict(user_cookie)), 'photo_id': photo_id} request_dict.update(ph_dict) from viewfinder.backend.www.test.update_photo_test import _TestUpdatePhoto _TestUpdatePhoto(self, user_cookie, request_dict)
'update_user: Updates existing user\'s profile and settings metadata. The attributes in "user_dict" are used to update the user object, and the attributes in "settings_dict" are used to create or update the account settings object.'
def UpdateUser(self, user_cookie, settings_dict=None, **user_dict):
request_dict = {} util.SetIfNotNone(request_dict, 'account_settings', settings_dict) request_dict.update(user_dict) from viewfinder.backend.www.test.update_user_test import _TestUpdateUser _TestUpdateUser(self, user_cookie, request_dict)
'update_user_photo: Update existing photo\'s per-user metadata. The attributes in "up_dict" are used to update the UserPhoto.'
def UpdateUserPhoto(self, user_cookie, photo_id, **up_dict):
request_dict = {'photo_id': photo_id} request_dict.update(up_dict) from viewfinder.backend.www.test.update_user_photo_test import _TestUpdateUserPhoto _TestUpdateUserPhoto(self, user_cookie, request_dict)
'update_viewpoint: Updates existing viewpoint\'s metadata. The attributes in "vp_dict" are used to update the viewpoint.'
def UpdateViewpoint(self, user_cookie, viewpoint_id, act_dict=None, **vp_dict):
request_dict = {'activity': (act_dict or self.CreateActivityDict(user_cookie)), 'viewpoint_id': viewpoint_id} request_dict.update(vp_dict) from viewfinder.backend.www.test.update_viewpoint_test import _TestUpdateViewpoint _TestUpdateViewpoint(self, user_cookie, request_dict)
'upload_contacts: uploads new contacts. Pre-existing contacts that match any of these are untouched.'
def UploadContacts(self, user_cookie, contacts_dict_list):
(user_id, device_id) = self.GetIdsFromCookie(user_cookie) request_dict = {'contacts': contacts_dict_list} from viewfinder.backend.www.test.upload_contacts_test import _TestUploadContacts return _TestUploadContacts(self, user_cookie, request_dict)
'upload_episode: Uploads photos to an episode in the user\'s default viewpoint. The attributes in "ep_dict" are used to create the episode. The episode_id and timestamp are automatically generated if not present. The attributes in "ph_dict_list" are used to create each photo in the new episode. The photo_id and timesta...
def UploadEpisode(self, user_cookie, ep_dict, ph_dict_list, act_dict=None, add_test_photos=False):
(user_id, device_id) = self.GetIdsFromCookie(user_cookie) timestamp = ep_dict.get('timestamp', time.time()) episode_id = ep_dict.get('episode_id', Episode.ConstructEpisodeId(timestamp, device_id, self._test_id)) self._test_id += 1 request_dict = {'activity': (act_dict or self.CreateActivityDict(user...
'Creates an activity dict to be passed to various service methods that create an activity. Uses the current time and the next unique test id.'
def CreateActivityDict(self, user_cookie):
(user_id, device_id) = self.GetIdsFromCookie(user_cookie) timestamp = time.time() activity_id = Activity.ConstructActivityId(timestamp, device_id, self._test_id) self._test_id += 1 return {'activity_id': activity_id, 'timestamp': timestamp}
'Creates a contact dict corresponding to each item in "contacts". If a contact is a string, then assumes it is an identity key. If a contact is a number, then assumes it is a user id. Otherwise, it should already be a contact metadata dict.'
def CreateContactDicts(self, contacts):
contact_dicts = [] for contact in contacts: if (type(contact) in [str, unicode]): contact_dicts.append({'identity': contact}) elif (type(contact) in [int, long]): contact_dicts.append({'user_id': contact}) else: assert isinstance(contact, dict), contac...
'Creates an episode selection dict.'
def CreateEpisodeSelection(self, episode_id, get_attributes=True, get_photos=True):
selection = {'episode_id': episode_id} util.SetIfNotNone(selection, 'get_attributes', get_attributes) util.SetIfNotNone(selection, 'get_photos', get_photos) return selection
'Creates a viewpoint selection dict.'
def CreateViewpointSelection(self, viewpoint_id, get_attributes=True, get_followers=True, follower_start_key=None, get_activities=True, activity_start_key=None, get_episodes=True, episode_start_key=None, get_comments=True, comment_start_key=None):
kwargs = locals().copy() [kwargs.pop(key) for (key, value) in kwargs.items() if ((key in ['self', 'viewpoint_id']) or (value is None))] selection = {'viewpoint_id': viewpoint_id} selection.update(kwargs) return selection
'Creates an episode copy request dict, using the current time and the next unique test id. See COPY_EPISODES_METADATA in json_schema.py for a description of the format.'
def CreateCopyDict(self, user_cookie, existing_episode_id, photo_ids):
(user_id, device_id) = self.GetIdsFromCookie(user_cookie) episode_id = Episode.ConstructEpisodeId(time.time(), device_id, self._test_id) copy_dict = {'existing_episode_id': existing_episode_id, 'new_episode_id': episode_id, 'photo_ids': photo_ids} self._test_id += 1 return copy_dict
'Creates and returns a list of episode copy request dicts. "copy_list" is a list containing tuples and/or dicts. Dicts must be in the COPY_EPISODES_METADATA format described in json_schema.py. Any tuples in the list must be in the following format: (existing_ep_id, [ph_id1, ph_id2, ...]) These tuples are converted into...
def _CreateCopyDictList(self, user_cookie, copy_list):
copy_dict_list = [] for copy_item in copy_list: if (type(copy_item) is tuple): (existing_episode_id, photo_ids) = copy_item copy_dict_list.append(self.CreateCopyDict(user_cookie, existing_episode_id, photo_ids)) else: copy_dict_list.append(copy_item) retur...
'link/facebook: Links a Facebook account to an existing Viewfinder account.'
def LinkFacebookUser(self, user_dict, device_dict=None, user_cookie=None):
from viewfinder.backend.www.test.auth_facebook_test import _TestAuthFacebookUser return _TestAuthFacebookUser('link', self, user_dict, device_dict, user_cookie)
'link/google: Links a Google account to an existing Viewfinder account.'
def LinkGoogleUser(self, user_dict, device_dict=None, user_cookie=None):
from viewfinder.backend.www.test.auth_google_test import _TestAuthGoogleUser return _TestAuthGoogleUser('link', self, user_dict, device_dict, user_cookie)
'link/viewfinder: Links an email or SMS identity to an existing Viewfinder account.'
def LinkViewfinderUser(self, user_dict, device_dict=None, user_cookie=None):
from viewfinder.backend.www.test.auth_viewfinder_test import _TestAuthViewfinderUser return _TestAuthViewfinderUser('link', self, user_dict, device_dict, user_cookie)
'login/facebook: Logs into an existing Viewfinder account using an already linked Facebook account.'
def LoginFacebookUser(self, user_dict, device_dict=None, user_cookie=None):
from viewfinder.backend.www.test.auth_facebook_test import _TestAuthFacebookUser return _TestAuthFacebookUser('login', self, user_dict, device_dict, user_cookie)
'login/fakeviewfinder: Logs into an existing Viewfinder account. This method is faster than LoginViewfinderUser but is less representative of the real process. Use LoginViewfinderUser to test the login process; use LoginFakeViewfinderUser when you just need to log in.'
def LoginFakeViewfinderUser(self, user_dict, device_dict=None, user_cookie=None):
from viewfinder.backend.www.test.auth_viewfinder_test import _TestFakeAuthViewfinderUser return _TestFakeAuthViewfinderUser('login', self, user_dict, device_dict, user_cookie)
'login/google: Logs into an existing Viewfinder account using an already linked Google account.'
def LoginGoogleUser(self, user_dict, device_dict=None, user_cookie=None):
from viewfinder.backend.www.test.auth_google_test import _TestAuthGoogleUser return _TestAuthGoogleUser('login', self, user_dict, device_dict, user_cookie)
'login/viewfinder: Logs into an existing Viewfinder account using a verified email address.'
def LoginViewfinderUser(self, user_dict, device_dict=None, user_cookie=None):
from viewfinder.backend.www.test.auth_viewfinder_test import _TestAuthViewfinderUser return _TestAuthViewfinderUser('login', self, user_dict, device_dict, user_cookie)
'login_reset/viewfinder: Logs into an existing Viewfinder account using a verified identity, in order to produce a confirmed login cookie that will be used to update the password.'
def LoginResetViewfinderUser(self, user_dict, device_dict=None, user_cookie=None):
from viewfinder.backend.www.test.auth_viewfinder_test import _TestAuthViewfinderUser return _TestAuthViewfinderUser('login_reset', self, user_dict, device_dict, user_cookie)
'register/facebook: Registers a new Viewfinder account, linking it to a Facebook account.'
def RegisterFacebookUser(self, user_dict, device_dict=None, user_cookie=None):
from viewfinder.backend.www.test.auth_facebook_test import _TestAuthFacebookUser return _TestAuthFacebookUser('register', self, user_dict, device_dict, user_cookie)
'register/google: Registers a new Viewfinder account, linking it to a Google account.'
def RegisterGoogleUser(self, user_dict, device_dict=None, user_cookie=None):
from viewfinder.backend.www.test.auth_google_test import _TestAuthGoogleUser return _TestAuthGoogleUser('register', self, user_dict, device_dict, user_cookie)
'register/viewfinder: Registers a new Viewfinder account, linking it to a verified email address.'
def RegisterViewfinderUser(self, user_dict, device_dict=None, user_cookie=None):
from viewfinder.backend.www.test.auth_viewfinder_test import _TestAuthViewfinderUser return _TestAuthViewfinderUser('register', self, user_dict, device_dict, user_cookie)
'register/fakeviewfinder: Registers a new Viewfinder account, linking it to a verified email address. This method is faster than RegisterViewfinderUser but is less representative of the real process. Use RegisterViewfinderUser to test the registration process; use RegisterFakeViewfinderUser when you just need a user (...
def RegisterFakeViewfinderUser(self, user_dict, device_dict=None, user_cookie=None):
from viewfinder.backend.www.test.auth_viewfinder_test import _TestFakeAuthViewfinderUser return _TestFakeAuthViewfinderUser('register', self, user_dict, device_dict, user_cookie)
'Gets full service URL by concatenating "path" to the service URL.'
def GetUrl(self, path):
return (self._svc_url + path)
'Makes a POST request to the specified service method. If version is not None, then does not migrate the version of the message -- just uses the "raw" request that was provided. Returns the JSON response as a Python dict.'
def SendRequest(self, method, user_cookie, request_dict, version=None):
return self._RunAsync(self.SendRequestAsync, method, user_cookie, request_dict, version=version)
'Makes a POST request to the specified service method. If version is not None, then does not migrate the version of the message -- just uses the "raw" request that was provided. Invokes the callback with the JSON response as a Python dict.'
def SendRequestAsync(self, method, user_cookie, request_dict, callback, version=None):
def _OnFetch(response): response.rethrow() callback(json.loads(response.body)) version = (message.MAX_SUPPORTED_MESSAGE_VERSION if (version is None) else version) request_message = message.Message(request_dict, default_version=version) has_op_header = ('op_id' in ServiceHandler.SERVICE_M...
'Sends a GET request to the photo store URL for the specified episode and photo. Returns the HTTP response.'
def GetPhotoImage(self, user_cookie, episode_id, photo_id, suffix):
headers = {} if (user_cookie is not None): headers = {'Cookie': ('user=%s' % user_cookie)} url = self.GetUrl(('/episodes/%s/photos/%s%s' % (episode_id, photo_id, suffix))) return self._RunAsync(self.http_client.fetch, url, method='GET', follow_redirects=True, headers=headers)
'Sends a PUT request to the photo store URL for the specified episode and photo. The put request body is set to "image_data". Returns the HTTP response.'
def PutPhotoImage(self, user_cookie, episode_id, photo_id, suffix, image_data, etag=None, content_md5=None):
headers = {'Content-Type': 'image/jpeg', 'X-Xsrftoken': 'fake_xsrf', 'Cookie': '_xsrf=fake_xsrf'} if (user_cookie is not None): headers['Cookie'] += (';user=%s' % user_cookie) if (content_md5 is not None): headers['Content-MD5'] = content_md5 if etag: headers['If-None-Match'] = e...
'Sends an HTTP request to the specified admin service "method" from the test-user/test-password admin. Returns the JSON response as a dict.'
def SendAdminRequest(self, method, request_dict):
otp_cookie_value = OTPEntryHandler._CreateCookie('test-user', time.time()) otp_cookie = web.create_signed_value(self._secret, basic_auth.COOKIE_NAME, otp_cookie_value) headers = {'Content-Type': 'application/json', 'Cookie': ('%s=%s;_xsrf=fake_xsrf' % (basic_auth.COOKIE_NAME, otp_cookie)), 'X-Xsrftoken': 'f...
'Json-encodes and signs a user cookie using the service secret.'
def EncodeUserCookie(self, cookie):
return web.create_signed_value(self._secret, 'user', json.dumps(cookie))
'Decodes and json-decodes a user cookie using the service secret, or returns None if the cookie could not be decoded.'
def DecodeUserCookie(self, cookie):
value = web.decode_signed_value(self._secret, 'user', cookie) return (json.loads(value) if value else None)
'Creates an encoded user cookie containing the given information.'
def GetSecureUserCookie(self, user_id, device_id, user_name, viewpoint_id=None, confirm_time=None):
cookie = {'user_id': user_id, 'name': user_name, 'device_id': device_id, 'server_version': ServiceTester.SERVER_VERSION} util.SetIfNotNone(cookie, 'viewpoint_id', viewpoint_id) util.SetIfNotNone(cookie, 'confirm_time', confirm_time) return self.EncodeUserCookie(cookie)
'Gets the user_id and device_id fields from the encoded cookie.'
def GetIdsFromCookie(self, user_cookie):
cookie_dict = self.DecodeUserCookie(user_cookie) if (cookie_dict is None): return (None, None) return (cookie_dict.get('user_id', None), cookie_dict.get('device_id', None))
'Extracts the user cookie from an HTTP response and returns it if it exists, or returns None if not.'
def GetCookieFromResponse(self, response):
user_cookie_header_list = [h for h in response.headers.get_list('Set-Cookie') if h.startswith('user=')] if (not user_cookie_header_list): return None return re.match('user="?([^";]*)', user_cookie_header_list[(-1)]).group(1)