desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Test identity verification in the mobile case where we can\'t switch to the app.'
@mock.patch.object(VerifyIdMobileHandler, '_ACCESS_TOKEN_WAIT', 0.01) def testVerifyIdMobileFail(self):
def _Test(action, identity): self.assertEqual(len(identity.access_token), 9) url = self._tester.GetUrl(('/%s%s' % (identity.json_attrs['group_id'], identity.json_attrs['random_key']))) response = self._RunAsync(self.http_client.fetch, url, method='GET') self.assertEqual(response.code...
'Test identity verification in the mobile case where switching to app works.'
@mock.patch.object(VerifyIdMobileHandler, '_ACCESS_TOKEN_WAIT', 0.01) def testVerifyIdMobileSuccess(self):
auth_info_dict = {'identity': ('Email:%s' % self._viewfinder_user_dict['email']), 'name': self._viewfinder_user_dict['name'], 'given_name': self._viewfinder_user_dict['given_name']} identity = _TestGenerateAccessToken('register', self._tester, self._mobile_device_dict, auth_info_dict, use_short_token=False) ...
'Test identity verification in the web site case.'
def testVerifyIdWeb(self):
auth_info_dict = {'identity': ('Email:%s' % self._viewfinder_user_dict['email']), 'name': self._viewfinder_user_dict['name'], 'given_name': self._viewfinder_user_dict['given_name'], 'family_name': self._viewfinder_user_dict['family_name'], 'password': 'foobarbaz'} identity = _TestGenerateAccessToken('register',...
'Use valid and invalid access tokens with Viewfinder auth.'
def testAccessToken(self):
auth_info_dict = {'identity': 'Email:new.user@emailscrubbed.com', 'name': 'New User', 'given_name': 'New User'} identity = _TestGenerateAccessToken('register', self._tester, self._mobile_device_dict, auth_info_dict) url = self._tester.GetUrl('/verify/viewfinder') request_dict = {'headers': {'versi...
'Test that access token will be reused if it is not redeemed or expired.'
def testTokenReuse(self):
auth_info_dict = {'identity': 'Email:kat@emailscrubbed.com', 'name': 'Kat Mattis', 'given_name': 'Kat'} identity = _TestGenerateAccessToken('register', self._tester, self._mobile_device_dict, auth_info_dict) identity2 = _TestGenerateAccessToken('register', self._tester, self._mobile_device_dict, auth_inf...
'ERROR: Test that maximum access token guesses are respected.'
def testMaxGuesses(self):
auth_info_dict = {'identity': 'Email:new.user@emailscrubbed.com', 'name': 'New User', 'given_name': 'New User'} identity = _TestGenerateAccessToken('register', self._tester, self._mobile_device_dict, auth_info_dict) url = self._tester.GetUrl('/verify/viewfinder') request_dict = {'identity': auth_i...
'ERROR: Try to use invalid Viewfinder access token with existing Google identity.'
def testRegisterOverGoogle(self):
url = self._tester.GetUrl('/verify/viewfinder') request_dict = {'identity': 'Email:user3@emailscrubbed.com', 'access_token': 'mismatch'} self.assertRaisesHttpError(403, auth_test._SendAuthRequest, self._tester, url, 'POST', request_dict=request_dict) user = self._RunAsync(User.Query, self._client, self....
'ERROR: Try to send too many auth messages to a particular identity.'
@mock.patch.object(VerifyIdBaseHandler, '_MAX_MESSAGES_PER_MIN', 2) @mock.patch.object(VerifyIdBaseHandler, '_MAX_MESSAGES_PER_DAY', 3) def testTooManyMessages(self):
emails = TestEmailManager.Instance().emails phone_numbers = TestSMSManager.Instance().phone_numbers emails.clear() auth_info_dict = {'identity': 'Email:mike@emailscrubbed.com', 'name': 'Mike', 'given_name': 'Mike'} _GenerateAccessToken('register', self._tester, {}, auth_info_dict) _GenerateAcces...
'Test the VerifyIdBaseHandler.SendVerifyIdMessage method with an email identity.'
def testEmailAccessToken(self):
def _TestEmail(action, identity_key, name, token_len): (identity_type, value) = Identity.SplitKey(identity_key) email_args = TestEmailManager.Instance().emails[value][0] identity = self._RunAsync(Identity.Query, self._client, identity_key, None) url = ('https://%s/%s%s' % (ServerEnvi...
'Test the VerifyIdBaseHandler.SendVerifyIdMessage method with an SMS identity.'
def testSmsAccessToken(self):
def _TestSms(identity_key, name): identity = self._RunAsync(Identity.Query, self._client, identity_key, None) (identity_type, value) = Identity.SplitKey(identity_key) sms_args = TestSMSManager.Instance().phone_numbers[value][0] self.assertEqual(sms_args['To'], value) self.ass...
'Test generation and use of a confirmed cookie.'
def testConfirmedCookie(self):
user_dict = self._viewfinder_user_dict self._tester.RegisterViewfinderUser(user_dict, None) ident_dict = {'key': ('Email:%s' % user_dict['email']), 'authority': 'Viewfinder'} response = _AuthViewfinderUser(self._tester, 'login', user_dict, ident_dict, None) auth_test._ValidateAuthUser(self._tester, ...
'Test successful login of the fake viewfinder authority.'
def testFakeViewfinderLogin(self):
(user, device_id) = _TestFakeAuthViewfinderUser('register', self._tester, self._viewfinder_user3_dict, self._mobile_device_dict) self.assertIsNotNone(user.pwd_hash) (user2, device_id2) = _TestFakeAuthViewfinderUser('login', self._tester, self._viewfinder_user3_dict, self._mobile_device_dict) self.assert...
'Test register and login with an identity/user that is not fully created yet.'
def testPartialUser(self):
ident_dict = {'key': ('Email:%s' % self._viewfinder_user_dict['email']), 'authority': 'Viewfinder'} response = _AuthViewfinderUser(self._tester, 'register', self._viewfinder_user_dict, ident_dict, None) response_dict = json.loads(response.body) user = self._RunAsync(User.Query, self._client, response_di...
'Update a friend attribute.'
def testUpdateFriend(self):
self._tester.UpdateFriend(self._cookie, user_id=self._user2.user_id, nickname='Bob') response = self._tester.QueryUsers(self._cookie, [self._user2.user_id]) self.assertEqual(response['users'][0]['nickname'], 'Bob')
'Update friend attributes on self.'
def testUpdateSelf(self):
self._tester.UpdateFriend(self._cookie, user_id=self._user.user_id, nickname='Frank') response = self._tester.QueryUsers(self._cookie, [self._user.user_id]) self.assertEqual(response['users'][0]['nickname'], 'Frank')
'Test multiple updates of various attributes.'
def testMultipleUpdates(self):
self._tester.UpdateFriend(self._cookie, user_id=self._user2.user_id) self._tester.UpdateFriend(self._cookie, user_id=self._user2.user_id, nickname='Jim') self._tester.UpdateFriend(self._cookie, user_id=self._user2.user_id, nickname='Jim Bob') response = self._tester.QueryUsers(self._cookie, [self._us...
'Set nickname, then clear it by passing null.'
def testClearNickname(self):
self._tester.UpdateFriend(self._cookie, user_id=self._user2.user_id, nickname='Nick') self._tester.UpdateFriend(self._cookie, user_id=self._user2.user_id, nickname=None) response = self._tester.QueryUsers(self._cookie, [self._user2.user_id]) self.assertNotIn('nickname', response['users'][0])
'Update user that is not currently a friend.'
def testUpdateNonFriend(self):
self._tester.UpdateFriend(self._cookie, user_id=self._user3.user_id, nickname='Han Solo') response = self._tester.QueryUsers(self._cookie, [self._user3.user_id]) self.assertEqual(response['users'][0], {'user_id': self._user3.user_id, 'nickname': 'Han Solo', 'labels': ['registered']})
'ERROR: Try to update a non-existent user.'
def testUpdateNonUser(self):
self.assertRaisesHttpError(404, self._tester.UpdateFriend, self._cookie, user_id=1000, nickname='Foo Bar')
'ERROR: Send bad requests.'
def testBadRequests(self):
self.assertRaisesHttpError(400, self._tester.UpdateFriend, self._cookie) self.assertRaisesHttpError(400, self._tester.UpdateFriend, self._cookie, user_id=self._user2.user_id, friend_id=100) self.assertRaisesHttpError(400, self._tester.UpdateFriend, self._cookie, user_id=self._user2.user_id, nickname=5)
'Hide photos from default and shared viewpoints.'
def testHidePhotos(self):
(ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 9) self._tester.HidePhotos(self._cookie, [(ep_id, ph_ids[::2])]) (vp_id, new_ep_ids) = self._tester.ShareNew(self._cookie, [(ep_id, ph_ids)], [self._user2.user_id]) self._tester.HidePhotos(self._cookie, [(new_ep_ids[0], ph_ids[::2])])
'Hide photos from multiple episodes.'
def testHideMultipleEpisodes(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._tester.HidePhot...
'Hide the same photos multiple times.'
def testHideDuplicatePhotos(self):
(ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 3) self._tester.HidePhotos(self._cookie, [(ep_id, ph_ids)]) self._tester.HidePhotos(self._cookie, [(ep_id, ph_ids)]) self._tester.HidePhotos(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._tester.HidePhotos(self._cookie, [(ep_id, ph_ids[:1])]) self._tester.HidePhotos(self._cookie, [(ep_id, ph_ids)]) (vp_id, new_ep_ids) = self._tester.ShareNew(self._cookie, [(ep_id, ph_ids)], [self._user2.user_id]) self._tester.HidePhotos(...
'ERROR: Hide from an episode without a POST entry.'
def testHideNonExistingPhoto(self):
(ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 3) self.assertRaisesHttpError(400, self._tester.HidePhotos, self._cookie, [(ep_id, ['punknown'])])
'ERROR: Remove from a non-existing episode.'
def testHideFromNonExistingEpisode(self):
(ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 3) self.assertRaisesHttpError(400, self._tester.HidePhotos, self._cookie, [('eunknown', ph_ids)])
'ERROR: Try to hide photo which has been unshared or removed.'
def testHideRemoved(self):
(ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 1) self._tester.RemovePhotos(self._cookie, [(ep_id, ph_ids)]) self.assertRaisesHttpError(403, self._tester.HidePhotos, self._cookie, [(ep_id, ph_ids)]) self._tester.Unshare(self._cookie, self._user.private_vp_id, [(ep_id, ph_ids)]) self.assertRa...
'ERROR: Ensure that only photos visible to the user can be hidden.'
def testHidePhotosAccess(self):
(ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 1) self.assertRaisesHttpError(403, self._tester.HidePhotos, 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._tester.HidePhotos...
'Creates an IOLoop with an adjustable clock. Increment self._time_adjustment to advance the IOLoop\'s clock and trigger timeouts immediately. This does not use viewfinder.base.util.GetCurrentTimestamp because the IOLoop is likely to go into an infinite loop if time stands completely still.'
def get_new_ioloop(self):
return IOLoop(time_func=(lambda : (time.time() + self._time_adjustment)))
'Speed up the IOLoop\'s clock by one second per iteration.'
@contextlib.contextmanager def _AccelerateTime(self):
done = [False] def _Adjust(): if (not done[0]): self._time_adjustment += 1 self.io_loop.add_callback(_Adjust) _Adjust() (yield) done[0] = True
'Try querying with no notifications.'
def testQueryNotificationsEmpty(self):
self._validate = False notifications = self._RunAsync(Notification.RangeQuery, self._client, self._user.user_id, None, None, None) for n in notifications: self._RunAsync(n.Delete, self._client) response_dict = self._tester.SendRequest('query_notifications', self._cookie, {}) self.assertEqual...
'Simple test for querying notifications.'
def testQueryNotificationsNotifications(self):
self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids)], [self._user2.user_id]) response_dict = self._tester.QueryNotifications(self._cookie) self.assertEqual(len(response_dict['notifications']), 4) response_dict = self._tester.QueryNotifications(self._cookie, max_long_poll=60) sel...
'Create a notification while a long-polling request is pending.'
def testQueryNotificationsLongPoll(self):
response_dict = self._tester.QueryNotifications(self._cookie) start_key = response_dict['last_key'] with self._AccelerateTime(): start_time = self.io_loop.time() self._tester.SendRequestAsync('query_notifications', self._cookie, {'max_long_poll': 60, 'start_key': start_key}, callback=self.st...
'Test notifications sent to multiple devices owned by same user.'
def testQueryNotificationsMultipleDevices(self):
web_cookie = self._GetSecureUserCookie(device_id=self._webapp_device_id) ep_ph_ids = self._UploadOneEpisode(self._cookie3, 2) self._tester.ShareNew(self._cookie3, [ep_ph_ids], [self._user.user_id]) self._tester.QueryNotifications(self._cookie) self._tester.QueryNotifications(web_cookie) self._te...
'Test all notification types.'
def testQueryNotificationsCoverage(self):
self._tester.LinkFacebookUser({'id': 100}, user_cookie=self._cookie) self._tester.UnlinkIdentity(self._cookie, 'FacebookGraph:100') ep_ph_ids = self._UploadOneEpisode(self._cookie, 2) (vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids), ep_ph_ids], [self._user2.use...
'Test inlining of comments in notifications.'
def testCommentInlining(self):
message = ('a' * NotificationManager.MAX_INLINE_COMMENT_LEN) self._tester.PostComment(self._cookie, self._user.private_vp_id, message=message) self._tester.PostComment(self._cookie, self._user.private_vp_id, (message + 'b')) response_dict = self._tester.QueryNotifications(self._cookie, limit=2, scan_for...
'Post multiple comments with increasing timestamps and verify that earliest notification\'s start_key covers them all.'
def testPostCommentNotification(self):
(vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids)], [self._user2.user_id]) timestamp = time.time() message = ('a' * (NotificationManager.MAX_INLINE_COMMENT_LEN + 1)) comment_id1 = self._tester.PostComment(self._cookie, vp_id, timestamp=timestamp, message=message)...
'Create 10 new photos using mobile device.'
def testMobileUploadEpisode(self):
photos = [{'aspect_ratio': 1.3333, 'tn_md5': util.ComputeMD5Hex('thumbnail image data'), 'med_md5': util.ComputeMD5Hex('medium image data'), 'full_md5': util.ComputeMD5Hex('full image data'), 'orig_md5': util.ComputeMD5Hex('original image data'), 'tn_size': (5 * 1024), 'med_size': (10 * 1024...
'Create 10 new photos using web.'
def testWebappUploadEpisode(self):
photos = [{'aspect_ratio': 1.3333, 'timestamp': time.time(), 'content_type': 'text/plain', 'tn_md5': util.ComputeMD5Hex('thumbnail image data'), 'med_md5': util.ComputeMD5Hex('medium image data'), 'full_md5': util.ComputeMD5Hex('full image data'), 'orig_md5': util.ComputeMD5Hex('original image ...
'Upload the same photo to multiple episodes and expect that it fails to load the same photo to a different episode.'
def testUploadDifferentEpisodesFail(self):
photos = [self._CreatePhotoDict(self._cookie)] self._UploadEpisode(self._cookie, photos) self.assertRaisesHttpError(400, self._UploadEpisode, self._cookie, photos)
'Upload the same photo in the same episode twice. Test client scenario where it sometimes uploads an episode with photos and then (due to a crash or restart) will upload the same episode again with the same photos and sometimes additional photos. Server should be able to tolerate this.'
def testUploadSameEpisodeTwice(self):
photos = [self._CreatePhotoDict(self._cookie)] ep_dict = {'timestamp': time.time()} (ep_id, _) = self._UploadEpisode(self._cookie, photos, ep_dict) ep_dict['episode_id'] = ep_id photos.append(self._CreatePhotoDict(self._cookie)) (ep_id2, _) = self._UploadEpisode(self._cookie, photos, ep_dict) ...
'Verify the same photo/episode upload twice is idempotent.'
def testRepeatUpload(self):
request_dict = {'activity': self._tester.CreateActivityDict(self._cookie), 'episode': self._CreateEpisodeDict(self._cookie), 'photos': [self._CreatePhotoDict(self._cookie)]} response_dict1 = _TestUploadEpisode(self._tester, self._cookie, request_dict) response_dict2 = _TestUploadEpisode(self._tester, self._...
'ERROR: Try to create an episode and photo using device ids that are different than the ones in the user cookies.'
def testWrongDeviceIds(self):
bad_episode_id = Episode.ConstructEpisodeId(100, 1000, 1) self.assertRaisesHttpError(403, self._tester.UploadEpisode, self._cookie, ep_dict={'episode_id': bad_episode_id, 'timestamp': 100}, ph_dict_list=[]) episode_id = Episode.ConstructEpisodeId(100, self._device_ids[0], 100) bad_photo_id = Photo.Const...
'Upload an episode twice, and on the second time from a bad user-id.'
def testBadUserEpisodeUpload(self):
request_dict = {'activity': self._tester.CreateActivityDict(self._cookie), 'episode': self._CreateEpisodeDict(self._cookie), 'photos': [self._CreatePhotoDict(self._cookie)]} _TestUploadEpisode(self._tester, self._cookie, request_dict) self.assertRaisesHttpError(403, _TestUploadEpisode, self._tester, self._c...
'Create new photos using mobile device and upload image file assets.'
def testUploadImageFiles(self):
request_dict = {'activity': self._tester.CreateActivityDict(self._cookie), 'episode': self._CreateEpisodeDict(self._cookie), 'photos': [self._CreatePhotoDict(self._cookie)]} response_dict = _TestUploadEpisode(self._tester, self._cookie, request_dict) photos = response_dict['photos'] for p in photos: ...
'Create new photos with placemarks, some with unicode characters, some with missing place names.'
def testPlacemarks(self):
photos = [self._CreatePhotoDict(self._cookie, placemark={'iso_country_code': 'US', 'country': 'United States', 'state': 'NY', 'locality': 'New York', 'sublocality': 'NoHo', 'thoroughfare': 'Broadway', 'subthoroughfare': '682'}), self._CreatePhotoDict(self._cookie, placemark={'iso_country_code': 'DR', 'country...
'Upload a photo with an ID that already exists.'
def testExistingPhotoId(self):
photos = [self._CreatePhotoDict(self._cookie, caption='first caption')] (ep_id, _) = self._UploadEpisode(self._cookie, photos) photos[0]['caption'] = 'second caption' self._UploadEpisode(self._cookie, photos, {'episode_id': ep_id})
'Upload photos with asset keys.'
def testAssetKey(self):
photos = [self._CreatePhotoDict(self._cookie, asset_keys=['a/#asset1'])] self._UploadEpisode(self._cookie, photos)
'Upload photos with md5 checksums set.'
def testMD5(self):
orig_md5 = '4ae4aa09eb9fd9ceab65794d4f7fb29d' full_md5 = 'a37bdd4d2338f5ac338f766e255eb4b3' med_md5 = '373bf078574d0bae9a76268ee087e7c4' tn_md5 = 'dd8d288cff109fed6bf1b8cdfac2f4b0' photos = [{'aspect_ratio': 0.75, 'timestamp': time.time(), 'orig_md5': orig_md5, 'full_md5': full_md5, 'med_md5': med_m...
'Call upload_episode once. Then call it again, but with different MD5 image values. Because the photo image data does not yet exist, the metadata should be overwritten with the new values. Then actually upload the image data and try to overwrite the MD5 values again, expecting an error this time.'
def testUploadMD5Mismatch(self):
upload_data = [('tn_md5', '.t', 'new thumbnail image data'), ('med_md5', '.m', 'new medium image data'), ('full_md5', '.f', 'new full image data'), ('orig_md5', '.o', 'new original image data')] ph_dict = {'aspect_ratio': 0.75, 'timestamp': time.time(), 'tn_size': (5 * 1024),...
'Force op failure in order to test idempotency.'
@mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True) def testIdempotency(self):
ph_dict = self._CreatePhotoDict(self._cookie) location = ph_dict.pop('location') placemark = ph_dict.pop('placemark') ep_dict = self._CreateEpisodeDict(self._cookie) request_dict = {'activity': self._tester.CreateActivityDict(self._cookie), 'episode': ep_dict, 'photos': [ph_dict]} _TestUploadEpi...
'Returns an upload_episode request dict.'
def _UploadEpisode(self, user_cookie, photos, ep_dict=None):
if (ep_dict is None): ep_dict = {} ep_dict['title'] = 'Episode Title' return self._tester.UploadEpisode(user_cookie, ep_dict, photos)
'Makes a GET request to the specified \'url\' to download file.'
def _DownloadImageFile(self, url):
response = self._RunAsync(self._tester.http_client.fetch, url, method='GET') assert (response.code == 200), response assert (response.headers['Content-Type'] == 'image/jpeg'), response.headers['Content-Type'] return response.body
'Makes a PUT request to the specified \'url\' to upload \'image_data\'.'
def _UploadImageFile(self, url, image_data):
md5_hex = util.ComputeMD5Base64(image_data) response = self._RunAsync(self._tester.http_client.fetch, url, method='PUT', body=image_data, headers={'Content-Type': 'image/jpeg', 'Content-MD5': md5_hex}) assert (response.code == 200), response return response.body
'Update device properties of default mobile_dev.'
def testSimpleUpdate(self):
self._tester.UpdateDevice(self._cookie, self._mobile_device.device_id, **_DEVICE_DICT)
'Test update with only device id.'
def testMinimumUpdate(self):
self._tester.UpdateDevice(self._cookie, self._mobile_device.device_id)
'Test adding a push token after initial registration.'
def testAddPushToken(self):
(user, device_id) = self._tester.RegisterGoogleUser({'name': 'Andy', 'email': 'kimball.andy@emailscrubbed.com', 'verified_email': True}, {}) cookie = self._GetSecureUserCookie(user, device_id) self._tester.UpdateDevice(cookie, device_id, push_token=_DEVICE_DICT['push_token'])
'Test update, then update again with increased access time.'
def testLastAccess(self):
self._tester.UpdateDevice(self._cookie, self._mobile_device.device_id) util._TEST_TIME += 1 self._tester.UpdateDevice(self._cookie, self._mobile_device.device_id, **_DEVICE_DICT)
'Update push token that is already in use by another device.'
def testDuplicateToken(self):
self._tester.UpdateDevice(self._cookie, self._mobile_device.device_id, **_DEVICE_DICT) (user, device_id) = self._tester.RegisterGoogleUser({'name': 'Andy', 'email': 'kimball.andy@emailscrubbed.com', 'verified_email': True}, {}) cookie = self._GetSecureUserCookie(user, device_id) self._tester.UpdateDevic...
'Verify 400 bad auth cookie error on device id mismatch.'
def testDeviceIdMismatch(self):
self.assertRaisesHttpError(400, self._tester.UpdateDevice, self._cookie, (self._mobile_device.device_id + 1))
'Terminate user account with a single identity.'
def testSimpleTerminate(self):
self._tester.TerminateAccount(self._cookie2) self._cookies.remove(self._cookie2)
'Terminate user account with multiple linked identities.'
def testMultipleTerminate(self):
self._tester.LinkFacebookUser({'id': 100}, user_cookie=self._cookie) self._tester.TerminateAccount(self._cookie) self._cookies.remove(self._cookie)
'Terminate user account that is friends with another account.'
def testTerminateWithFriend(self):
self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids)], [self._user2.user_id, self._user3.user_id]) self._tester.TerminateAccount(self._cookie2) self._cookies.remove(self._cookie2)
'Share to identity that was formerly connected to terminated account.'
def testShareToTerminatedAccount(self):
self._tester.TerminateAccount(self._cookie2) self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids)], ['FacebookGraph:2']) self._cookies.remove(self._cookie2)
'Try to log in with a terminated user cookie.'
def testLoginAfterTerminate(self):
self._tester.TerminateAccount(self._cookie3) self.assertRaisesHttpError(401, self._tester.TerminateAccount, self._cookie3) self._cookies.remove(self._cookie3)
'Terminate user account to which a contact was linked.'
def testTerminateWithContact(self):
identity_key = 'Email:foo@emailscrubbed.com' contact_dict = Contact.CreateContactDict(self._user.user_id, [('Email:user3@emailscrubbed.com', None)], util._TEST_TIME, Contact.GMAIL) self._UpdateOrAllocateDBObject(Contact, **contact_dict) self._tester.TerminateAccount(self._cookie3) response_dict = se...
'Verify N concurrent synchronous uploads with an additional operation manager also trying to scan and assume device operation queues.'
@mock.patch.object(Lock, 'ABANDONMENT_SECS', 0.15) @mock.patch.object(Lock, 'LOCK_RENEWAL_SECS', 0.05) def testConcurrentOperations(self):
N = 50 with util.Barrier(self.stop) as b: for i in xrange(N): request_dict = {'activity': self._tester.CreateActivityDict(self._cookie), 'episode': self._CreateEpisodeDict(self._cookie), 'photos': [self._CreatePhotoDict(self._cookie)]} self._tester.SendRequestAsync('upload_episod...
'Ensure that the INLINE_INVALIDATIONS migration works correctly.'
def testInlineInvalidationsMigration(self):
episode_id = Episode.ConstructEpisodeId(1, self._device_ids[0], 1) photo_id = Photo.ConstructPhotoId(1, self._device_ids[0], 1) request = {'activity': self._tester.CreateActivityDict(self._cookie), 'episode': {'episode_id': episode_id, 'timestamp': 1}, 'photos': [self._CreatePhotoDict(self._cookie, photo_id...
'Ensure that the EXTRACT_FILE_SIZES migration works correctly.'
def testFileSizeExtraction(self):
episode_id = Episode.ConstructEpisodeId(1, self._device_ids[0], 1) photo_id = Photo.ConstructPhotoId(1, self._device_ids[0], 1) request = {'activity': self._tester.CreateActivityDict(self._cookie), 'episode': {'episode_id': episode_id, 'timestamp': 1}, 'photos': [self._CreatePhotoDict(self._cookie, photo_id...
'Ensure that the INLINE_COMMENTS migration works correctly.'
def testInlineCommentsMigration(self):
comment_id = self._tester.PostComment(self._cookie, self._user.private_vp_id, 'hi') response_dict = self._SendRequest('query_notifications', self._cookie, {'scan_forward': False}, version=Message.EXTRACT_FILE_SIZES) notify_dict = response_dict['notifications'][0] invalidate = notify_dict['invalidate'] ...
'Ensure that the SPLIT_NAMES migration works correctly.'
def testSplitNamesMigration(self):
self._SendRequest('update_user', self._cookie, {'name': ' DCTB \r\nAndrew E DCTB Kimball '}, version=Message.INLINE_COMMENTS) user = self._RunAsync(User.Query, self._client, self._user.user_id, None) self.assertEqual(user.name, ' DCTB \r\nAndrew E DCTB Kimball ') ...
'Ensure that the EXPLICIT_SHARE_ORDER migration works correctly. The expectation is that the migration orders the episode ids and photo ids to the original mobile client algorithm for cover photo selection.'
def testExplicitShareOrderMigration(self):
def _IsEpDictOrderedAsOriginalAlgorithm(ep_dicts, episode_id_key): 'Returns true if the order matches original mobile client algorithm ordering for\n cover photo selection.' last_episode_id = None for ep_dict in ep_dicts: ...
'Ensure that the SUPPRESS_BLANK_COVER_PHOTO migration works correctly.'
def testSuppressBlankCoverPhotoMigration(self):
(episode_id1, photo_ids1) = self._UploadOneEpisode(self._cookie, 2) ep_dicts = self._tester._CreateCopyDictList(self._cookie, [(episode_id1, photo_ids1)]) update_vp_dict = {'cover_photo': {'episode_id': episode_id1, 'photo_id': ''}} request_dict = {'activity': self._tester.CreateActivityDict(self._cooki...
'Ensure that the SUPPORT_MULTIPLE_IDENTITIES_PER_CONTACT migration works correctly.'
def testSupportMultipleIdentitiesPerContact(self):
identity_key = ('Email:' + self._user2.email) self._UpdateOrAllocateDBObject(Identity, key=identity_key, user_id=21) contact_dict = Contact.CreateContactDict(user_id=self._user.user_id, identities_properties=[(identity_key, 'work'), (('Email:' + self._user3.email), 'home'), ('Phone:+13191234567', 'mobile')]...
'Test migrator that renames HIDDEN label to REMOVED for older clients.'
def testRenamePhotoLabelMigration(self):
(ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 2) response_dict = self._SendRequest('remove_photos', self._cookie, {'episodes': [{'episode_id': ep_id, 'photo_ids': ph_ids[:1]}, {'episode_id': ep_id, 'photo_ids': ph_ids[1:]}]}, version=Message.SUPPORT_MULTIPLE_IDENTITIES_PER_CONTACT) post_id = Post.C...
'Test migrator that removes names from non-register auth messages.'
def testSuppressAuthNameMigration(self):
user_dict = {'name': 'Andy Kimball', 'given_name': 'Andy', 'family_name': 'Kimball', 'email': 'andy@emailscrubbed.com'} (user, device_id) = self._tester.RegisterViewfinderUser(user_dict, None) user_cookie = self._GetSecureUserCookie(user, device_id) url = self._tester.GetUrl('/link/viewfinder') r...
'Test migrator that projects only ids from followers returned by query_viewpoints.'
def testSupportRemovedFollowers(self):
self._CreateSimpleTestAssets() (vp_id, _) = self._ShareSimpleTestAssets([self._user2.user_id, self._user3.user_id]) self._tester.RemoveFollowers(self._cookie, vp_id, [self._user3.user_id]) response_dict = self._SendRequest('query_viewpoints', self._cookie, {'viewpoints': [{'viewpoint_id': vp_id, 'get_fo...
'Test migrator that removes timestamp from share and save operations.'
def testSuppressCopyTimestamp(self):
self._CreateSimpleTestAssets() new_episode_id = Episode.ConstructEpisodeId(time.time(), self._device_ids[0], self._test_id) self._test_id += 1 request_dict = {'activity': self._tester.CreateActivityDict(self._cookie), 'viewpoint': self._CreateViewpointDict(self._cookie), 'episodes': [{'existing_episode_...
'Test migrator that truncates and skips fields in upload_contacts.'
def testSupportContactLimits(self):
request_dict = {'contacts': [{'contact_source': Contact.MANUAL, 'name': ('a' * 1001), 'given_name': ('a' * 2000), 'family_name': ('a' * 6000), 'identities': [{'identity': ('Email:%s' % ('a' * 1001)), 'description': ('a' * 1001)} for i in xrange(100)]}]} self._SendRequest('upload_contacts', self._cookie, request...
'Test migrator that removes empty titles from update_viewpoint operations.'
def testSuppressEmptyTitle(self):
self._CreateSimpleTestAssets() (vp_id, ep_id) = self._ShareSimpleTestAssets([self._user2.user_id]) request_dict = {'activity': self._tester.CreateActivityDict(self._cookie), 'viewpoint_id': vp_id, 'title': ''} self._SendRequest('update_viewpoint', self._cookie, request_dict, version=Message.SUPPORT_CONT...
'Test that "method" is not supported in the specified "version" of the message protocol.'
def _TestMethodNotSupported(self, method, version):
self.assertRaisesHttpError(400, self._SendRequest, method, self._cookie, {}, version=version)
'Update existing viewpoints.'
def testUpdateViewpoint(self):
self._tester.UpdateViewpoint(self._cookie, self._user.private_vp_id, title='a new title', description='a new description', name='newname') self._tester.UpdateViewpoint(self._cookie2, self._new_vp_id, cover_photo={'episode_id': self._new_ep_id, 'photo_id': self._photo_ids[1]}) self._tester.Update...
'Update viewpoint attributes for which we keep previous values.'
def testUpdateAttributesWithHistory(self):
self._tester.UpdateViewpoint(self._cookie, self._new_vp_id, title='a new title', cover_photo={'episode_id': self._new_ep_id, 'photo_id': self._photo_ids[1]}) response_dict = self._tester.QueryNotifications(self._cookie, 1, None, scan_forward=False) activity = response_dict['notifications'][0]['inline'...
'Update follower attributes that should not trigger activity creation.'
def testUpdateFollower(self):
self._UpdateOrAllocateDBObject(Follower, user_id=self._user.user_id, viewpoint_id=self._new_vp_id, labels=[]) self._tester.UpdateViewpoint(self._cookie, self._new_vp_id, viewed_seq=100) self._tester.UpdateViewpoint(self._cookie, self._new_vp_id, viewed_seq=101, labels=[]) self._tester.UpdateViewpoint(se...
'Update viewpoint attribute to same value as it had before.'
def testNoOpUpdate(self):
self._tester.UpdateViewpoint(self._cookie, self._new_vp_id, title='some title') self._tester.UpdateViewpoint(self._cookie, self._new_vp_id, title='some title')
'Try to update attributes which not available for update.'
def testAdditionalAttributes(self):
for attr in ['sharing_user_id', 'foo']: self.assertRaisesHttpError(400, self._tester.UpdateViewpoint, self._cookie, self._new_vp_id, attr=attr)
'Update a viewpoint with an unrevivable removed follower.'
def testUnrevivable(self):
self._tester.RemoveFollowers(self._cookie, self._new_vp_id, [self._user2.user_id]) self._tester.UpdateViewpoint(self._cookie, self._new_vp_id, title='a new title') response_dict = self._tester.QueryFollowed(self._cookie2) self.assertIn(Follower.REMOVED, response_dict['viewpoints'][0]['labels']) ...
'Force op failure in order to test idempotency.'
@mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True) def testIdempotency(self):
self._tester.RemoveViewpoint(self._cookie2, self._new_vp_id) self._tester.UpdateViewpoint(self._cookie, self._new_vp_id, title='a new title', description='a new description', name='newname', cover_photo={'episode_id': self._new_ep_id, 'photo_id': self._photo_ids[1]})
'ERROR: Try to update a viewpoint title to the empty string.'
def testEmptyTitle(self):
self.assertRaisesHttpError(400, self._tester.UpdateViewpoint, self._cookie, self._new_vp_id, title='')
'ERROR: Try to update a viewpoint that does not exist.'
def testInvalidViewpoint(self):
self.assertRaisesHttpError(400, self._tester.UpdateViewpoint, self._cookie, 'vunknown', title='some title')
'ERROR: Try to update a viewpoint that is not followed.'
def testViewpointNotFollowed(self):
self.assertRaisesHttpError(403, self._tester.UpdateViewpoint, self._cookie3, self._new_vp_id, title='some title')
'ERROR: Try to update read-only attribute.'
def testUpdateReadOnlyAttribute(self):
self.assertRaisesHttpError(400, self._tester.UpdateViewpoint, self._cookie, self._new_vp_id, type='foobar')
'ERROR: Try to update update_seq attribute.'
def testUpdateSeq(self):
self.assertRaisesHttpError(400, self._tester.UpdateViewpoint, self._cookie, self._new_vp_id, update_seq=100)
'ERROR: Try to update both viewpoint and follower metadata in one call.'
def testUpdateViewpointAndFollower(self):
self.assertRaisesHttpError(400, self._tester.UpdateViewpoint, self._cookie, self._new_vp_id, title='some title', viewed_seq=2)
'ERROR: Try to add invalid cover photos.'
def testInvalidCoverPhotos(self):
self.assertRaisesHttpError(400, self._tester.UpdateViewpoint, self._cookie, self._user.private_vp_id, cover_photo={}) self.assertRaisesHttpError(400, self._tester.UpdateViewpoint, self._cookie, self._user.private_vp_id, cover_photo={'episode_id': self._episode_id, 'photo_id': self._photo_ids[1]}) self.asser...
'Verify that all allow_prospective service methods can be called by a prospective user, and that all other methods result in a permission error.'
def testProspectiveUserPermissions(self):
allow_prospective_names = set(['query_episodes', 'query_users', 'query_viewpoints', 'query_followed']) for (name, method) in service.ServiceHandler.SERVICE_MAP.items(): self.assertEqual((name in allow_prospective_names), method.allow_prospective) try: self._SendRequest(name, self._pr...
'ERROR: Test various invalid and missing cookies.'
def testInvalidUser(self):
bad_cookie = self._tester.GetSecureUserCookie(1000, 1000, 'andy') self.assertRaisesHttpError(401, self._SendRequest, 'query_episodes', bad_cookie, {}) bad_cookie = self._tester.EncodeUserCookie({}) self.assertRaisesHttpError(401, self._SendRequest, 'query_episodes', bad_cookie, {}) response = self._...
'Add single follower to viewpoint.'
def testAddFollower(self):
self._tester.AddFollowers(self._cookie, self._vp_id, ['Email:extra.user1@emailscrubbed.com'])
'Add multiple followers to viewpoint.'
def testAddMultipleFollowers(self):
self._tester.AddFollowers(self._cookie, self._user.private_vp_id, ['Email:extra.user1@emailscrubbed.com', 'Email:extra.user2@emailscrubbed.com', {'user_id': self._extra_users[0].user_id}])
'Add same followers multiple times.'
def testDuplicateFollowers(self):
self._tester.AddFollowers(self._cookie, self._vp_id, ['Email:extra.user1@emailscrubbed.com', 'Email:extra.user1@emailscrubbed.com', 'Email:extra.user2@emailscrubbed.com']) util._TEST_TIME += 100 self._tester.AddFollowers(self._cookie, self._vp_id, ['Email:extra.user1@emailscrubbed.com', 'Email:extra.user1@e...