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() |