def test_third_page(self): """Test getting the third page with more total count.""" query = datastore_query.Query(TestDatastoreModel) query.filter_in('tokens', ['a', 'b']) query.filter('boolean_value', True) query.order('datetime_value', is_desc=True) query.fetch_page(page=1, page_size=2, projection=['tokens'], more_limit=4) self.assertIsInstance(self.queries[0][-1].filters, ndb.AND) self.assertItemsEqual([ ('tokens', '=', 'a'), ('boolean_value', '=', True), ], [f.__getnewargs__() for f in self.queries[0][-1].filters]) self.assertIsInstance(self.queries[1][-1].filters, ndb.AND) self.assertItemsEqual([ ('tokens', '=', 'b'), ('boolean_value', '=', True), ], [f.__getnewargs__() for f in self.queries[1][-1].filters]) self.assertIsInstance(self.queries[2][-1].filters, ndb.OR) self.assertItemsEqual([ ('__key__', '=', datastore_types.Key.from_path( u'TestDatastoreModel', 0, _app=u'test-clusterfuzz')), ('__key__', '=', datastore_types.Key.from_path( u'TestDatastoreModel', 1, _app=u'test-clusterfuzz')), ], [f.__getnewargs__() for f in self.queries[2][-1].filters])
def test_greater_or_equal(self): """Test that a query using an operator other than "=" works.""" query = datastore_query.Query(TestDatastoreModel) query.filter( 'datetime_value', datetime.datetime.fromtimestamp(96), operator='>=') query.order('datetime_value', is_desc=True) _, total_count, has_more = query.fetch( offset=0, limit=100, projection=['tokens'], more_limit=100) # We expect the above query to return values from 96-100. self.assertEqual(total_count, 5) self.assertFalse(has_more)
def get_result(this): """Get the result.""" params = {k: v for k, v in this.request.iterparams()} page = helpers.cast( this.request.get('page') or 1, int, "'page' is not an int.") query = datastore_query.Query(data_types.TestcaseUploadMetadata) query.order('timestamp', is_desc=True) if not access.has_access(need_privileged_access=True): query.filter('uploader_email', helpers.get_user_email()) params['permission'] = {'uploaderEmail': helpers.get_user_email()} entities, total_pages, total_items, has_more = query.fetch_page( page=page, page_size=PAGE_SIZE, projection=None, more_limit=MORE_LIMIT) items = [] for entity in entities: items.append({ 'timestamp': utils.utc_datetime_to_timestamp(entity.timestamp), 'testcaseId': entity.testcase_id, 'uploaderEmail': entity.uploader_email, 'filename': entity.filename, 'bundled': entity.bundled, 'pathInArchive': entity.path_in_archive, 'status': entity.status }) attach_testcases(items) result = { 'hasMore': has_more, 'items': items, 'page': page, 'pageSize': PAGE_SIZE, 'totalItems': total_items, 'totalPages': total_pages, } return result, params
def test_third_page(self): """Test getting the third page with more total count.""" query = datastore_query.Query(TestDatastoreModel) query.filter_in('tokens', ['a', 'b']) query.filter('boolean_value', True) query.order('datetime_value', is_desc=True) items, total_pages, total_items, has_more = query.fetch_page( page=3, page_size=2, projection=['tokens'], more_limit=4) self.assertListEqual([self.mocks[8].key.id(), self.mocks[10].key.id()], [item.key.id() for item in items]) self.assertListEqual([['a'], ['a']], [item.tokens for item in items]) with self.assertRaises(ndb.UnprojectedPropertyError): _ = [item.boolean_value for item in items] self.assertEqual(10, total_items) self.assertEqual(5, total_pages) self.assertTrue(has_more)
def get_result(this): """Get the result.""" params = {k: v for k, v in this.request.iterparams()} page = helpers.cast( this.request.get("page") or 1, int, "'page' is not an int.") query = datastore_query.Query(data_types.TestcaseUploadMetadata) query.order("timestamp", is_desc=True) if not access.has_access(need_privileged_access=True): query.filter("uploader_email", helpers.get_user_email()) params["permission"] = {"uploaderEmail": helpers.get_user_email()} entities, total_pages, total_items, has_more = query.fetch_page( page=page, page_size=PAGE_SIZE, projection=None, more_limit=MORE_LIMIT) items = [] for entity in entities: items.append({ "timestamp": utils.utc_datetime_to_timestamp(entity.timestamp), "testcaseId": entity.testcase_id, "uploaderEmail": entity.uploader_email, "filename": entity.filename, "bundled": entity.bundled, "pathInArchive": entity.path_in_archive, "status": entity.status, }) attach_testcases(items) result = { "hasMore": has_more, "items": items, "page": page, "pageSize": PAGE_SIZE, "totalItems": total_items, "totalPages": total_pages, } return result, params
def get_results(this): """Get results for the jobs page.""" # Return jobs sorted alphabetically by name query = datastore_query.Query(data_types.Job) query.order('name', is_desc=False) params = dict(this.request.iterparams()) filters.add(query, params, FILTERS) page = helpers.cast( this.request.get('page') or 1, int, "'page' is not an int.") items, total_pages, total_items, has_more = query.fetch_page( page=page, page_size=PAGE_SIZE, projection=None, more_limit=MORE_LIMIT) result = { 'hasMore': has_more, 'items': [_job_to_dict(item) for item in items], 'page': page, 'pageSize': PAGE_SIZE, 'totalItems': total_items, 'totalPages': total_pages, } return result, params
def get_results(): """Get results for the bots page.""" # Return bots sorted alphabetically by bot_name query = datastore_query.Query(data_types.Heartbeat) query.order('bot_name', is_desc=False) params = dict(request.iterparams()) filters.add(query, params, FILTERS) page = helpers.cast(request.get('page', 1), int, "'page' is not an int.") items, total_pages, total_items, has_more = query.fetch_page( page=page, page_size=PAGE_SIZE, projection=None, more_limit=MORE_LIMIT) items = _convert_heartbeats_to_dicts(items) helpers.log('Bots', helpers.VIEW_OPERATION) result = { 'hasMore': has_more, 'items': items, 'page': page, 'pageSize': PAGE_SIZE, 'totalItems': total_items, 'totalPages': total_pages, } return result, params
def test_third_page(self): """Test getting the third page with more total count.""" query = datastore_query.Query(TestDatastoreModel) query.filter_in('tokens', ['a', 'b']) query.filter('boolean_value', True) query.order('datetime_value', is_desc=True) query.fetch_page(page=1, page_size=2, projection=['tokens'], more_limit=4) self.assertIsInstance(self.queries[0][-1].filters, ndb.AND) six.assertCountEqual(self, [ ('tokens', '=', 'a'), ('boolean_value', '=', True), ], [f.__getnewargs__() for f in self.queries[0][-1].filters]) self.assertIsInstance(self.queries[1][-1].filters, ndb.AND) six.assertCountEqual(self, [ ('tokens', '=', 'b'), ('boolean_value', '=', True), ], [f.__getnewargs__() for f in self.queries[1][-1].filters]) self.assertIsInstance(self.queries[2][-1].filters, ndb.OR) expected = [] for item in [f.__getnewargs__() for f in self.queries[2][-1].filters]: expected.append((item[0], item[1], repr(item[2]))) six.assertCountEqual(self, [ ('__key__', '=', '<Key(\'TestDatastoreModel\', 0), project=test-clusterfuzz>'), ('__key__', '=', '<Key(\'TestDatastoreModel\', 1), project=test-clusterfuzz>'), ], expected)
def get_result(this): """Get the result for the testcase list page.""" params = {k: v for k, v in this.request.iterparams()} page = helpers.cast( this.request.get('page') or 1, int, "'page' is not an int.") query = datastore_query.Query(data_types.Testcase) crash_access.add_scope(query, params, 'security_flag', 'job_type', 'fuzzer_name_indices') add_filters(query, params) testcases, total_pages, total_items, has_more = query.fetch_page( page=page, page_size=PAGE_SIZE, projection=FIELDS, more_limit=MORE_LIMIT) items = [] for testcase in testcases: regression_range = '' fixed_range = '' if testcase.regression and testcase.regression != 'NA': regression_range = testcase.regression if testcase.fixed and testcase.fixed != 'NA': fixed_range = testcase.fixed item = { 'id': testcase.key.id(), 'crashType': ' '.join(testcase.crash_type.splitlines()), 'crashStateLines': testcase.crash_state.strip().splitlines(), 'jobType': testcase.job_type, 'isClosed': not testcase.open, 'isFixed': testcase.fixed and testcase.fixed != 'NA', 'isReproducible': not testcase.one_time_crasher_flag, 'isSecurity': testcase.security_flag, 'isImpactSet': testcase.is_impact_set_flag, 'impacts': { 'stable': testcase.impact_stable_version, 'beta': testcase.impact_beta_version, }, 'regressionRange': regression_range, 'fixedRange': fixed_range, 'groupId': testcase.group_id, 'projectName': testcase.project_name, 'platform': testcase.platform, 'issueId': testcase.bug_information or testcase.group_bug_information, 'showImpacts': testcase.has_impacts(), 'impactsProduction': testcase.impacts_production() } if testcase.timestamp: item['timestamp'] = utils.utc_datetime_to_timestamp( testcase.timestamp) items.append(item) helpers.log('Testcases', helpers.VIEW_OPERATION) result = { 'hasMore': has_more, 'items': items, 'page': page, 'pageSize': PAGE_SIZE, 'totalItems': total_items, 'totalPages': total_pages, } return result, params