def setUp(self): super(BisectFYITest, self).setUp() stored_object.Set(bisect_fyi._BISECT_FYI_CONFIGS_KEY, TEST_FYI_CONFIGS) stored_object.Set( start_try_job._TESTER_DIRECTOR_MAP_KEY, { 'linux_perf_bisect': 'linux_perf_bisector', 'win_x64_perf_bisect': 'linux_perf_bisector', }) app = webapp2.WSGIApplication([('/bisect_fyi', bisect_fyi.BisectFYIHandler)]) self.testapp = webtest.TestApp(app)
def Set(key, value, days_to_keep=None, namespace=None): """Sets the value in the datastore. Args: key: The key name, which will be namespaced. value: The value to set. days_to_keep: Number of days to keep entity in datastore, default is None. Entity will not expire when this value is 0 or None. namespace: Optional namespace, otherwise namespace will be retrieved using datastore_hooks.GetNamespace(). """ # When number of days to keep is given, calculate expiration time for # the entity and store it in datastore. # Once the entity expires, it will be deleted from the datastore. expire_time = None if days_to_keep: expire_time = datetime.datetime.now() + datetime.timedelta( days=days_to_keep) namespaced_key = _NamespaceKey(key, namespace) try: CachedPickledString(id=namespaced_key, value=cPickle.dumps(value), expire_time=expire_time).put() except datastore_errors.BadRequestError as e: logging.warning('BadRequestError for key %s: %s', key, e) except apiproxy_errors.RequestTooLargeError as e: stored_object.Set(key, value)
def setUp(self): super(StartNewBisectForBugTest, self).setUp() stored_object.Set( start_try_job._TESTER_DIRECTOR_MAP_KEY, { 'linux_perf_tester': 'linux_perf_bisector', 'win64_nv_tester': 'linux_perf_bisector', })
def testPost_ForcesCacheUpdate(self): key = update_test_suites._NamespaceKey( update_test_suites._LIST_SUITES_CACHE_KEY) stored_object.Set(key, {'foo': 'bar'}) self.assertEqual( {'foo': 'bar'}, update_test_suites.FetchCachedTestSuites()) self._AddSampleData() # Because there is something cached, the cache is # not automatically updated when new data is added. self.assertEqual( {'foo': 'bar'}, update_test_suites.FetchCachedTestSuites()) # Making a request to /udate_test_suites forces an update. self.testapp.post('/update_test_suites') self.assertEqual( { 'dromaeo': { 'mas': {'Chromium': {'mac': False, 'win7': False}}, }, 'scrolling': { 'mas': {'Chromium': {'mac': False, 'win7': False}}, }, 'really': { 'mas': {'Chromium': {'mac': False, 'win7': False}}, }, }, update_test_suites.FetchCachedTestSuites())
def testAddRowsToCache(self): self._AddMockData() rows = [] stored_object.Set( 'externally_visible__num_revisions_ChromiumPerf/win7/dromaeo/dom', [[10, 2, 3], [15, 4, 5], [100, 6, 7]]) test_key = utils.TestKey('ChromiumPerf/win7/dromaeo/dom') test_container_key = utils.GetTestContainerKey(test_key) ts1 = datetime.datetime(2013, 1, 1) row1 = graph_data.Row(parent=test_container_key, id=1, value=9, timestamp=ts1) rows.append(row1) ts2 = datetime.datetime(2013, 1, 2) row2 = graph_data.Row(parent=test_container_key, id=12, value=90, timestamp=ts2) rows.append(row2) ts3 = datetime.datetime(2013, 1, 3) row3 = graph_data.Row(parent=test_container_key, id=102, value=99, timestamp=ts3) rows.append(row3) graph_revisions.AddRowsToCache(rows) self.assertEqual( [[1, 9, utils.TimestampMilliseconds(ts1)], [10, 2, 3], [12, 90, utils.TimestampMilliseconds(ts2)], [15, 4, 5], [100, 6, 7], [102, 99, utils.TimestampMilliseconds(ts3)]], stored_object.Get('externally_visible__num_revisions_' 'ChromiumPerf/win7/dromaeo/dom'))
def testFetchCachedTestSuites_NotEmpty(self): # If the cache is set, then whatever's there is returned. key = update_test_suites._NamespaceKey( update_test_suites._LIST_SUITES_CACHE_KEY) stored_object.Set(key, {'foo': 'bar'}) self.assertEqual({'foo': 'bar'}, update_test_suites.FetchCachedTestSuites())
def testPost_CacheSet_ReturnsCachedRevisions(self): stored_object.Set( 'externally_visible__num_revisions_ChromiumPerf/win7/dromaeo/dom', [[1, 2, 3]]) response = self.testapp.post( '/graph_revisions', {'test_path': 'ChromiumPerf/win7/dromaeo/dom'}) self.assertEqual([[1, 2, 3]], json.loads(response.body))
def UpdateTestSuites(permissions_namespace): """Updates test suite data for either internal or external users.""" logging.info('Updating test suite data for: %s', permissions_namespace) suite_dict = _CreateTestSuiteDict() key = _NamespaceKey(_LIST_SUITES_CACHE_KEY, namespace=permissions_namespace) stored_object.Set(key, suite_dict)
def setUp(self): super(StartBisectTest, self).setUp() stored_object.Set( start_try_job._TESTER_DIRECTOR_MAP_KEY, { 'linux_perf_tester': 'linux_perf_bisector', 'win64_nv_tester': 'linux_perf_bisector', }) app = webapp2.WSGIApplication( [('/start_try_job', start_try_job.StartBisectHandler)]) self.testapp = webtest.TestApp(app) namespaced_stored_object.Set( start_try_job._BISECT_BOT_MAP_KEY, { 'ChromiumPerf': [ ('nexus4', 'android_nexus4_perf_bisect'), ('nexus7', 'android_nexus7_perf_bisect'), ('win8', 'win_8_perf_bisect'), ('xp', 'win_xp_perf_bisect'), ('android', 'android_nexus7_perf_bisect'), ('mac', 'mac_perf_bisect'), ('win', 'win_perf_bisect'), ('linux', 'linux_perf_bisect'), ('', 'linux_perf_bisect'), ], }) namespaced_stored_object.Set( start_try_job._BUILDER_TYPES_KEY, {'ChromiumPerf': 'perf', 'OtherMaster': 'foo'}) testing_common.SetSheriffDomains(['chromium.org'])
def testSetAndGet_CacheNotExist_CacheSet(self): new_account = SampleSerializableClass('Some account data.') stored_object.Set('chris', new_account) stored_object.MultipartCache.Delete('chris') chris_account = stored_object.Get('chris') self.assertEqual(new_account, chris_account) cache_values = self._GetCachedValues('chris') self.assertGreater(len(cache_values), 0)
def setUp(self): super(BisectFYITest, self).setUp() app = webapp2.WSGIApplication([('/bisect_fyi', bisect_fyi.BisectFYIHandler)]) self.testapp = webtest.TestApp(app) stored_object.Set(bisect_fyi._BISECT_FYI_CONFIGS_KEY, TEST_FYI_CONFIGS) testing_common.SetIsInternalUser('*****@*****.**', True) self.SetCurrentUser('*****@*****.**')
def testPost_WithSomeInvalidJSON_ShowsErrorAndDoesNotModify(self): stored_object.Set('foo', 'XXX') response = self.testapp.post('/edit_site_config', { 'key': 'foo', 'value': '[1, 2, this is not json', 'xsrf_token': xsrf.GenerateToken(users.get_current_user()), }) self.assertIn('Invalid JSON', response.body) self.assertEqual('XXX', stored_object.Get('foo'))
def setUp(self): super(AutoBisectTest, self).setUp() stored_object.Set( start_try_job._TESTER_DIRECTOR_MAP_KEY, { 'linux_perf_tester': 'linux_perf_bisector', 'win64_nv_tester': 'linux_perf_bisector', }) app = webapp2.WSGIApplication([('/auto_bisect', auto_bisect.AutoBisectHandler)]) self.testapp = webtest.TestApp(app)
def testDelete_LargeObject_AllEntitiesDeleted(self): a_large_string = '0' * 2097152 new_account = SampleSerializableClass(a_large_string) stored_object.Set('chris', new_account) stored_object.Delete('chris') multipart_entities = stored_object.MultipartEntity.query().fetch() self.assertEqual(0, len(multipart_entities)) part_entities = stored_object.PartEntity.query().fetch() self.assertEqual(0, len(part_entities)) cache_values = self._GetCachedValues('chris') self.assertEqual(0, len(cache_values))
def setUp(self): super(BisectFYITest, self).setUp() app = webapp2.WSGIApplication([('/bisect_fyi', bisect_fyi.BisectFYIHandler)]) self.testapp = webtest.TestApp(app) stored_object.Set(bisect_fyi._BISECT_FYI_CONFIGS_KEY, TEST_FYI_CONFIGS) testing_common.SetIsInternalUser('*****@*****.**', True) self.SetCurrentUser('*****@*****.**') namespaced_stored_object.Set( start_try_job._TESTER_DIRECTOR_MAP_KEY, { 'ChromiumPerf': { 'linux_perf_bisect': 'linux_perf_bisector', 'win_x64_perf_bisect': 'win_x64_perf_bisect', } })
def testSetAndGet_LargeObject(self): a_large_string = '0' * 2097152 new_account = SampleSerializableClass(a_large_string) stored_object.Set('chris', new_account) chris_account = stored_object.Get('chris') part_entities = stored_object.PartEntity.query().fetch() self.assertEqual(new_account, chris_account) # chris_account object should be stored over 3 PartEntity entities. self.assertEqual(3, len(part_entities)) # Stored over 4 caches here, one extra for the head cache. cache_values = self._GetCachedValues('chris') self.assertEqual(4, len(cache_values))
def post(self): """Accepts posted values, makes changes, and shows the form again.""" key = self.request.get('key') if not utils.IsInternalUser(): self.RenderHtml('edit_site_config.html', { 'error': 'Only internal users can post to this end-point.' }) return if not key: self.RenderHtml('edit_site_config.html', {}) return new_value_json = self.request.get('value').strip() new_external_value_json = self.request.get('external_value').strip() new_internal_value_json = self.request.get('internal_value').strip() template_params = { 'key': key, 'value': new_value_json, 'external_value': new_external_value_json, 'internal_value': new_internal_value_json, } try: new_value = json.loads(new_value_json or 'null') new_external_value = json.loads(new_external_value_json or 'null') new_internal_value = json.loads(new_internal_value_json or 'null') except ValueError: template_params['error'] = 'Invalid JSON in at least one field.' self.RenderHtml('edit_site_config.html', template_params) return old_value = stored_object.Get(key) old_external_value = namespaced_stored_object.GetExternal(key) old_internal_value = namespaced_stored_object.Get(key) stored_object.Set(key, new_value) namespaced_stored_object.SetExternal(key, new_external_value) namespaced_stored_object.Set(key, new_internal_value) _SendNotificationEmail( key, old_value, old_external_value, old_internal_value, new_value, new_external_value, new_internal_value) self.RenderHtml('edit_site_config.html', template_params)
def testFYI_Send_No_Email_On_Success(self): stored_object.Set( bisect_fyi._BISECT_FYI_CONFIGS_KEY, bisect_fyi_test.TEST_FYI_CONFIGS) test_config = bisect_fyi_test.TEST_FYI_CONFIGS['positive_culprit'] bisect_config = test_config.get('bisect_config') self._AddTryJob(12345, 'started', 'win_perf', results_data=_SAMPLE_BISECT_RESULTS_JSON, internal_only=True, config=utils.BisectConfigPythonString(bisect_config), job_type='bisect-fyi', job_name='positive_culprit', email='*****@*****.**') self.testapp.get('/update_bug_with_results') messages = self.mail_stub.get_sent_messages() self.assertEqual(0, len(messages))
def setUp(self): super(StartBisectTest, self).setUp() stored_object.Set( start_try_job._TESTER_DIRECTOR_MAP_KEY, { 'linux_perf_tester': 'linux_perf_bisector', 'win64_nv_tester': 'linux_perf_bisector', }) app = webapp2.WSGIApplication( [('/start_try_job', start_try_job.StartBisectHandler)]) self.testapp = webtest.TestApp(app) namespaced_stored_object.Set( start_try_job._BISECT_BOT_MAP_KEY, { 'ChromiumPerf': [ ('nexus4', 'android_nexus4_perf_bisect'), ('nexus7', 'android_nexus7_perf_bisect'), ('win8', 'win_8_perf_bisect'), ('xp', 'win_xp_perf_bisect'), ('android', 'android_nexus7_perf_bisect'), ('mac', 'mac_perf_bisect'), ('win', 'win_perf_bisect'), ('linux', 'linux_perf_bisect'), ('', 'linux_perf_bisect'), ], }) namespaced_stored_object.Set( start_try_job._BUILDER_TYPES_KEY, {'ChromiumPerf': 'perf', 'OtherMaster': 'foo'}) namespaced_stored_object.Set( start_try_job._BOT_BROWSER_MAP_KEY, [ ['android', 'android-chromium'], ['winx64', 'release_x64'], ['win_x64', 'release_x64'], ['', 'release'], ]) testing_common.SetSheriffDomains(['chromium.org']) # Add fake Rietveld auth info. rietveld_config = rietveld_service.RietveldConfig( id='default_rietveld_config', client_email='*****@*****.**', service_account_key='Fake Account Key', server_url='https://test-rietveld.appspot.com') rietveld_config.put()
def testFYI_Failed_Job_SendEmail_On_Exception(self): stored_object.Set( bisect_fyi._BISECT_FYI_CONFIGS_KEY, bisect_fyi_test.TEST_FYI_CONFIGS) test_config = bisect_fyi_test.TEST_FYI_CONFIGS['positive_culprit'] bisect_config = test_config.get('bisect_config') sample_bisect_results = copy.deepcopy(_SAMPLE_BISECT_RESULTS_JSON) sample_bisect_results['status'] = 'failed' self._AddTryJob(12345, 'started', 'win_perf', results_data=sample_bisect_results, internal_only=True, buildbucket_job_id='12345', config=utils.BisectConfigPythonString(bisect_config), job_type='bisect-fyi', job_name='positive_culprit', email='*****@*****.**') self.testapp.get('/update_bug_with_results') messages = self.mail_stub.get_sent_messages() self.assertEqual(1, len(messages))
def post(self): """Accepts posted values, makes changes, and shows the form again.""" key = self.request.get('key') if not utils.IsInternalUser(): self.RenderHtml('edit_site_config.html', { 'error': 'Only internal users can post to this end-point.' }) return if not key: self.RenderHtml('edit_site_config.html', {}) return value = self.request.get('value').strip() external_value = self.request.get('external_value').strip() internal_value = self.request.get('internal_value').strip() template_params = { 'key': key, 'value': value, 'external_value': external_value, 'internal_value': internal_value, } try: if value: stored_object.Set(key, json.loads(value)) if external_value: namespaced_stored_object.SetExternal(key, json.loads(external_value)) if internal_value: namespaced_stored_object.Set(key, json.loads(internal_value)) except ValueError: template_params['error'] = 'Invalid JSON in at least one field.' _SendNotificationEmail(key, template_params) self.RenderHtml('edit_site_config.html', template_params)
def SetInternalDomain(domain): """Sets the domain that users who can access internal data belong to.""" stored_object.Set(utils.INTERNAL_DOMAIN_KEY, domain)
def testGet_WithNonNamespacedKey_ShowsPageWithCurrentValue(self): stored_object.Set('foo', 'XXXYYY') response = self.testapp.get('/edit_site_config?key=foo') self.assertEqual(1, len(response.html('form'))) self.assertIn('XXXYYY', response.body)
def testGet_InternalUser_InternalVersionReturned(self): self.SetCurrentUser('*****@*****.**') stored_object.Set('internal_only__foo', [1, 2, 3]) stored_object.Set('externally_visible__foo', [4, 5, 6]) self.assertEqual([1, 2, 3], namespaced_stored_object.Get('foo'))
def testGet_StoredObject(self): stored_object.Set('foo', 'bar') self.assertEqual('bar', layered_cache.Get('foo'))
def SetSheriffDomains(domains): """Sets the domain that users who can access internal data belong to.""" stored_object.Set(utils.SHERIFF_DOMAINS_KEY, domains)
def SetIpWhitelist(ip_addresses): """Sets the list of whitelisted IP addresses.""" stored_object.Set(utils.IP_WHITELIST_KEY, ip_addresses)
def testSetAndGet(self): new_account = SampleSerializableClass('Some account data.') stored_object.Set('chris', new_account) chris_account = stored_object.Get('chris') self.assertEqual(new_account, chris_account)
def testDelete_BothVersionsDeleted(self): stored_object.Set('internal_only__foo', [1, 2, 3]) stored_object.Set('externally_visible__foo', [4, 5, 6]) namespaced_stored_object.Delete('foo') self.assertIsNone(stored_object.Get('internal_only__foo')) self.assertIsNone(stored_object.Get('externally_visible__foo'))
def testGetExternal_InternalUser_ExternalVersionReturned(self): self.SetCurrentUser('*****@*****.**') stored_object.Set('internal_only__foo', [1, 2, 3]) stored_object.Set('externally_visible__foo', [4, 5, 6]) self.assertEqual([4, 5, 6], namespaced_stored_object.GetExternal('foo'))