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

Unified Diff: appengine/monorail/sitewide/test/projectsearch_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/sitewide/test/projectsearch_test.py
diff --git a/appengine/monorail/sitewide/test/projectsearch_test.py b/appengine/monorail/sitewide/test/projectsearch_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..1e71076ca29354ce2fe1c987e991be3a8b96c274
--- /dev/null
+++ b/appengine/monorail/sitewide/test/projectsearch_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 the projectsearch module."""
+
+import unittest
+
+import mox
+
+from framework import profiler
+from proto import project_pb2
+from services import service_manager
+from sitewide import projectsearch
+from testing import fake
+from testing import testing_helpers
+
+
+class ProjectSearchTest(unittest.TestCase):
+
+ def setUp(self):
+ self.services = service_manager.Services(
+ project=fake.ProjectService())
+
+ for idx, letter in enumerate('abcdefghijklmnopqrstuvwxyz'):
+ self.services.project.TestAddProject(letter, project_id=idx + 1)
+
+ self.mox = mox.Mox()
+ self.mox.StubOutWithMock(self.services.project, 'GetVisibleLiveProjects')
+
+ def tearDown(self):
+ self.mox.UnsetStubs()
+ self.mox.ResetAll()
+
+ def TestPipeline(
+ self, mr=None, expected_start=1, expected_last=None,
+ expected_len=None):
+ if not mr:
+ mr = testing_helpers.MakeMonorailRequest()
+
+ if expected_last is None and expected_len is not None:
+ expected_last = expected_len
+
+ mr.can = 1
+ prof = profiler.Profiler()
+
+ pipeline = projectsearch.ProjectSearchPipeline(mr, self.services, prof)
+ pipeline.SearchForIDs()
+ pipeline.GetProjectsAndPaginate('fake cnxn', '/hosting/search')
+ self.assertEqual(expected_start, pipeline.pagination.start)
+ if expected_last is not None:
+ self.assertEqual(expected_last, pipeline.pagination.last)
+ if expected_len is not None:
+ self.assertEqual(expected_len, len(pipeline.visible_results))
+
+ return pipeline
+
+ def SetUpZeroResults(self):
+ self.services.project.GetVisibleLiveProjects(
+ mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn([])
+
+ def testZeroResults(self):
+ self.SetUpZeroResults()
+ self.mox.ReplayAll()
+ pipeline = self.TestPipeline(
+ expected_last=0, expected_len=0)
+ self.mox.VerifyAll()
+ self.assertListEqual([], pipeline.visible_results)
+
+ def SetUpNonzeroResults(self):
+ self.services.project.GetVisibleLiveProjects(
+ mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn([1, 2, 3])
+
+ def testNonzeroResults(self):
+ self.SetUpNonzeroResults()
+ self.mox.ReplayAll()
+ pipeline = self.TestPipeline(
+ expected_last=3, expected_len=3)
+ self.mox.VerifyAll()
+ self.assertListEqual(
+ [1, 2, 3], [p.project_id for p in pipeline.visible_results])
+
+ def SetUpTwoPageResults(self):
+ self.services.project.GetVisibleLiveProjects(
+ mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(
+ range(1, 16))
+
+ def testTwoPageResults(self):
+ """Test more than one pagination page of results."""
+ self.SetUpTwoPageResults()
+ self.mox.ReplayAll()
+ pipeline = self.TestPipeline(
+ expected_last=10, expected_len=10)
+ self.mox.VerifyAll()
+ self.assertEqual(
+ '/hosting/search?num=10&start=10', pipeline.pagination.next_url)
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « appengine/monorail/sitewide/test/projectcreate_test.py ('k') | appengine/monorail/sitewide/test/sitewide_helpers_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698