desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Pass through to ServiceTester.SendRequest.'
def _SendRequest(self, method, user_cookie, request_dict, version=None):
return self._tester.SendRequest(method, user_cookie, request_dict, version=version)
'Pass through to ServiceTester.GetSecureUserCookie, but defaulting to user #1 and device #1 if not specified.'
def _GetSecureUserCookie(self, user=None, device_id=None, confirm_time=None):
return self._tester.GetSecureUserCookie(user_id=(self._user.user_id if (not user) else user.user_id), device_id=(device_id or self._device_ids[0]), user_name=(self._user.name if (not user) else user.name), confirm_time=confirm_time)
'Create several interesting users and devices to use in testing.'
def _CreateTestUsers(self):
self._users = list() self._device_ids = list() self._cookies = list() def _SaveUserInfo(user, device_id): self._users.append(user) device_id = (user.webapp_dev_id if (device_id is None) else device_id) self._device_ids.append(device_id) self._cookies.append(self._GetSecur...
'Create two episodes with several photos in user #1\'s default viewpoint. This is useful for tests which just need a little data to work with, and where having lots of data makes debugging harder.'
def _CreateSimpleTestAssets(self):
(self._episode_id, self._photo_ids) = self._UploadOneEpisode(self._cookie, 2) (self._episode_id2, self._photo_ids2) = self._UploadOneEpisode(self._cookie, 2)
'Shares the episode and photos ids created by _CreateSimpleTestAssets with the given list of contacts. Returns a tuple with the viewpoint and episode.'
def _ShareSimpleTestAssets(self, contacts):
(vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids)], contacts, **self._CreateViewpointDict(self._cookie)) return (vp_id, ep_ids[0])
'Create multiple unbound contacts for user #1 and user #2.'
def _CreateSimpleContacts(self):
for user_id in [self._user.user_id, self._user2.user_id]: for identity_key in ['Local:identity1', 'Local:identity2']: contact_dict = Contact.CreateContactDict(user_id, [('Phone:+13191234567', 'mobile'), (identity_key, None)], util._TEST_TIME, Contact.GMAIL) self._UpdateOrAllocateDBOb...
'Creates a prospective user by sharing the photos created by _CreateSimpleTestAssets to a new email identity "Email:prospective@emailscrubbed.com". Returns a tuple containing the user, the new viewpoint, and the new episode.'
def _CreateProspectiveUser(self):
assert getattr(self, '_episode_id'), 'call _CreateSimpleTestAssets first' (vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids)], ['Email:prospective@emailscrubbed.com']) identity = self._RunAsync(Identity.Query, self._client, 'Email:prospective@emailscrubbed.com',...
'Create a good number of interesting viewfinder assets for use by query tests in derived classes. Use the tester classes in order to ensure that all will be cleaned up after the test has completed.'
def _CreateQueryAssets(self, add_test_photos=False):
self._tester.ShareNew(self._cookie, [], [], **self._CreateViewpointDict(self._cookie)) ep_ph_ids_list = self._UploadMultipleEpisodes(self._cookie, 37, add_asset_keys=True, add_test_photos=add_test_photos) (vp_id, ep_ids) = self._tester.ShareNew(self._cookie, ep_ph_ids_list, [self._user2.user_id, self._user3...
'Updates an existing DBObject of type "cls", with the attributes in "db_dict". If no such object yet exists, allocates a new object, generating the object\'s key if necessary. Adds the object to the DB validator\'s model so that it can verify against it. Returns the updated or allocate object. This method is especially...
def _UpdateOrAllocateDBObject(self, cls, **db_dict):
hash_key_col = cls._table.hash_key_col range_key_col = cls._table.range_key_col if (not range_key_col): if (not db_dict.has_key(hash_key_col.name)): cls.Allocate(self._client, self.stop) else: cls.Query(self._client, db_dict[hash_key_col.name], col_names=None, callbac...
'Force the specified viewpoint to be a system viewpoint for testing purposes.'
def _MakeSystemViewpoint(self, viewpoint_id):
viewpoint = self._RunAsync(Viewpoint.Query, self._client, viewpoint_id, None) with mock.patch.object(viewpoint._columns['type'].col_def, 'read_only', False): self._UpdateOrAllocateDBObject(Viewpoint, viewpoint_id=viewpoint_id, type=Viewpoint.SYSTEM)
'Writes "log_content" to a user client log.'
def _WriteClientLog(self, user_cookie, log_record):
response_dict = self._SendRequest('new_client_log_url', user_cookie, {'headers': {'op_id': 'o1', 'op_timestamp': time.time()}, 'timestamp': log_record.timestamp, 'client_log_id': log_record.client_id}) url = response_dict['client_log_put_url'] headers = {'Content-Type': CLIENT_LOG_CONTENT_TYPE} self._te...
'Generate and execute requests to post "num_comments" to the specified viewpoint. Select from "user_cookies" to impersonate users who are posting the comments. Link each comment to the preceding comment via its "asset_id" attribute. If "ph_id" is specified, link the "root" comment\'s "asset_id" to that photo. Return th...
def _PostCommentChain(self, user_cookies, vp_id, num_comments, ph_id=None):
comment_ids = [] timestamp = time.time() asset_id = ph_id for i in xrange(num_comments): cm_dict = {'timestamp': timestamp} message = ('Comment #%d' % self._test_id) if (asset_id is not None): cm_dict['asset_id'] = asset_id timestamp += 10 self._tes...
'Generate and execute a request to upload "num_photos" to the default viewpoint of the specified user. Return a tuple of ids: (episode_id, photo_ids)'
def _UploadOneEpisode(self, user_cookie, num_photos):
ep_dict = {'title': ('Episode #%d Title' % self._test_id), 'description': ('Episode #%d Description' % self._test_id)} self._test_id += 1 ph_dict_list = [self._CreatePhotoDict(user_cookie) for i in range(num_photos)] return self._tester.UploadEpisode(user_cookie, ep_dict, ph_dict_list)
'Upload multiple episodes to the specified user\'s default viewpoint. Divide "num_photos" into groups that logarithmically decrease in size (base-2). Create the number of episodes that are needed to contain those photos, where each episode has a different number of photos, and the last episode has zero photos. Return a...
def _UploadMultipleEpisodes(self, user_cookie, num_photos, add_asset_keys=False, add_test_photos=False):
result = [] while True: half = ((num_photos + 1) / 2) num_photos -= half ep_dict = {'title': ('Episode #%d Title' % self._test_id), 'description': ('Episode #%d Description' % self._test_id)} self._test_id += 1 ph_dict_list = [self._CreatePhotoDict(user_cookie...
'Return count of episodes in the given viewpoint.'
def _CountEpisodes(self, user_cookie, viewpoint_id):
vp_select = self._tester.CreateViewpointSelection(viewpoint_id) response_dict = self._tester.QueryViewpoints(user_cookie, [vp_select]) return len(response_dict['viewpoints'][0]['episodes'])
'Create dict() for a test viewpoint, overriding default values with whatever is passed in "update_vp_dict".'
def _CreateViewpointDict(self, user_cookie, **update_vp_dict):
(user_id, device_id) = self._tester.GetIdsFromCookie(user_cookie) vp_dict = {'viewpoint_id': Viewpoint.ConstructViewpointId(device_id, self._test_id), 'title': ('Title %s' % self._test_id), 'description': ('Description %s. \xe6\x9c\x8b\xe5\x8f\x8b\xe4\xbd\xa0\xe5\xa5\xbd.' % self._test_id), 'name': ('N...
'Create dict() for a test episode, overriding default values with whatever is passed in "update_ep_dict".'
def _CreateEpisodeDict(self, user_cookie, **update_ep_dict):
(user_id, device_id) = self._tester.GetIdsFromCookie(user_cookie) timestamp = (time.time() - self._test_id) ep_dict = {'episode_id': Episode.ConstructEpisodeId(timestamp, device_id, self._test_id), 'timestamp': timestamp, 'title': ('Title %s' % self._test_id), 'description': ('Description %s. \xe6\...
'Create dict() for a test photo, overriding default values with whatever is passed in "update_ph_dict".'
def _CreatePhotoDict(self, user_cookie, **update_ph_dict):
(user_id, device_id) = self._tester.GetIdsFromCookie(user_cookie) timestamp = update_ph_dict.get('timestamp', (time.time() - self._test_id)) ph_dict = {'photo_id': Photo.ConstructPhotoId(timestamp, device_id, self._test_id), 'aspect_ratio': (0.75 + self._test_id), 'content_type': 'image/jpeg', 'tn_md5': uti...
'Upload two photos.'
def setUp(self):
super(UnshareTestCase, self).setUp() self._CreateSimpleTestAssets() (self._new_vp_id, new_ep_ids) = self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids)], [self._user2.user_id]) self._new_ep_id = new_ep_ids[0] settings = AccountSettings.CreateForUser(self._user2.user_id, sms_aler...
'Restore constants for future tests.'
def tearDown(self):
Photo.CLAWBACK_GRACE_PERIOD = (((60 * 60) * 24) * 7) UnshareOperation._UNSHARE_LIMIT = 200 super(UnshareTestCase, self).tearDown()
'Share photo from originator to user2, and unshare.'
def testUnshare(self):
UnshareOperation._UNSHARE_LIMIT = 1 before_cover_photo = self._RunAsync(Viewpoint.Query, self._client, self._new_vp_id, col_names=None).cover_photo self._tester.Unshare(self._cookie, self._new_vp_id, [(self._new_ep_id, self._photo_ids[:1])]) viewpoint = self._RunAsync(Viewpoint.Query, self._client, self...
'Share both photos from originator to user2, then user2 to user3, then unshare from originator.'
def testSerialUnshare(self):
UnshareOperation._UNSHARE_LIMIT = 2 self._tester.ShareNew(self._cookie2, [(self._new_ep_id, self._photo_ids)], [self._user3.user_id]) self._tester.Unshare(self._cookie, self._new_vp_id, [(self._new_ep_id, self._photo_ids)])
'Share both photos from originator to multiple viewpoints, then unshare from originator.'
def testTreeUnshare(self):
UnshareOperation._UNSHARE_LIMIT = 7 for i in xrange(2): (vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(self._new_ep_id, self._photo_ids)], [self._user2.user_id]) for j in xrange(1): self._tester.ShareNew(self._cookie2, [(ep_ids[0], self._photo_ids)], [self._user3.user_id]) ...
'Share both photos from originator to user2, then share only one photo to user3, then unshare all photos.'
def testUnshareSubsetShares(self):
UnshareOperation._UNSHARE_LIMIT = 2 self._tester.ShareNew(self._cookie2, [(self._new_ep_id, self._photo_ids[:1])], [self._user3.user_id]) self._tester.Unshare(self._cookie, self._new_vp_id, [(self._new_ep_id, self._photo_ids)])
'Share both photos from originator to user2, then user2 back to the the originating viewpoint (but different episode), then unshare.'
def testCircularUnshare(self):
UnshareOperation._UNSHARE_LIMIT = 3 (vp_id, ep_ids) = self._tester.ShareNew(self._cookie2, [(self._new_ep_id, self._photo_ids)], [self._user3.user_id]) self._tester.ShareExisting(self._cookie2, self._new_vp_id, [(ep_ids[0], self._photo_ids)]) self._tester.Unshare(self._cookie, self._new_vp_id, [(self._n...
'Share both photos from originator to user2, then user2 to user3, the unshare from user2.'
def testSubUnshare(self):
UnshareOperation._UNSHARE_LIMIT = 1 (vp_id, ep_ids) = self._tester.ShareNew(self._cookie2, [(self._new_ep_id, self._photo_ids)], [self._user3.user_id]) self._tester.Unshare(self._cookie2, vp_id, [(ep_ids[0], self._photo_ids)])
'Share photo from originator to user2, then user2 to user3, then from originator to user3. Verify that when user2 unshares, photos shared by originator are not unshared as well.'
def testMultiplePaths(self):
UnshareOperation._UNSHARE_LIMIT = 1 (vp_id, ep_ids) = self._tester.ShareNew(self._cookie2, [(self._new_ep_id, self._photo_ids)], [self._user3.user_id]) (vp_id_2, ep_ids_2) = self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids)], [self._user3.user_id]) self._tester.Unshare(self._cooki...
'Share photo from originator to user2 to user3, then unshare multiple times.'
def testMultipleUnshares(self):
(vp_id, ep_ids) = self._tester.ShareNew(self._cookie2, [(self._new_ep_id, self._photo_ids[:1]), (self._new_ep_id, self._photo_ids[1:])], [self._user3.user_id]) UnshareOperation._UNSHARE_LIMIT = 3 self._tester.Unshare(self._cookie, self._new_vp_id, [(self._new_ep_id, self._photo_ids[:1])]) UnshareOperati...
'Test same episode and photos unshared in same request.'
def testDuplicates(self):
self._tester.Unshare(self._cookie, self._new_vp_id, [(self._new_ep_id, self._photo_ids[:1]), (self._new_ep_id, [self._photo_ids[0], self._photo_ids[0]])])
'ERROR: Try to unshare invalid viewpoint id. Returns InvalidRequest.'
def testInvalidViewpointId(self):
self.assertRaisesHttpError(400, self._tester.Unshare, self._cookie, 'vunknown', [(self._new_ep_id, self._photo_ids)])
'ERROR: Try to unshare invalid episode id. Returns InvalidRequest.'
def testInvalidEpisodeId(self):
self.assertRaisesHttpError(400, self._tester.Unshare, self._cookie, self._new_vp_id, [('eunknown', self._photo_ids)])
'ERROR: Try to unshare invalid photo id.'
def testInvalidPhotoId(self):
self.assertRaisesHttpError(403, self._tester.Unshare, self._cookie, self._new_vp_id, [(self._new_ep_id, ['punknown'])])
'ERROR: Try to unshare a photo which the caller has no permission to access.'
def testNoPermission(self):
self.assertRaisesHttpError(403, self._tester.Unshare, self._cookie3, self._new_vp_id, [(self._new_ep_id, self._photo_ids)])
'ERROR: Try to unshare a photo which the caller did not originally share.'
def testNotSharer(self):
self.assertRaisesHttpError(403, self._tester.Unshare, self._cookie2, self._new_vp_id, [(self._new_ep_id, self._photo_ids)])
'ERROR: Try to unshare more episodes than the limit.'
def testShareLimit(self):
UnshareOperation._UNSHARE_LIMIT = 3 for i in xrange(3): self._tester.ShareNew(self._cookie, [(self._new_ep_id, self._photo_ids)], [self._user2.user_id]) self.assertRaisesHttpError(403, self._tester.Unshare, self._cookie, self._new_vp_id, [(self._new_ep_id, self._photo_ids)])
'ERROR: Share from originator to user2, then unshare. Verify that user2 is unable to reshare.'
def testRevokedPrivileges(self):
self._tester.Unshare(self._cookie, self._new_vp_id, [(self._new_ep_id, self._photo_ids)]) self.assertRaisesHttpError(403, self._tester.ShareNew, self._cookie2, [(self._new_ep_id, self._photo_ids)], [self._user3.user_id])
'Set grace period to a fraction of a second. Share both photos from originator to user2. Unshare photo 1 immediately and verify all privileges are revoked. Wait the grace period, unshare photo 2 and verify error is raised.'
def testClawbackGracePeriod(self):
Photo.CLAWBACK_GRACE_PERIOD = 0.5 util._TEST_TIME = time.time() (vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids)], [self._user2.user_id]) self._tester.Unshare(self._cookie, vp_id, [(ep_ids[0], self._photo_ids[:1])]) self._RunAsync(self.io_loop.add_timeout, (...
'Create episode with an old timestamp that is older than the clawback grace period. Then upload the episode so that its publish_timestamp is now. Verify that unshare is allowed, since unshare should use the publish_timestamp, not the episode timestamp.'
def testUnshareTimestamps(self):
timestamp = ((time.time() - Photo.CLAWBACK_GRACE_PERIOD) - 1) (ep_id, ph_ids) = self._tester.UploadEpisode(self._cookie, {'timestamp': timestamp}, [self._CreatePhotoDict(self._cookie)]) (new_vp_id, new_ep_ids) = self._tester.ShareNew(self._cookie, [(ep_id, ph_ids)], [self._user2.user_id]) self._tester.U...
'Unshare photos from multiple episodes inside the same viewpoint.'
def testMultipleEpisodeUnshare(self):
(vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(self._new_ep_id, self._photo_ids)], [self._user2.user_id]) timestamp = time.time() episode_id = Episode.ConstructEpisodeId(timestamp, self._device_ids[0], 100) (ep_id, ph_ids) = self._tester.UploadEpisode(self._cookie, {}, [self._CreatePhotoDict(se...
'Unshare photos from default viewpoint.'
def testDefaultViewpointUnshare(self):
self._tester.SavePhotos(self._cookie2, [(self._new_ep_id, self._photo_ids)]) self._tester.Unshare(self._cookie, self._new_vp_id, [(self._new_ep_id, self._photo_ids)])
'Unshare photos which have been removed from default viewpoint.'
def testUnshareRemoved(self):
ep_ids = self._tester.SavePhotos(self._cookie2, [(self._new_ep_id, self._photo_ids)]) self._tester.RemovePhotos(self._cookie2, [(ep_ids[0], self._photo_ids[:1])]) self._tester.Unshare(self._cookie, self._new_vp_id, [(self._new_ep_id, self._photo_ids)])
'Force op failure in order to test idempotency.'
@mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True) def testIdempotency(self):
(new_vp_id2, new_ep_ids2) = self._tester.ShareNew(self._cookie2, [(self._new_ep_id, self._photo_ids)], [self._user3.user_id]) self._tester.RemoveViewpoint(self._cookie2, self._new_vp_id) self._tester.Unshare(self._cookie, self._new_vp_id, [(self._new_ep_id, self._photo_ids[:1]), (self._new_ep_id, self._phot...
'Valid receipts get added to the user\'s subscriptions.'
def testValidReceipt(self):
self.mock_http.map('.*', itunes_store_test.MakeNewResponse()) response = self._RecordSubscription(self._cookie, itunes_store_test.kReceiptData) self._CheckSubscriptionMetadata(response['subscription']) subs = self._GetSubscriptions() self.assertEqual(1, len(subs)) self.assertEqual(subs[0].transa...
'Receipts with expiration in the future are returned without include_history=True.'
def testFreshReceipt(self):
self._validate = False self.mock_http.map('.*', itunes_store_test.MakeFreshResponse()) response = self._RecordSubscription(self._cookie, itunes_store_test.kReceiptData) self._CheckSubscriptionMetadata(response['subscription']) subs = self._GetSubscriptions(include_history=False) self.assertEqual...
'Repeated upload of the same receipt succeeds but doesn\'t create duplicate records.'
def testDuplicateReceipt(self):
self.mock_http.map('.*', itunes_store_test.MakeNewResponse()) response = self._RecordSubscription(self._cookie, itunes_store_test.kReceiptData) self._CheckSubscriptionMetadata(response['subscription']) response = self._RecordSubscription(self._cookie, itunes_store_test.kReceiptData) self._CheckSubsc...
'Different receipts create new records.'
def testMultipleReceipts(self):
self.mock_http.map('.*', itunes_store_test.MakeNewResponse()) response = self._RecordSubscription(self._cookie, 'receipt1') self._CheckSubscriptionMetadata(response['subscription']) self.mock_http.map('.*', itunes_store_test.MakeRenewedResponse()) response = self._RecordSubscription(self._cookie, 'r...
'ERROR: an invalid signature fails cleanly with a 400 status code, indicating the retrying is futile.'
def testInvalidReceipt(self):
self.mock_http.map('.*', itunes_store_test.MakeBadSignatureResponse()) self.assertRaisesHttpError(400, self._RecordSubscription, self._cookie, itunes_store_test.kReceiptData) self.assertEqual([], self._GetSubscriptions())
'ERROR: server errors fail with a 500 status code, indicating that the request should be retried in the future.'
def testServerError(self):
self.mock_http.map('.*', itunes_store_test.MakeServerErrorResponse()) self.assertRaisesHttpError(500, self._RecordSubscription, self._cookie, itunes_store_test.kReceiptData) self.assertEqual([], self._GetSubscriptions())
'Receipts from the itunes sandbox are validated, but not recorded.'
def testSandboxReceipt(self):
self.mock_http.map(ITunesStoreClient._SETTINGS['prod']['verify_url'], itunes_store_test.MakeSandboxOnProdResponse()) self.mock_http.map(ITunesStoreClient._SETTINGS['dev']['verify_url'], itunes_store_test.MakeNewResponse()) response = self._RecordSubscription(self._cookie, itunes_store_test.kReceiptData) ...
'Remove photos from user\'s default viewpoint.'
def testRemovePhotos(self):
(ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 9) self._tester.RemovePhotos(self._cookie, [(ep_id, ph_ids[::2])]) self.assertEqual(self._CountRemovedPhotos(self._cookie), 5)
'Remove photos from multiple episodes.'
def testRemoveMultipleEpisodes(self):
ep_ph_ids_list = self._UploadMultipleEpisodes(self._cookie, 17) self._tester.RemovePhotos(self._cookie, ep_ph_ids_list[::2]) self.assertEqual(self._CountRemovedPhotos(self._cookie), 12)
'Remove the same photos multiple times.'
def testRemoveDuplicatePhotos(self):
(ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 3) self._tester.RemovePhotos(self._cookie, [(ep_id, ph_ids)]) self._tester.RemovePhotos(self._cookie, [(ep_id, ph_ids)]) self._tester.RemovePhotos(self._cookie, [(ep_id, ph_ids)]) self.assertEqual(self._CountRemovedPhotos(self._cookie), 3)
'Remove photos from the same episode in different patterns.'
def testRemoveOverlappingPhotos(self):
(ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 5) self._tester.RemovePhotos(self._cookie, [(ep_id, ph_ids[3:4])]) self._tester.RemovePhotos(self._cookie, [(ep_id, ph_ids[2:4])]) self._tester.RemovePhotos(self._cookie, [(ep_id, ph_ids[4:])]) self.assertEqual(self._CountRemovedPhotos(self._coo...
'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.RemovePhotos(self._cookie, [(ep_id, ph_ids[:1])]) self._tester.RemovePhotos(self._cookie, [(ep_id, ph_ids)]) self.assertEqual(self._CountRemovedPhotos(self._cookie), 2)
'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._tester.RemovePhotos, 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._tester.RemovePhotos, 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._tester.RemovePhotos, 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.RemovePh...
'ERROR: Try to remove from a shared viewpoint.'
def testRemoveFromSharedViewpoint(self):
(ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 3) (vp_id, new_ep_ids) = self._tester.ShareNew(self._cookie, [(ep_id, ph_ids)], [self._user2.user_id]) self.assertRaisesHttpError(403, self._tester.RemovePhotos, self._cookie, [(new_ep_ids[0], ph_ids)])
'Returns count of all removed photos in the user\'s default viewpoint.'
def _CountRemovedPhotos(self, user_cookie):
(user_id, device_id) = self._tester.GetIdsFromCookie(user_cookie) user = self._RunAsync(User.Query, self._client, user_id, None) vp_select = self._tester.CreateViewpointSelection(user.private_vp_id) vp_response_dict = self._tester.QueryViewpoints(user_cookie, [vp_select]) count = 0 for ep_dict i...
'Update a user profile attribute and an account setting.'
def testUpdateUser(self):
self._tester.UpdateUser(self._cookie, name='fake.name', given_name='fake.name', settings_dict={'email_alerts': 'on_share_new'}) response_dict = self._tester.QueryUsers(self._cookie, [self._user.user_id]) self.assertEqual(response_dict['users'][0]['name'], 'fake.name') self.assertEqual(response_dict['use...
'Call update_user, then call again with different values.'
def testSerialUpdateUser(self):
self._tester.UpdateUser(self._cookie, name='fake.name', given_name='fake.name', settings_dict={'sms_alerts': 'on_share_new'}) self._tester.UpdateUser(self._cookie, name='Andrew Kimball', given_name='Andrew', family_name='Kimball', settings_dict={'sms_alerts': 'none'}) response_dict = self._tester.QueryUs...
'Update only user profile attributes.'
def testUpdateProfile(self):
self._tester.UpdateUser(self._cookie, name='Andy Kimball', given_name='Andy', family_name='Kimball', picture='http://about.me/andrewkimball') response_dict = self._tester.QueryUsers(self._cookie, [self._user.user_id]) self.assertEqual(response_dict['users'][0]['name'], 'Andy Kimball')
'Update only account settings.'
def testUpdateSettings(self):
settings_dict = {'email_alerts': 'on_share_new', 'sms_alerts': 'on_share_new', 'push_alerts': 'all', 'storage_options': ['use_cloud', 'store_originals']} self._tester.UpdateUser(self._cookie, settings_dict=settings_dict) response_dict = self._tester.QueryUsers(self._cookie, [self._user.user_id]) self.as...
'Update a user with friends.'
def testUpdateWithFriends(self):
self._skip_validation_for = ['Alerts'] (ep_id, ph_ids) = self._UploadOneEpisode(self._cookie, 2) (vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(ep_id, ph_ids)], []) self._tester.AddFollowers(self._cookie, vp_id, [self._user2.user_id, self._user3.user_id, 'Local:identity1']) self._tester.Upd...
'Update no profile attributes or settings.'
def testUpdateNothing(self):
self._tester.UpdateUser(self._cookie)
'Update all settings.'
def testUpdateAllSettings(self):
self._tester.UpdateUser(self._cookie, settings_dict={'email_alerts': 'on_share_new'}) self._tester.UpdateUser(self._cookie, settings_dict={'email_alerts': 'none'}) self._tester.UpdateUser(self._cookie, settings_dict={'sms_alerts': 'on_share_new'}) self._tester.UpdateUser(self._cookie, settings_dict={'sm...
'Send empty settings dict.'
def testUpdateEmptySettings(self):
self._tester.UpdateUser(self._cookie, settings_dict={})
'Update various combinations of names and make sure names are updated in concert.'
def testUpdateNames(self):
self._tester.UpdateUser(self._cookie, name='Andy Kimball', given_name='Andy', family_name='Kimball') response_dict = self._tester.QueryUsers(self._cookie, [self._user.user_id]) self.assertEqual(response_dict['users'][0]['name'], 'Andy Kimball') self._tester.UpdateUser(self._cookie, name='Andy', gi...
'Test notifications sent to other users in one-sided "friendship".'
def testOneSidedFriendship(self):
self._tester.UpdateFriend(self._cookie, user_id=self._user2.user_id, nickname='The Dude') self._tester.UpdateUser(self._cookie, name='Andy Kimball', given_name='Andy') response = self._tester.QueryNotifications(self._cookie2, limit=1, scan_forward=False) self.assertEqual(response['notifications'][...
'Turn on/off alerts for a user and trigger operations which send alerts.'
def testAlerts(self):
self._skip_validation_for = ['Alerts'] emails = TestEmailManager.Instance().emails phone_numbers = TestSMSManager.Instance().phone_numbers self._CreateSimpleTestAssets() self._tester.UpdateUser(self._cookie2, settings_dict={'email_alerts': 'on_share_new', 'sms_alerts': 'on_share_new'}) (vp_id, e...
'ERROR: Try to update invalid subset of user names.'
def testMissingNameParts(self):
self.assertRaisesHttpError(400, self._tester.UpdateUser, self._cookie, given_name='Andy') self.assertRaisesHttpError(400, self._tester.UpdateUser, self._cookie, family_name='Kimball') self.assertRaisesHttpError(400, self._tester.UpdateUser, self._cookie, name='Andy Kimball')
'ERROR: Test invalid account settings.'
def testInvalidSettings(self):
settings_dict = {'unknown': 'unknown'} self.assertRaisesHttpError(400, self._tester.UpdateUser, self._cookie, settings_dict=settings_dict) settings_dict = {'email_alerts': 'unknown'} self.assertRaisesHttpError(400, self._tester.UpdateUser, self._cookie, settings_dict=settings_dict) settings_dict = {...
'ERROR: Test invalid requests.'
def testInvalidRequests(self):
request_dict = {'account_settings': 'unknown'} self.assertRaisesHttpError(400, self._tester.SendRequest, 'update_user', self._cookie, request_dict) request_dict = {'unknown': 'unknown'} self.assertRaisesHttpError(400, self._tester.SendRequest, 'update_user', self._cookie, request_dict) request_dict ...
'Test update of user password.'
def testUpdatePassword(self):
confirmed_cookie = self._GetSecureUserCookie(self._user, self._device_ids[0], confirm_time=util._TEST_TIME) self.assertIsNone(self._RunAsync(User.Query, self._client, self._user.user_id, None).pwd_hash) self._tester.UpdateUser(confirmed_cookie, password='supersecure', name='Jimmy John', given_name='user1...
'Verifies that the invitation grants access to user photos with and without various existing cookies.'
def testWithCookies(self):
response = self._SendRequest(self._invitation_url) user_cookie = self._VerifyInvitationResponse(response, self._new_vp_id) response = self._SendRequest(self._invitation_url, user_cookie) user_cookie = self._VerifyInvitationResponse(response, self._new_vp_id) invitation_url = self._CreateInvitationUR...
'Tests that prospective user can make a service API call.'
def testServiceInvitation(self):
response = self._SendRequest(self._invitation_url) user_cookie = self._VerifyInvitationResponse(response, self._new_vp_id) ep_select = self._tester.CreateEpisodeSelection(self._new_ep_id) self._tester.QueryEpisodes(user_cookie, [ep_select])
'Verify that an already registered user is redirected to /auth.'
def testRegisteredUser(self):
def _VerifyAuthRedirectResponse(response): 'Verifies the HTTPResponse has a status code of 302, a location\n header that starts with /auth, and no cookie.\n ' self.assertEqual(response.code, 302) ...
'Test that prospective user auth handler will redirect to "next" query parameter.'
def testRedirectNext(self):
response = self._SendRequest((self._invitation_url + '?next=/foobar'), self._cookie) self.assertEqual(response.code, 302) self.assertEqual(response.headers['location'], '/foobar') response = self._SendRequest((self._invitation_url + '?next=//foobar'), self._cookie) self.assertEqual(response.code, 40...
'Test that a photo redirection returns the signed S3 URL and does *not* set the cookie.'
def testRedirectPhoto(self):
next_url = ('?next=/episodes/%s/photos/%s.f' % (self._new_ep_id, self._photo_ids[0])) response = self._SendRequest((self._invitation_url + next_url)) self.assertEqual(response.code, 302) self.assertIn(('/fileobjstore/photo/%s.f' % self._photo_ids[0]), response.headers['location']) self.assertIsNone(...
'Test that first click of an invitation is a confirmed cookie, second is not.'
def testFirstClick(self):
response = self._SendRequest(self._invitation_url) prospective_user_cookie = self._VerifyInvitationResponse(response, self._new_vp_id) cookie_dict = self._tester.DecodeUserCookie(prospective_user_cookie) self.assertEqual(cookie_dict['confirm_time'], util._TEST_TIME) response = self._SendRequest(self...
'Test invitation that uses the short domain.'
def testShortDomain(self):
phone_key = 'Phone:+14251234567' (vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids)], [phone_key]) prospective_identity = self._RunAsync(Identity.Query, self._client, phone_key, None) prospective_user = self._RunAsync(User.Query, self._client, prospective_identity...
'Test that server stops sending SMS messages if the user is not clicking links.'
def testSMSLimit(self):
self._skip_validation_for = ['Alerts'] phone = '+14257349284' for i in xrange(5): self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids)], [('Phone:' + phone)]) sms_list = TestSMSManager.Instance().phone_numbers[phone] self.assertEqual(len(sms_list), 4) self.assertTrue(...
'ERROR: Identity has been unlinked since invitation was issued.'
def testUnlinkedIdentity(self):
user_dict = {'user_id': self._new_user.user_id, 'email': 'prospective@emailscrubbed.com', 'name': 'Matt Tracy', 'given_name': 'Matt'} (user, device_id) = self._tester.RegisterFakeViewfinderUser(user_dict, None) user_cookie = self._GetSecureUserCookie(user, device_id) user_dict = {'id': 100} self....
'ERROR: Try to use expired invitation.'
def testExpiredInvitation(self):
util._TEST_TIME += (constants.SECONDS_PER_DAY * 30) response = self._SendRequest(self._invitation_url) self.assertEqual(response.code, 403) self.assertIn('>The requested link has expired and can no longer be used.<', response.body)
'Test getting the primary identity from a prospective user.'
def testGetPrimaryIdentity(self):
identity = self._RunAsync(self._new_user.QueryPrimaryIdentity, self._client) self.assertEqual(identity.key, 'Email:prospective@emailscrubbed.com')
'Create an invitation URL for the prospective user created in setUp, giving him access to the given viewpoint, and redirecting to "default_url" after authentication.'
def _CreateInvitationURL(self, viewpoint_id, default_url):
short_url = self._RunAsync(Identity.CreateInvitationURL, self._client, self._new_user.user_id, 'Email:prospective@emailscrubbed.com', viewpoint_id, default_url) return self._tester.GetUrl(('/%s%s' % (short_url.group_id, short_url.random_key)))
'Sends HTTP request to the service URL and returns the response.'
def _SendRequest(self, url, user_cookie=None):
return self._RunAsync(self.http_client.fetch, url, method='GET', headers=({'Cookie': ('user=%s' % user_cookie)} if (user_cookie is not None) else None), follow_redirects=False)
'Verifies the HTTPResponse returned from an invitation request. The response should have a status code of 200 and contain a cookie that grants access to the specified viewpoint, but not to any other viewpoint. Returns the cookie.'
def _VerifyInvitationResponse(self, response, viewpoint_id):
self.assertEqual(response.code, 302) self.assertEqual(response.headers['Location'], '/view') cookie = self._tester.GetCookieFromResponse(response) cookie_dict = self._tester.DecodeUserCookie(cookie) self.assertEqual(cookie_dict['viewpoint_id'], viewpoint_id) self.assertNotIn('expires', response....
'Send request on behalf of staging user from mobile client to staging server and expect success (not redirection).'
def testRedirectStagingUserMobileClientFromStagingServer(self):
self._SendRequest('get_calendar', self._staging_cookie, {'calendars': [{'calendar_id': 'EnglishHolidays.ics', 'year': 2012}]})
'Send request on behalf of staging user from web app to staging server and expect success (no redirection).'
def testRedirectStagingUserWebClientFromStagingServer(self):
self._SendRequest('get_calendar', self._staging_webapp_cookie, {'calendars': [{'calendar_id': 'EnglishHolidays.ics', 'year': 2012}]})
'Send request on behalf of production user from web app to staging server and expect redirection to production.'
def testRedirectProductionUserWebClientFromStagingServer(self):
exc = self.assertRaisesHttpError(301, self._SendRequest, 'get_calendar', self._cookie, {'calendars': [{'calendar_id': 'EnglishHolidays.ics', 'year': 2012}]}) self.assertEqual(exc.response.headers['Location'], 'http://www.goviewfinder.com/service/get_calendar') self.assertEqual(exc.response.headers['X-VF-Sta...
'Send request on behalf of staging user from mobile client to staging server and expect success (not redirection).'
def testRedirectStagingUserMobileClientFromStagingUrl(self):
self._SendRequest('get_calendar', self._staging_cookie, {'calendars': [{'calendar_id': 'EnglishHolidays.ics', 'year': 2012}]})
'Send request on behalf of staging user from web app to staging server and expect success (no redirection).'
def testRedirectStagingUserWebClientFromStagingUrl(self):
self._SendRequest('get_calendar', self._staging_webapp_cookie, {'calendars': [{'calendar_id': 'EnglishHolidays.ics', 'year': 2012}]})
'Send request on behalf of production user from web app to staging server and expect redirection to production.'
def testRedirectProductionUserWebClientFromStagingUrl(self):
exc = self.assertRaisesHttpError(301, self._SendRequest, 'get_calendar', self._cookie, {'calendars': [{'calendar_id': 'EnglishHolidays.ics', 'year': 2012}]}) self.assertEqual(exc.response.headers['Location'], 'http://www.goviewfinder.com/service/get_calendar') self.assertEqual(exc.response.headers['X-VF-Sta...
'Send request on behalf of staging user mobile client to production server and expect redirection.'
def testRedirectStagingMobileClientFromProduction(self):
exc = self.assertRaisesHttpError(301, self._SendRequest, 'get_calendar', self._staging_cookie, {'calendars': [{'calendar_id': 'EnglishHolidays.ics', 'year': 2012}]}) self.assertEqual(exc.response.headers['Location'], 'http://staging.goviewfinder.com/service/get_calendar') self.assertEqual(exc.response.heade...
'Send request on behalf of staging user from web app to production server and expect success (no redirection).'
def testRedirectStagingWebClientFromProduction(self):
self._SendRequest('get_calendar', self._staging_webapp_cookie, {'calendars': [{'calendar_id': 'EnglishHolidays.ics', 'year': 2012}]})
'Test valid short URL generation and redemption via GET request.'
def testShortURLGet(self):
response = self._RunAsync(self.http_client.fetch, self._url, method='GET') self.assertEqual(response.code, 200) self.assertEqual(json.loads(response.body), {'method': 'GET', 'group_id': 'test/abcd', 'random_key': self._short_url.random_key, 'timestamp': util._TEST_TIME, 'expires': (util._TEST_TIME + constan...
'Test valid short URL generation and redemption via POST requeset.'
def testShortURLPost(self):
response = self._RunAsync(self.http_client.fetch, self._url, method='POST', headers={'Cookie': '_xsrf="fake_xsrf";', 'X-Xsrftoken': 'fake_xsrf'}, body='{}') self.assertEqual(response.code, 200) self.assertEqual(json.loads(response.body), {'method': 'POST', 'group_id': 'test/abcd', 'random_key': self._short_...
'Test enforcement of max guesses for a particular group id.'
@mock.patch.object(TestShortURLBaseHandler, '_MAX_GUESSES', 1) def testMaxGuesses(self):
url = self.get_url('/test/abcd12345678') response = self._RunAsync(self.http_client.fetch, url, method='GET') self.assertEqual(response.code, 404) response = self._RunAsync(self.http_client.fetch, url, method='GET') self.assertEqual(response.code, 403) response = self._RunAsync(self.http_client....
'Test forced expiration of a ShortURL.'
def testExpire(self):
self._RunAsync(self._short_url.Expire, self._client) response = self._RunAsync(self.http_client.fetch, self._url, method='GET') self.assertEqual(response.code, 403)