def testDetermineIssuePositionInShard_IssueIsNotInShard(self): pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) # The total ordering is issue_1, issue_3, issue_2 for high, med, low. pipeline.filtered_iids = { 0: [self.issue_2.issue_id, self.issue_3.issue_id], } prev_cand, index, next_cand = pipeline._DetermineIssuePositionInShard( 0, self.issue_1, {}) self.assertEqual(None, prev_cand) self.assertEqual(0, index) self.assertEqual(self.issue_3, next_cand) pipeline.filtered_iids = { 0: [self.issue_1.issue_id, self.issue_2.issue_id], } prev_cand, index, next_cand = pipeline._DetermineIssuePositionInShard( 0, self.issue_3, {}) self.assertEqual(self.issue_1, prev_cand) self.assertEqual(1, index) self.assertEqual(self.issue_2, next_cand) pipeline.filtered_iids = { 0: [self.issue_1.issue_id, self.issue_3.issue_id], } prev_cand, index, next_cand = pipeline._DetermineIssuePositionInShard( 0, self.issue_2, {}) self.assertEqual(self.issue_3, prev_cand) self.assertEqual(2, index) self.assertEqual(None, next_cand)
def testSearchForIIDs_CrossProject_MembersOnlyOmitted(self): self.services.project.TestAddProject( 'other', project_id=790, access=project_pb2.ProjectAccess.MEMBERS_ONLY) unfiltered_iids = {(1, 'p:v'): [1001, 1011]} nonviewable_iids = {1: set()} # project 'other' gets filtered out before the backend call. self.mr.query_project_names = ['other'] self.mox.StubOutWithMock(frontendsearchpipeline, '_StartBackendSearch') frontendsearchpipeline._StartBackendSearch( self.mr, ['proj'], [789], mox.IsA(tracker_pb2.ProjectIssueConfig), unfiltered_iids, {}, nonviewable_iids, set(), self.services).AndReturn([]) self.mox.StubOutWithMock(frontendsearchpipeline, '_FinishBackendSearch') frontendsearchpipeline._FinishBackendSearch([]) self.mox.ReplayAll() pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) pipeline.unfiltered_iids = unfiltered_iids pipeline.nonviewable_iids = nonviewable_iids pipeline.SearchForIIDs() self.mox.VerifyAll() self.assertEqual(2, pipeline.total_count) self.assertEqual([1001, 1011], pipeline.filtered_iids[(1, 'p:v')])
def issues_list(self, request): """List issues for projects.""" mar = self.mar_factory(request) if request.additionalProject: for project_name in request.additionalProject: project = self._services.project.GetProjectByName( mar.cnxn, project_name) if project and not permissions.UserCanViewProject( mar.auth.user_pb, mar.auth.effective_ids, project): raise permissions.PermissionException( 'The user %s has no permission for project %s' % (mar.auth.email, project_name)) prof = profiler.Profiler() pipeline = frontendsearchpipeline.FrontendSearchPipeline( mar, self._services, prof, mar.num) if not mar.errors.AnyErrors(): pipeline.SearchForIIDs() pipeline.MergeAndSortIssues() pipeline.Paginate() else: raise endpoints.BadRequestException(mar.errors.query) issue_list = [ api_pb2_v1_helpers.convert_issue( api_pb2_v1.IssueWrapper, r, mar, self._services) for r in pipeline.visible_results] return api_pb2_v1.IssuesListResponse( kind='monorail#issueList', totalResults=pipeline.total_count, items=issue_list)
def testChooseSampleIssues_Small(self): """When the search gave few results, don't bother with samples.""" pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) issue_ids = [78901, 78902] on_hand_issues, needed_iids = pipeline._ChooseSampleIssues(issue_ids) self.assertEqual({}, on_hand_issues) self.assertEqual([], needed_iids)
def testChooseSampleIssues_Empty(self): """When the search gave no results, there cannot be any samples.""" pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) issue_ids = [] on_hand_issues, needed_iids = pipeline._ChooseSampleIssues(issue_ids) self.assertEqual({}, on_hand_issues) self.assertEqual([], needed_iids)
def testFetchAllSamples_Empty(self): filtered_iids = {} pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) samples_by_shard, sample_iids_to_shard = pipeline._FetchAllSamples( filtered_iids) self.assertEqual({}, samples_by_shard) self.assertEqual({}, sample_iids_to_shard)
def testMergeAndSortIssues_EmptyResult(self): pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) pipeline.filtered_iids = {0: [], 1: [], 2: []} pipeline.MergeAndSortIssues() self.assertEqual([], pipeline.allowed_iids) self.assertEqual([], pipeline.allowed_results) self.assertEqual({}, pipeline.users_by_id)
def testLookupNeededUsers(self): pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) pipeline._LookupNeededUsers([]) self.assertEqual([], pipeline.users_by_id.keys()) pipeline._LookupNeededUsers([self.issue_1, self.issue_2, self.issue_3]) self.assertEqual([111L], pipeline.users_by_id.keys())
def testChooseSampleIssues_Normal(self): """We will choose at least one sample for every 10 results in a shard.""" pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) issues = self.MakeIssues(23) issue_ids = [issue.issue_id for issue in issues] on_hand_issues, needed_iids = pipeline._ChooseSampleIssues(issue_ids) self.assertEqual({}, on_hand_issues) self.assertEqual(2, len(needed_iids)) for sample_iid in needed_iids: self.assertIn(sample_iid, issue_ids)
def testFetchAllSamples_SmallResultsPerShard(self): filtered_iids = { 0: [100, 110, 120], 1: [101, 111, 121], } pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) samples_by_shard, sample_iids_to_shard = pipeline._FetchAllSamples( filtered_iids) self.assertEqual(2, len(samples_by_shard)) self.assertEqual(0, len(sample_iids_to_shard))
def testPaginate_Grid(self): self.mr.mode = 'grid' pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) pipeline.allowed_iids = [ self.issue_1.issue_id, self.issue_2.issue_id, self.issue_3.issue_id ] pipeline.allowed_results = [self.issue_1, self.issue_2, self.issue_3] pipeline.total_count = len(pipeline.allowed_results) pipeline.Paginate() self.assertEqual([self.issue_1, self.issue_2, self.issue_3], pipeline.visible_results)
def testPaginate_List(self): pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) pipeline.allowed_iids = [ self.issue_1.issue_id, self.issue_2.issue_id, self.issue_3.issue_id ] pipeline.allowed_results = [self.issue_1, self.issue_2, self.issue_3] pipeline.total_count = len(pipeline.allowed_results) pipeline.Paginate() self.assertEqual([self.issue_1, self.issue_2, self.issue_3], pipeline.visible_results) self.assertFalse(pipeline.pagination.limit_reached)
def testFetchAllSamples_Normal(self): pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) issues = self.MakeIssues(23) filtered_iids = { 0: [issue.issue_id for issue in issues], } samples_by_shard, sample_iids_to_shard = pipeline._FetchAllSamples( filtered_iids) self.assertEqual(1, len(samples_by_shard)) self.assertEqual(2, len(samples_by_shard[0])) self.assertEqual(2, len(sample_iids_to_shard)) for sample_iid in sample_iids_to_shard: shard_key = sample_iids_to_shard[sample_iid] self.assertIn(sample_iid, filtered_iids[shard_key])
def testDetermineIssuePosition_NotInResults(self): pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) # In this unit test case we are not calling SearchForIIDs(), instead just # set pipeline.filtered_iids directly. pipeline.filtered_iids = { 0: [], 1: [self.issue_1.issue_id], 2: [self.issue_2.issue_id], 3: [] } prev_iid, index, next_iid = pipeline.DetermineIssuePosition( self.issue_3) # The total ordering is issue_1, issue_3, issue_2 for high, med, low. self.assertEqual(None, prev_iid) self.assertEqual(None, index) self.assertEqual(None, next_iid)
def testMergeAndSortIssues_Normal(self): pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) # In this unit test case we are not calling SearchForIIDs(), instead just # set pipeline.filtered_iids directly. pipeline.filtered_iids = { 0: [], 1: [self.issue_1.issue_id], 2: [self.issue_2.issue_id], 3: [self.issue_3.issue_id] } pipeline.MergeAndSortIssues() self.assertEqual([ self.issue_1.issue_id, self.issue_2.issue_id, self.issue_3.issue_id ], pipeline.allowed_iids) self.assertEqual( [self.issue_1, self.issue_3, self.issue_2], # high, medium, low. pipeline.allowed_results) self.assertEqual([111L], pipeline.users_by_id.keys())
def testSearchForIIDs_AllResultsCached_AllAtRiskCached(self): unfiltered_iids = {(1, 'p:v'): [1001, 1011]} nonviewable_iids = {1: set()} self.mox.StubOutWithMock(frontendsearchpipeline, '_StartBackendSearch') frontendsearchpipeline._StartBackendSearch( self.mr, ['proj'], [789], mox.IsA(tracker_pb2.ProjectIssueConfig), unfiltered_iids, {}, nonviewable_iids, set(), self.services).AndReturn([]) self.mox.StubOutWithMock(frontendsearchpipeline, '_FinishBackendSearch') frontendsearchpipeline._FinishBackendSearch([]) self.mox.ReplayAll() pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) pipeline.unfiltered_iids = unfiltered_iids pipeline.nonviewable_iids = nonviewable_iids pipeline.SearchForIIDs() self.mox.VerifyAll() self.assertEqual(2, pipeline.total_count) self.assertEqual([1001, 1011], pipeline.filtered_iids[(1, 'p:v')])
def testSearchForIIDs_CrossProject_AllViewable(self): self.services.project.TestAddProject('other', project_id=790) unfiltered_iids = {(1, 'p:v'): [1001, 1011, 2001]} nonviewable_iids = {1: set()} self.mr.query_project_names = ['other'] self.mox.StubOutWithMock(frontendsearchpipeline, '_StartBackendSearch') frontendsearchpipeline._StartBackendSearch( self.mr, ['other', 'proj'], [789, 790], mox.IsA(tracker_pb2.ProjectIssueConfig), unfiltered_iids, {}, nonviewable_iids, set(), self.services).AndReturn([]) self.mox.StubOutWithMock(frontendsearchpipeline, '_FinishBackendSearch') frontendsearchpipeline._FinishBackendSearch([]) self.mox.ReplayAll() pipeline = frontendsearchpipeline.FrontendSearchPipeline( self.mr, self.services, self.profiler, 100) pipeline.unfiltered_iids = unfiltered_iids pipeline.nonviewable_iids = nonviewable_iids pipeline.SearchForIIDs() self.mox.VerifyAll() self.assertEqual(3, pipeline.total_count) self.assertEqual([1001, 1011, 2001], pipeline.filtered_iids[(1, 'p:v')])