Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3332)

Unified Diff: appengine/monorail/search/test/backendsearch_test.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/monorail/search/test/backendsearch_test.py
diff --git a/appengine/monorail/search/test/backendsearch_test.py b/appengine/monorail/search/test/backendsearch_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..bfc64ef72222a91054edbbe927adbd4bd5a169e0
--- /dev/null
+++ b/appengine/monorail/search/test/backendsearch_test.py
@@ -0,0 +1,101 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is govered by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""Unittests for monorail.search.backendsearch."""
+
+import unittest
+import mox
+
+import settings
+from search import backendsearch
+from search import backendsearchpipeline
+from services import service_manager
+from testing import fake
+from testing import testing_helpers
+
+
+class BackendSearchTest(unittest.TestCase):
+
+ def setUp(self):
+ self.services = service_manager.Services(
+ issue=fake.IssueService(),
+ )
+ self.mr = testing_helpers.MakeMonorailRequest(
+ path='/_backend/besearch?q=Priority:High&shard=2')
+ self.mr.query_project_names = ['proj']
+ self.mr.specified_logged_in_user_id = 111L
+ self.mr.specified_me_user_id = 222L
+ self.mr.shard_id = 2
+ self.servlet = backendsearch.BackendSearch(
+ 'req', 'res', services=self.services)
+ self.mox = mox.Mox()
+
+ def tearDown(self):
+ self.mox.UnsetStubs()
+ self.mox.ResetAll()
+
+ def testHandleRequest_NoResults(self):
+ """Handle the case where the search has no results."""
+ pipeline = testing_helpers.Blank(
+ SearchForIIDs=lambda: None,
+ result_iids=[],
+ search_limit_reached=False)
+ self.mox.StubOutWithMock(backendsearchpipeline, 'BackendSearchPipeline')
+ backendsearchpipeline.BackendSearchPipeline(
+ self.mr, self.services, self.servlet.profiler, 100, ['proj'], 111L, 222L
+ ).AndReturn(pipeline)
+ self.mox.ReplayAll()
+
+ json_data = self.servlet.HandleRequest(self.mr)
+ self.mox.VerifyAll()
+ self.assertEqual([], json_data['unfiltered_iids'])
+ self.assertFalse(json_data['search_limit_reached'])
+
+ def testHandleRequest_ResultsInOnePagainationPage(self):
+ """Prefetch all result issues and return them."""
+ allowed_iids = [1, 2, 3, 4, 5, 6, 7, 8]
+ pipeline = testing_helpers.Blank(
+ SearchForIIDs=lambda: None,
+ result_iids=allowed_iids,
+ search_limit_reached=False)
+ self.mox.StubOutWithMock(backendsearchpipeline, 'BackendSearchPipeline')
+ backendsearchpipeline.BackendSearchPipeline(
+ self.mr, self.services, self.servlet.profiler, 100, ['proj'], 111L, 222L
+ ).AndReturn(pipeline)
+ self.mox.StubOutWithMock(self.services.issue, 'GetIssues')
+ # All issues are prefetched because they fit on the first pagination page.
+ self.services.issue.GetIssues(self.mr.cnxn, allowed_iids, shard_id=2)
+ self.mox.ReplayAll()
+
+ json_data = self.servlet.HandleRequest(self.mr)
+ self.mox.VerifyAll()
+ self.assertEqual([1, 2, 3, 4, 5, 6, 7, 8], json_data['unfiltered_iids'])
+ self.assertFalse(json_data['search_limit_reached'])
+
+ def testHandleRequest_ResultsExceedPagainationPage(self):
+ """Return all result issue IDs, but only prefetch the first page."""
+ self.mr.num = 5
+ pipeline = testing_helpers.Blank(
+ SearchForIIDs=lambda: None,
+ result_iids=[1, 2, 3, 4, 5, 6, 7, 8],
+ search_limit_reached=False)
+ self.mox.StubOutWithMock(backendsearchpipeline, 'BackendSearchPipeline')
+ backendsearchpipeline.BackendSearchPipeline(
+ self.mr, self.services, self.servlet.profiler, 100, ['proj'], 111L, 222L
+ ).AndReturn(pipeline)
+ self.mox.StubOutWithMock(self.services.issue, 'GetIssues')
+ # First 5 issues are prefetched because num=5
+ self.services.issue.GetIssues(self.mr.cnxn, [1, 2, 3, 4, 5], shard_id=2)
+ self.mox.ReplayAll()
+
+ json_data = self.servlet.HandleRequest(self.mr)
+ self.mox.VerifyAll()
+ # All are IDs are returned to the frontend.
+ self.assertEqual([1, 2, 3, 4, 5, 6, 7, 8], json_data['unfiltered_iids'])
+ self.assertFalse(json_data['search_limit_reached'])
+
+
+if __name__ == '__main__':
+ unittest.main()

Powered by Google App Engine
This is Rietveld 408576698