desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Return detection of a Brew device
Detects whether the device is a Brew-powered device.'
| def detectBrewDevice(self):
| return (UAgentInfo.deviceBrew in self.__userAgent)
|
'Return detection of a Danger Hiptop
Detects the Danger Hiptop device.'
| def detectDangerHiptop(self):
| return ((UAgentInfo.deviceDanger in self.__userAgent) or (UAgentInfo.deviceHiptop in self.__userAgent))
|
'Return detection of an Opera browser for a mobile device
Detects Opera Mobile or Opera Mini.'
| def detectOperaMobile(self):
| return ((UAgentInfo.engineOpera in self.__userAgent) and ((UAgentInfo.mini in self.__userAgent) or (UAgentInfo.mobi in self.__userAgent)))
|
'Return detection of an Opera browser on an Android phone
Detects Opera Mobile on an Android phone.'
| def detectOperaAndroidPhone(self):
| return ((UAgentInfo.engineOpera in self.__userAgent) and (UAgentInfo.deviceAndroid in self.__userAgent) and (UAgentInfo.mobi in self.__userAgent))
|
'Return detection of an Opera browser on an Android tablet
Detects Opera Mobile on an Android tablet.'
| def detectOperaAndroidTablet(self):
| return ((UAgentInfo.engineOpera in self.__userAgent) and (UAgentInfo.deviceAndroid in self.__userAgent) and (UAgentInfo.deviceTablet in self.__userAgent))
|
'Return detection of a WAP- or WML-capable device
Detects whether the device supports WAP or WML.'
| def detectWapWml(self):
| return ((UAgentInfo.vndwap in self.__httpAccept) or (UAgentInfo.wml in self.__httpAccept))
|
'Return detection of a Kindle
Detects if the current device is an Amazon Kindle (eInk devices only).
Note: For the Kindle Fire, use the normal Android methods.'
| def detectKindle(self):
| return ((UAgentInfo.deviceKindle in self.__userAgent) and (not self.detectAndroid()))
|
'Return detection of an Amazon Kindle Fire in Silk mode.
Detects if the current Amazon device is using the Silk Browser.
Note: Typically used by the the Kindle Fire.'
| def detectAmazonSilk(self):
| return (UAgentInfo.engineSilk in self.__userAgent)
|
'Return detection of any mobile device using the quicker method
Detects if the current device is a mobile device.
This method catches most of the popular modern devices.
Excludes Apple iPads and other modern tablets.'
| def detectMobileQuick(self):
| if self.__isTierTablet:
return False
if self.detectSmartphone():
return True
if (self.detectWapWml() or self.detectBrewDevice() or self.detectOperaMobile()):
return True
if ((UAgentInfo.engineNetfront in self.__userAgent) or (UAgentInfo.engineUpBrowser in self.__userAgent) or (UA... |
'Return detection of Sony Playstation
Detects if the current device is a Sony Playstation.'
| def detectSonyPlaystation(self):
| return (UAgentInfo.devicePlaystation in self.__userAgent)
|
'Return detection of Nintendo
Detects if the current device is a Nintendo game device.'
| def detectNintendo(self):
| return ((UAgentInfo.deviceNintendo in self.__userAgent) or (UAgentInfo.deviceNintendo in self.__userAgent) or (UAgentInfo.deviceNintendo in self.__userAgent))
|
'Return detection of Xbox
Detects if the current device is a Microsoft Xbox.'
| def detectXbox(self):
| return (UAgentInfo.deviceXbox in self.__userAgent)
|
'Return detection of any Game Console
Detects if the current device is an Internet-capable game console.'
| def detectGameConsole(self):
| return (self.detectSonyPlaystation() or self.detectNintendo() or self.detectXbox())
|
'Return detection of a MIDP mobile Java-capable device
Detects if the current device supports MIDP, a mobile Java technology.'
| def detectMidpCapable(self):
| return ((UAgentInfo.deviceMidp in self.__userAgent) or (UAgentInfo.deviceMidp in self.__httpAccept))
|
'Return detection of a Maemo OS tablet
Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.'
| def detectMaemoTablet(self):
| if (UAgentInfo.maemo in self.__userAgent):
return True
return ((UAgentInfo.linux in self.__userAgent) and (UAgentInfo.deviceTablet in self.__userAgent) and (not self.detectWebOSTablet()) and (not self.detectAndroid()))
|
'Return detection of an Archos media player
Detects if the current device is an Archos media player/Internet tablet.'
| def detectArchos(self):
| return (UAgentInfo.deviceArchos in self.__userAgent)
|
'Return detection of a Sony Mylo device
Detects if the current browser is a Sony Mylo device.'
| def detectSonyMylo(self):
| return ((UAgentInfo.manuSony in self.__userAgent) and ((UAgentInfo.qtembedded in self.__userAgent) or (UAgentInfo.mylocom2 in self.__userAgent)))
|
'Return detection of any mobile device using the more thorough method
The longer and more thorough way to detect for a mobile device.
Will probably detect most feature phones,
smartphone-class devices, Internet Tablets,
Internet-enabled game consoles, etc.
This ought to catch a lot of the more obscure and older devices... | def detectMobileLong(self):
| if (self.detectMobileQuick() or self.detectGameConsole() or self.detectSonyMylo()):
return True
return ((UAgentInfo.uplink in self.__userAgent) or (UAgentInfo.manuSonyEricsson in self.__userAgent) or (UAgentInfo.manuericsson in self.__userAgent) or (UAgentInfo.manuSamsung1 in self.__userAgent) or (UAgen... |
'Return detection of any device in the Tablet Tier
The quick way to detect for a tier of devices.
This method detects for the new generation of
HTML 5 capable, larger screen tablets.
Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.'
| def detectTierTablet(self):
| return (self.detectIpad() or self.detectAndroidTablet() or self.detectBlackBerryTablet() or self.detectWebOSTablet())
|
'Return detection of any device in the iPhone/Android/WP7/WebOS Tier
The quick way to detect for a tier of devices.
This method detects for devices which can
display iPhone-optimized web content.
Includes iPhone, iPod Touch, Android, Windows Phone 7, Palm WebOS, etc.'
| def detectTierIphone(self):
| return (self.__isIphone or self.__isAndroidPhone or (self.detectBlackBerryWebKit() and self.detectBlackBerryTouch()) or self.detectWindowsPhone7() or self.detectPalmWebOS() or self.detectGarminNuvifone())
|
'Return detection of any device in the \'Rich CSS\' Tier
The quick way to detect for a tier of devices.
This method detects for devices which are likely to be capable
of viewing CSS content optimized for the iPhone,
but may not necessarily support JavaScript.
Excludes all iPhone Tier devices.'
| def detectTierRichCss(self):
| if (not self.detectMobileQuick()):
return False
if (self.detectTierIphone() or self.detectKindle()):
return False
return (self.detectWebkit() or self.detectS60OssBrowser() or self.detectBlackBerryHigh() or self.detectWindowsMobile() or (UAgentInfo.engineTelecaQ in self.__userAgent))
|
'Return detection of a mobile device in the less capable tier
The quick way to detect for a tier of devices.
This method detects for all other types of phones,
but excludes the iPhone and RichCSS Tier devices.'
| def detectTierOtherPhones(self):
| return (self.detectMobileLong() and (not self.detectTierIphone()) and (not self.detectTierRichCss()))
|
'GET is used when authenticating via the web application.'
| @handler.asynchronous(datastore=True)
@gen.engine
def get(self, action):
| self._StartInteractiveRequest(action)
if self.get_argument('code', False):
user_dict = (yield gen.Task(self.get_authenticated_user, redirect_uri=('https://%s/%s/facebook' % (self.request.host, action)), client_id=self.settings['facebook_api_key'], client_secret=self.settings['facebook_secret'], extra_fi... |
'POST is used when authenticating via the mobile application. The device info is in the
JSON-encoded request body. A device id will be allocated and returned with the response.'
| @handler.asynchronous(datastore=True)
@gen.engine
def post(self, action):
| (yield gen.Task(self._StartJSONRequest, action, self.request, json_schema.AUTH_FB_GOOGLE_REQUEST))
device_dict = self._request_message.dict.get('device', None)
access_token = self.get_argument('access_token')
user_dict = (yield gen.Task(self.facebook_request, path='/me', access_token=access_token, field... |
'Converts user_dict returned by Facebook to Viewfinder format and forwards to base class
_OnAuthenticate.'
| def _PrepareUserInfo(self, device_dict, user_dict):
| for (key, value) in user_dict.items():
if (value is None):
del user_dict[key]
if ('picture' in user_dict):
user_dict['picture'] = user_dict['picture']['data']['url']
ident_dict = {'key': ('FacebookGraph:%s' % user_dict['id']), 'authority': 'Facebook', 'access_token': user_dict.po... |
'Overrides the get_http_client() method use in the facebook Auth mixin.'
| def get_http_client(self):
| return httpclient.AsyncHTTPClient()
|
'Handle GET requests to a ShortURL. Recover the group id and random key components and
use them to redeem the ShortURL if it exists and is not expired. Fetch the named parameters
that were associated with the ShortURL and pass them to the _HandleGet method.'
| @handler.asynchronous(datastore=True, obj_store=True)
@gen.engine
def get(self, url_path):
| short_url = (yield self._CheckShortURL(url_path))
self._HandleGet(short_url, **short_url.json)
|
'Handle POST requests to a ShortURL. Recover the group id and random key components and
use them to redeem the ShortURL if it exists and is not expired. Fetch the named parameters
that were associated with the ShortURL and pass them to the _HandlePost method.'
| @handler.asynchronous(datastore=True, obj_store=True)
@gen.engine
def post(self, url_path):
| short_url = (yield self._CheckShortURL(url_path))
self._HandlePost(short_url, **short_url.json)
|
'Extract the ShortURL components from the URL path and check that the ShortURL exists
and is valid.'
| @gen.coroutine
def _CheckShortURL(self, url_path):
| group_id = url_path[:(- ShortURL.KEY_LEN_IN_BASE64)]
random_key = url_path[(- ShortURL.KEY_LEN_IN_BASE64):]
if ((len(group_id) == 0) or (len(random_key) != ShortURL.KEY_LEN_IN_BASE64)):
raise web.HTTPError(400, 'The URL path is not valid.')
guess_id = Guess.ConstructGuessId('url',... |
'Any derived class should override this method in order to handle HTTP GET requests
to the ShortURL. This method is called with the redeemed ShortURL db object. In addition,
any named parameters passed to ShortURL.Create are passed to the derived _HandleGet.'
| def _HandleGet(self, short_url):
| raise web.HTTPError(405)
|
'Any derived class should override this method in order to handle HTTP POST requests
to the ShortURL. This method is called with the redeemed ShortURL db object. In addition,
any named parameters passed to ShortURL.Create are passed to the derived _HandlePost.'
| def _HandlePost(self, short_url):
| raise web.HTTPError(405)
|
'Save a single photo to the default viewpoint.'
| def testSave(self):
| self._tester.SavePhotos(self._cookie, [(self._existing_ep_id, self._photo_ids[:1])])
|
'Save two photos to the default viewpoint.'
| def testSaveMultiple(self):
| self._tester.SavePhotos(self._cookie, [(self._existing_ep_id, self._photo_ids)])
|
'Save photos from default viewpoint to default viewpoint.'
| def testSaveToSelf(self):
| self._tester.SavePhotos(self._cookie, [(self._episode_id, self._photo_ids)])
|
'Save empty episode list.'
| def testSaveNoEpisodes(self):
| self._tester.SavePhotos(self._cookie, [])
|
'Save photos from multiple episodes.'
| def testSaveMultipleEpisodes(self):
| (vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(self._episode_id2, self._photo_ids2)], [self._user3.user_id], **self._CreateViewpointDict(self._cookie))
self._tester.SavePhotos(self._cookie, [(self._existing_ep_id, self._photo_ids), (ep_ids[0], self._photo_ids2)])
|
'Save same photos from same source episode to same target episode.'
| def testSaveDuplicatePhotos(self):
| self._tester.SavePhotos(self._cookie, [(self._existing_ep_id, self._photo_ids)])
self._tester.SavePhotos(self._cookie, [(self._existing_ep_id, self._photo_ids[:1])])
self._tester.SavePhotos(self._cookie, [(self._existing_ep_id, self._photo_ids[1:])])
|
'Save different photos from same source episode to same target episode.'
| def testSaveSameEpisode(self):
| self._tester.SavePhotos(self._cookie, [(self._existing_ep_id, self._photo_ids[:1])])
self._tester.SavePhotos(self._cookie, [(self._existing_ep_id, self._photo_ids[1:])])
|
'Save episode created by a different user.'
| def testSaveDifferentUser(self):
| self._tester.SavePhotos(self._cookie2, [(self._existing_ep_id, self._photo_ids)])
|
'Save same photos from same source episode to same target episode in default viewpoint.'
| def testSaveDuplicatePhotos(self):
| new_episode_id = Episode.ConstructEpisodeId(time.time(), self._device_ids[0], self._test_id)
self._test_id += 1
share_list = [{'existing_episode_id': self._existing_ep_id, 'new_episode_id': new_episode_id, 'photo_ids': self._photo_ids}]
self._tester.SavePhotos(self._cookie, share_list)
self._tester.... |
'Save multiple photos to same target episode in default viewpoint.'
| def testSaveToSameEpisode(self):
| timestamp = time.time()
new_episode_id = Episode.ConstructEpisodeId(timestamp, self._device_ids[0], self._test_id)
self._test_id += 1
share_dict1 = {'existing_episode_id': self._existing_ep_id, 'new_episode_id': new_episode_id, 'photo_ids': self._photo_ids[:1]}
share_dict2 = {'existing_episode_id': ... |
'Save photos after having removed them.'
| def testSaveAfterRemove(self):
| ep_ids = self._tester.SavePhotos(self._cookie2, [(self._existing_ep_id, self._photo_ids)])
self._tester.RemovePhotos(self._cookie2, [(ep_ids[0], self._photo_ids[:1])])
post = self._RunAsync(Post.Query, self._client, ep_ids[0], self._photo_ids[0], None)
self.assertIn(Post.REMOVED, post.labels)
self._... |
'Save photos after having unshared them.'
| def testSaveAfterUnshare(self):
| ep_ids = self._tester.SavePhotos(self._cookie2, [(self._existing_ep_id, self._photo_ids)])
self._tester.Unshare(self._cookie2, self._user2.private_vp_id, [(ep_ids[0], self._photo_ids[:1])])
post = self._RunAsync(Post.Query, self._client, ep_ids[0], self._photo_ids[0], None)
self.assertIn(Post.UNSHARED, ... |
'Save all episodes from single viewpoint.'
| def testSaveOneViewpoint(self):
| self._tester.SavePhotos(self._cookie2, viewpoint_ids=['vunk'])
self.assertEqual(self._CountEpisodes(self._cookie2, self._user2.private_vp_id), 0)
self._tester.SavePhotos(self._cookie2, viewpoint_ids=[self._existing_vp_id])
self.assertEqual(self._CountEpisodes(self._cookie2, self._user2.private_vp_id), 1... |
'Save all episodes from multiple viewpoints.'
| def testSaveMultipleViewpoints(self):
| (vp_id, ep_ids) = self._tester.ShareNew(self._cookie, [(self._episode_id, self._photo_ids), (self._episode_id2, self._photo_ids2)], [self._user2.user_id, self._user3.user_id], **self._CreateViewpointDict(self._cookie))
self._tester.SavePhotos(self._cookie2, viewpoint_ids=[self._existing_vp_id, vp_id])
self.... |
'Save duplicate episode and photo ids.'
| def testSaveDuplicateIds(self):
| self._tester.SavePhotos(self._cookie, [(self._existing_ep_id, (self._photo_ids + self._photo_ids))])
self.assertEqual(self._CountEpisodes(self._cookie, self._user.private_vp_id), 3)
self._tester.SavePhotos(self._cookie, [(self._existing_ep_id, self._photo_ids), (self._existing_ep_id, self._photo_ids)])
... |
'ERROR: Try to save viewpoint with no permissions.'
| def testSaveViewpointNoPermission(self):
| self.assertRaisesHttpError(403, self._tester.SavePhotos, self._cookie3, viewpoint_ids=[self._existing_vp_id])
|
'ERROR: Try to save to the same episode from multiple parent episodes.'
| def testSaveFromMultipleParents(self):
| save_ep_ids = self._tester.SavePhotos(self._cookie, [(self._existing_ep_id, self._photo_ids)])
share_ep_ids = self._tester.ShareExisting(self._cookie, self._existing_vp_id, [(self._episode_id2, self._photo_ids2)])
share_dict = {'existing_episode_id': share_ep_ids[0], 'new_episode_id': save_ep_ids[0], 'photo... |
'Force op failure in order to test idempotency.'
| @mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True)
def testIdempotency(self):
| self._tester.SavePhotos(self._cookie, [(self._existing_ep_id, self._photo_ids[:1])])
self._tester.SavePhotos(self._cookie, [(self._existing_ep_id, self._photo_ids)])
|
'ERROR: Try to share episodes from viewpoint which user does not follow.'
| def testSaveNoAccess(self):
| self.assertRaisesHttpError(403, self._tester.SavePhotos, self._cookie3, [(self._existing_ep_id, self._photo_ids)])
|
'ERROR: Try to save a non-existing episode.'
| def testSaveInvalidEpisode(self):
| self.assertRaisesHttpError(400, self._tester.SavePhotos, self._cookie2, [('eunknown', self._photo_ids)])
|
'ERROR: Try to create an episode using a device id that is different
than the one in the user cookie.'
| def testWrongDeviceId(self):
| save_list = [self._tester.CreateCopyDict(self._cookie2, self._existing_ep_id, self._photo_ids)]
self.assertRaisesHttpError(403, self._tester.SavePhotos, self._cookie, save_list)
|
'ERROR: Try to save from two source episodes to the same target episode.'
| def testSaveToSameEpisode(self):
| share_ep_ids = self._tester.ShareExisting(self._cookie, self._existing_vp_id, [(self._episode_id2, self._photo_ids2)])
new_episode_id = Episode.ConstructEpisodeId(time.time(), self._device_ids[0], self._test_id)
self._test_id += 1
self.assertRaisesHttpError(400, self._tester.SavePhotos, self._cookie, [{... |
'Verify the requests per second and failures per second performance counters.'
| def testServiceCounters(self):
| self._CheckCounters(0, 0)
for i in range(5):
self._SendRequest('query_notifications', self._cookie, {})
self.assertRaisesHttpError(400, self._SendRequest, 'query_notifications', self._cookie, {'start_key': 2})
self._CheckCounters(10, 5)
self._CheckCounters(0, 0)
|
'Follow the redirect from /app to app store and verify google analytics logging.'
| def test_app_redirect(self):
| requests = []
def _LogRequest(request):
requests.append(request)
return HTTPResponse(request, 200, buffer=StringIO(''))
with mock.patch('tornado.httpclient.AsyncHTTPClient', MockAsyncHTTPClient()) as mock_client:
mock_client.map('.*', _LogRequest)
response = self.fetch('/app'... |
'Cleans up the temporary directory.'
| def tearDown(self):
| shutil.rmtree(self._temp_dir)
|
'Test scripts/fetch_logs.py.'
| @thread_test
def testFetchLogsScript(self):
| self._FetchLogs(self._users[0].user_id, start_timestamp=self._cur_t, end_timestamp=self._cur_t, exp_logs=self._user0_logs[2:])
|
'Verify time ranges with fetch_logs.'
| @thread_test
def testFetchLogsScriptTimeRange(self):
| self._FetchLogs(self._users[0].user_id, start_timestamp=self._t_minus_2d, end_timestamp=self._cur_t, exp_logs=self._user0_logs)
|
'Verify date ranges with fetch_logs.'
| @thread_test
def testFetchLogsScriptDateRange(self):
| options.options.use_utc = True
self._FetchLogs(self._users[0].user_id, start_date=FetchLogsTestCase._IsoDateTime(self._t_minus_1d, utc_time=True), end_date=FetchLogsTestCase._IsoDateTime(self._cur_t, utc_time=True), exp_logs=self._user0_logs[1:])
options.options.use_utc = False
self._FetchLogs(self._use... |
'Verify date ranges with fetch_logs.'
| @thread_test
def testFetchLogsScriptFilter(self):
| self._FetchLogs(self._users[0].user_id, start_timestamp=self._cur_t, end_timestamp=(self._cur_t + SECONDS_PER_DAY), filter='t.2', exp_logs=self._user0_logs[3:])
|
'Verify merged output from fetch of all logs for user 1.'
| @thread_test
def testFetchLogsScriptMerge(self):
| log_urls = self._FetchLogs(self._users[1].user_id, start_timestamp=self._t, end_timestamp=(self._t + SECONDS_PER_DAY), exp_logs=self._user1_logs)
output = StringIO()
options.options.merge_logs = True
fetch_logs.MergeLogs(log_urls, output)
self.assertEqual(self._merged, output.getvalue())
output.... |
'Gets the admin opener. Returns the opener and api_host.'
| def _GetAdminOpener(self):
| otp._ClearUserHistory()
api_host = ('www.goviewfinder.com:%d' % self.get_http_port())
tmp_file = tempfile.NamedTemporaryFile(delete=False)
opener = otp.GetAdminOpener(api_host, 'test-user', 'test-password', otp.GetOTP('test-user'), tmp_file.name)
return (api_host, opener)
|
'Calls the fetch_logs.FetchLogs method by setting command-line
options according to this method\'s parameters. Verifies the resulting
list of fetched urls and the contents of the locally saved log files.
Returns the resulting array of log urls from fetch_logs.FetchLogs().'
| def _FetchLogs(self, user_id, start_date=None, start_timestamp=None, end_date=None, end_timestamp=None, filter=None, exp_logs=[]):
| (api_host, opener) = self._GetAdminOpener()
options.options.user_id = user_id
options.options.start_date = None
options.options.start_timestamp = None
options.options.end_date = None
options.options.end_timestamp = None
options.options.filter = None
if (start_date is not None):
o... |
'Converts timestamp to ISO 8601 date/time value. If "utc_time" is true, return the UTC
date/time. Otherwise, return the local date/time.'
| @staticmethod
def _IsoDateTime(timestamp, utc_time=False):
| dt = (datetime.utcfromtimestamp(timestamp) if utc_time else datetime.fromtimestamp(timestamp))
return dt.strftime('%Y-%m-%d %H:%M:%S')
|
'Send a POST request without a header containing the xsrf token and expect failure.'
| def testXsrfFailureNoXsrfHeader(self):
| self._tester.http_client.fetch(self._tester.GetUrl('/service/get_calendar'), callback=(lambda r: self.stop(r)), method='POST', body=json.dumps({'calendars': [{'calendar_id': 'EnglishHolidays.ics', 'year': 2012}]}), headers={'Content-Type': 'application/json', 'Cookie': ('user=%s' % self._cookie)})
response = se... |
'Send a POST request with an xsrf token that doesn\'t match the token in the xsrf cookie and expect failure.'
| def testXsrfFailureBadXsrfHeader(self):
| xsrf_cookie = '_xsrf=a3675174a8f64c72a4a626aae658dbcd'
self._tester.http_client.fetch(self._tester.GetUrl('/service/get_calendar'), callback=(lambda r: self.stop(r)), method='POST', body=json.dumps({'calendars': [{'calendar_id': 'EnglishHolidays.ics', 'year': 2012}]}), headers={'Content-Type': 'application/json... |
'Send a POST request with an xsrf token that matches the on in the xsrf cookie and expect success.'
| def testXsrfSuccess(self):
| xsrf_cookie = '_xsrf=a3675174a8f64c72a4a626aae658dbcd'
self._tester.http_client.fetch(self._tester.GetUrl('/service/get_calendar'), callback=(lambda r: self.stop(r)), method='POST', body=json.dumps({'headers': {'version': message.MAX_SUPPORTED_MESSAGE_VERSION}, 'calendars': [{'calendar_id': 'EnglishHolidays.ics... |
'Send a POST request to our auth handler without an xsrf token and expect a 403 failure.'
| def testXsrfAuthFailure(self):
| self._tester.http_client.fetch(self._tester.GetUrl('/register/google'), callback=(lambda r: self.stop(r)), method='POST', body=json.dumps({'something': [{'invalid': 'stuff'}, {'other': 'stuff'}]}), headers={'Content-Type': 'application/json', 'Cookie': ('user=%s' % self._cookie)})
response = self.wait()
sel... |
'Send a POST request without an xsrf token and with xsrf disabled and expect no XSRF cookie in a successful
response.'
| def testXsrfSendAlways(self):
| self._tester.http_client.fetch(self._tester.GetUrl('/service/get_calendar'), callback=(lambda r: self.stop(r)), method='POST', body=json.dumps({'headers': {'version': message.MAX_SUPPORTED_MESSAGE_VERSION}, 'calendars': [{'calendar_id': 'EnglishHolidays.ics', 'year': 2012}]}), headers={'Content-Type': 'application/... |
'Test pings with very little info in the request. Since the ping handler does not go through
the standard service methods, validation is much more lenient.'
| def testNoInfoPing(self):
| req_dict = {}
response = self._RunAsync(self._tester.http_client.fetch, self._tester.GetUrl('/ping'), method='POST', headers={'Content-Type': 'application/json'}, body=json.dumps(req_dict))
self.assertEqual(response.code, 200)
req_dict = {'headers': {'synchronous': True}, 'device': {'country': 'US'}}
... |
'Test pings with gzip-encoded bodies.'
| def testGzip(self):
| req_dict = {}
response = self._RunAsync(self._tester.http_client.fetch, self._tester.GetUrl('/ping'), method='POST', headers={'Content-Type': 'application/json', 'Content-Encoding': 'gzip'}, body=GzipEncode(json.dumps(req_dict)))
self.assertEqual(response.code, 200)
|
'version known to trigger an INFO response message.'
| def testInfoPing(self):
| device_dict = {'version': '1.6.0.41.dev'}
resp = json.loads(self._SendPing(device_dict))
self.assertFalse(resp.has_key('message'))
device_dict = {'version': '1.6.0.40.dev'}
resp = json.loads(self._SendPing(device_dict))
self.assertFalse(resp.has_key('message'))
|
'We should keep this updated as app store and test flight versions are pushed to ensure that
we do not accidentally disable some.'
| def testAllReleasedVersions(self):
| testflight_versions = ['1.4.1.25.adhoc', '1.5.0.26.adhoc', '1.5.0.27.adhoc', '1.5.0.28.adhoc', '1.5.0.29.adhoc', '1.5.0.30.adhoc', '1.5.0.31.adhoc', '1.5.0.32.adhoc', '1.5.0.33.adhoc', '1.5.0.34.adhoc', '1.5.0.35.adhoc', '1.5.0.37.adhoc', '1.5.0.38.adhoc', '1.5.0.39.adhoc', '1.6.0.40.adhoc', '1.6.0.41.adhoc']
a... |
'Invoke the /ping handler.'
| def _SendPing(self, device_dict=None):
| req_dict = {'headers': {'version': message.MAX_SUPPORTED_MESSAGE_VERSION}}
req_dict['device'] = device_dict
response = self._RunAsync(self._tester.http_client.fetch, self._tester.GetUrl('/ping'), method='POST', headers={'Content-Type': 'application/json'}, body=json.dumps(req_dict))
return response.body... |
'Test successful upload_contacts.'
| def testUploadContacts(self):
| contacts = [{'identities': [{'identity': 'Email:mikep@non.com', 'description': 'work'}], 'contact_source': Contact.MANUAL, 'name': 'Mike Purtell', 'given_name': 'Mike', 'family_name': 'Purtell'}, {'identities': [{'identity': 'Phone:+13191231111', 'description': 'home'}, {'identity': 'Phone:+13191232222', 'descri... |
'Test interaction between user registration, contacts and notifications.'
| def testContactsWithRegisteredUsers(self):
| def _RegisterUser(name, given_name, email):
(user, _) = self._tester.RegisterFakeViewfinderUser({'name': name, 'given_name': given_name, 'email': email}, {})
return user
def _ValidateContactUpdate(expected_notification_name, expected_user_ids):
notification_list = self._tester._RunAsync(... |
'Force op failure in order to test idempotency.'
| @mock.patch.object(Operation, 'FAILPOINTS_ENABLED', True)
def testIdempotency(self):
| self._tester.UploadContacts(self._cookie, [{'identities': [{'identity': 'Email:mikep@non.com', 'description': 'work'}], 'contact_source': Contact.MANUAL, 'name': 'Mike Purtell', 'given_name': 'Mike', 'family_name': 'Purtell'}])
|
'ERROR: Test some failure cases.'
| def testUploadContactsFailures(self):
| good_contact = {'identities': [{'identity': 'Email:mikep@non.com', 'description': 'work'}], 'contact_source': Contact.MANUAL, 'name': 'Mike Purtell', 'given_name': 'Mike', 'family_name': 'Purtell'}
bad_contact = deepcopy(good_contact)
bad_contact['identities'] = [{}]
self.assertRaisesHttpError(400, s... |
'Test exceed limit error.'
| @mock.patch.object(Contact, 'MAX_CONTACTS_LIMIT', 2)
def testMaxContactLimit(self):
| self._tester.UploadContacts(self._cookie, [{'identities': [{'identity': 'Email:e1@a.com'}], 'contact_source': Contact.IPHONE}])
self.assertRaisesHttpError(403, self._tester.UploadContacts, self._cookie, [{'identities': [{'identity': 'Email:e2@a.com'}], 'contact_source': Contact.IPHONE}, {'identities': [{'identi... |
'Verify that a contact without any identities succeeds.'
| def testUploadContactWithNoIdentities(self):
| contacts = [{'identities': [], 'contact_source': Contact.IPHONE, 'name': 'Mike Purtell', 'given_name': 'Mike', 'family_name': 'Purtell'}]
upload_result = self._tester.UploadContacts(self._cookie, contacts)
self.assertEqual(len(upload_result['contact_ids']), 1)
contact_id = upload_result['contact_ids'... |
'Post multiple comments to a viewpoint.'
| def testPostComment(self):
| comment_id = self._tester.PostComment(self._cookie, self._vp_id, message='A comment \xe6\x9c\x8b\xe5\x8f\x8b\xe4\xbd\xa0\xe5\xa5\xbd')
self._tester.PostComment(self._cookie2, self._vp_id, message='A linked comment', asset_id=comment_id)
self._tester.PostComment(self._cookie2, self._vp_id, messag... |
'Post a comment after at least 24 hours have passed since viewpoint was created.'
| def testPostAfterDay(self):
| util._TEST_TIME += constants.SECONDS_PER_DAY
self._tester.PostComment(self._cookie, self._vp_id, message='It took some time for me to respond')
self._tester.PostComment(self._cookie2, self._vp_id, message="I'm just glad you acknowledged my existence")
util._TEST_TI... |
'Post a comment on a viewpoint with an unrevivable removed follower.'
| def testUnrevivable(self):
| self._tester.RemoveFollowers(self._cookie, self._vp_id, [self._user2.user_id])
self._tester.PostComment(self._cookie, self._vp_id, 'Hi there')
response_dict = self._tester.QueryFollowed(self._cookie2)
self.assertIn(Follower.REMOVED, response_dict['viewpoints'][0]['labels'])
self.assertIn(Follower... |
'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.PostComment(self._cookie, self._vp_id, message='Revival comment')
|
'ERROR: Try to send invalid fields.'
| def testInvalidFields(self):
| for attr in ['user_id', 'device_id']:
self.assertRaisesHttpError(400, self._tester.PostComment, self._cookie, self._vp_id, timestamp=0, asset_id='unknown asset', message='override', attr=100)
|
'ERROR: Try to post a comment in a viewpoint that the user does not follow.'
| def testPostViewpointNotFollowed(self):
| self.assertRaisesHttpError(403, self._tester.PostComment, self._cookie3, self._vp_id, message='message')
|
'ERROR: Try to create a comment using a device id that is different
than the one in the user cookie.'
| def testWrongDeviceId(self):
| self.assertRaisesHttpError(403, self._tester.PostComment, self._cookie3, self._vp_id, message='message', comment_id=Comment.ConstructCommentId(100, 1000, 1))
|
'Verify that a comment message that is too large fails.'
| def testMessageTooLarge(self):
| msg = ('a' * Comment.COMMENT_SIZE_LIMIT_BYTES)
self._tester.PostComment(self._cookie, self._vp_id, message=msg)
self.assertRaisesHttpError(403, self._tester.PostComment, self._cookie, self._vp_id, message=(msg + 'a'))
|
'Upload a photo, PUT the photo image data, then access it in
various ways.'
| def testUploadAndGetPut(self):
| episode_id = self._episode_id
photo_id = self._photo_ids[0]
orig_image_data = 'original image data'
self._PutPhotoAndVerify(self._cookie, 200, episode_id, photo_id, '.o', orig_image_data)
self._PutPhotoAndVerify(self._cookie, 200, episode_id, photo_id, '.f', 'full image data')
self._... |
'Test that error response is always in JSON format.'
| def testErrorResponse(self):
| response = self._PutPhoto(self._cookie, 'unk', 'unk', '.o', '')
self.assertEqual(json.loads(response.body), {'error': {'message': 'Missing Content-MD5 header.'}})
response = self._GetPhoto(self._cookie, 'unk', 'unk', '.o')
self.assertEqual(json.loads(response.body), {u'error': {u'message': u'Photo... |
'Upload a new photo and attempt to re-upload using If-None-Match
header to simulate a phone reinstall where the client uses the
/photos/<photo_id> interface to get a redirect to a PUT URL. In
the case of the photo existing, the Etag should match and result
in a 304 response, saving the client the upload bandwidth.'
| def testReUpload(self):
| full_image_data = 'full image data'
for photo_id in self._photo_ids:
response = self._PutPhoto(self._cookie, self._episode_id, photo_id, '.f', full_image_data, content_md5=util.ComputeMD5Base64(full_image_data), etag=util.ComputeMD5Hex(full_image_data))
self.assertEqual(response.code, 200)... |
'Upload photo image data with a different MD5 than was originally
provided to upload_episode. Because the photo image data does not
yet exist, the metadata should be overwritten with the new values.
Then try to upload a different MD5 again, expecting an error this
time.'
| def testUploadMismatch(self):
| for (attr_name, suffix, image_data) in [('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')]:
response = self._PutPhoto(self._cookie, self._episo... |
'Gets photos using a prospective user cookie.'
| def testProspectiveCookie(self):
| orig_image_data = 'original image data'
self._PutPhotoAndVerify(self._cookie, 200, self._episode_id, self._photo_ids[0], '.o', orig_image_data)
(prospective_user, vp_id, ep_id) = self._CreateProspectiveUser()
prospective_cookie = self._tester.GetSecureUserCookie(user_id=prospective_user.user_id, d... |
'Call _GetPhoto and verify return code equals "exp_code".'
| def _GetPhotoAndVerify(self, user_cookie, exp_code, episode_id, photo_id, suffix):
| response = self._GetPhoto(user_cookie, episode_id, photo_id, suffix)
self.assertEqual(response.code, exp_code)
if (response.code == 200):
self.assertEqual(response.headers['Cache-Control'], 'private,max-age=31536000')
return response
|
'Call _PutPhoto and verify return code equals "exp_code".'
| def _PutPhotoAndVerify(self, user_cookie, exp_code, episode_id, photo_id, suffix, image_data):
| response = self._PutPhoto(user_cookie, episode_id, photo_id, suffix, image_data, content_md5=util.ComputeMD5Base64(image_data))
self.assertEqual(response.code, exp_code)
return response
|
'Sends a GET request to the photo store URL for the specified
photo and user cookie.'
| def _GetPhoto(self, user_cookie, episode_id, photo_id, suffix):
| return self._tester.GetPhotoImage(user_cookie, episode_id, photo_id, suffix)
|
'Sends a PUT request to the photo store URL for the specified
photo and user cookie. The put request body is set to "image_data".'
| def _PutPhoto(self, user_cookie, episode_id, photo_id, suffix, image_data, etag=None, content_md5=None):
| return self._tester.PutPhotoImage(user_cookie, episode_id, photo_id, suffix, image_data, etag=etag, content_md5=content_md5)
|
'Share a single photo to a new episode in an existing viewpoint.'
| def testShare(self):
| self._tester.ShareExisting(self._cookie, self._existing_vp_id, [(self._episode_id, self._photo_ids[:1])])
viewpoint = self._RunAsync(Viewpoint.Query, self._client, self._existing_vp_id, col_names=None)
self.assertEqual(viewpoint.cover_photo['photo_id'], self._photo_ids2[0])
|
'ERROR: Try to share episodes from viewpoint which user does not
follow.'
| def testShareEpisodesNoAccess(self):
| self.assertRaisesHttpError(403, self._tester.ShareExisting, self._cookie2, self._existing_vp_id, [(self._episode_id, self._photo_ids)])
|
'ERROR: Try to share a non-existing episode.'
| def testShareInvalidEpisode(self):
| self.assertRaisesHttpError(400, self._tester.ShareExisting, self._cookie2, self._existing_vp_id, [('eunknown', self._photo_ids)])
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.