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

Unified Diff: appengine/monorail/framework/test/paginate_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/framework/test/paginate_test.py
diff --git a/appengine/monorail/framework/test/paginate_test.py b/appengine/monorail/framework/test/paginate_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..a05d1d5b7377501beb3759f86da4453f321264b3
--- /dev/null
+++ b/appengine/monorail/framework/test/paginate_test.py
@@ -0,0 +1,76 @@
+# 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
+
+"""Unit tests for pagination classes."""
+
+import unittest
+
+from framework import paginate
+from testing import testing_helpers
+
+
+class PaginateTest(unittest.TestCase):
+
+ def testVirtualPagination(self):
+ # Paginating 0 results on a page that can hold 100.
+ mr = testing_helpers.MakeMonorailRequest(path='/issues/list')
+ vp = paginate.VirtualPagination(mr, 0, 100)
+ self.assertEquals(vp.num, 100)
+ self.assertEquals(vp.start, 1)
+ self.assertEquals(vp.last, 0)
+ self.assertFalse(vp.visible)
+
+ # Paginationg 12 results on a page that can hold 100.
+ mr = testing_helpers.MakeMonorailRequest(path='/issues/list')
+ vp = paginate.VirtualPagination(mr, 12, 100)
+ self.assertEquals(vp.num, 100)
+ self.assertEquals(vp.start, 1)
+ self.assertEquals(vp.last, 12)
+ self.assertTrue(vp.visible)
+
+ # Paginationg 12 results on a page that can hold 10.
+ mr = testing_helpers.MakeMonorailRequest(path='/issues/list?num=10')
+ vp = paginate.VirtualPagination(mr, 12, 100)
+ self.assertEquals(vp.num, 10)
+ self.assertEquals(vp.start, 1)
+ self.assertEquals(vp.last, 10)
+ self.assertTrue(vp.visible)
+
+ # Paginationg 12 results starting at 5 on page that can hold 10.
+ mr = testing_helpers.MakeMonorailRequest(
+ path='/issues/list?start=5&num=10')
+ vp = paginate.VirtualPagination(mr, 12, 100)
+ self.assertEquals(vp.num, 10)
+ self.assertEquals(vp.start, 6)
+ self.assertEquals(vp.last, 12)
+ self.assertTrue(vp.visible)
+
+ # Paginationg 123 results on a page that can hold 100.
+ mr = testing_helpers.MakeMonorailRequest(path='/issues/list')
+ vp = paginate.VirtualPagination(mr, 123, 100)
+ self.assertEquals(vp.num, 100)
+ self.assertEquals(vp.start, 1)
+ self.assertEquals(vp.last, 100)
+ self.assertTrue(vp.visible)
+
+ # Paginationg 123 results on second page that can hold 100.
+ mr = testing_helpers.MakeMonorailRequest(path='/issues/list?start=100')
+ vp = paginate.VirtualPagination(mr, 123, 100)
+ self.assertEquals(vp.num, 100)
+ self.assertEquals(vp.start, 101)
+ self.assertEquals(vp.last, 123)
+ self.assertTrue(vp.visible)
+
+ # Paginationg a huge number of objects will show at most 5000 per page.
+ mr = testing_helpers.MakeMonorailRequest(path='/issues/list?num=9999')
+ vp = paginate.VirtualPagination(mr, 12345, 100)
+ self.assertEquals(vp.num, 1000)
+ self.assertEquals(vp.start, 1)
+ self.assertEquals(vp.last, 1000)
+ self.assertTrue(vp.visible)
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « appengine/monorail/framework/test/monorailrequest_test.py ('k') | appengine/monorail/framework/test/permissions_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698