allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [06/10] allura git commit: [#7794] ticket:677 Add tests for g.handle_paging
Date Wed, 19 Nov 2014 22:59:45 GMT
[#7794] ticket:677 Add tests for g.handle_paging


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/bcd41c9c
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/bcd41c9c
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/bcd41c9c

Branch: refs/heads/master
Commit: bcd41c9c99059f95adf9e891c4ab5e0001d57658
Parents: f2baa55
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Nov 10 13:26:31 2014 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Nov 19 22:58:32 2014 +0000

----------------------------------------------------------------------
 Allura/allura/tests/test_globals.py | 50 +++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/bcd41c9c/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 5dc0e43..85eeb37 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -23,7 +23,7 @@ import os
 import allura
 import unittest
 import hashlib
-from mock import patch
+from mock import patch, Mock
 
 from bson import ObjectId
 from nose.tools import with_setup, assert_equal, assert_in, assert_not_in
@@ -726,3 +726,51 @@ class TestCachedMarkdown(unittest.TestCase):
         self.assertIsNone(self.post.text_cache.md5)
         self.assertIsNone(self.post.text_cache.html)
         self.assertIsNone(self.post.text_cache.render_time)
+
+
+
+class TestHandlePaging(unittest.TestCase):
+
+    def setUp(self):
+        prefs = {}
+        c.user = Mock()
+        def get_pref(name):
+            return prefs.get(name)
+        def set_pref(name, value):
+            prefs[name] = value
+        c.user.get_pref = get_pref
+        c.user.set_pref = set_pref
+
+    def test_with_limit(self):
+        self.assertEqual(g.handle_paging(10, 0), (10, 0, 0))
+        self.assertEqual(g.handle_paging(10, 2), (10, 2, 20))
+        # handle paging must not mess up user preferences
+        self.assertEqual(c.user.get_pref('results_per_page'), None)
+
+    def test_without_limit(self):
+        # default limit = 50
+        self.assertEqual(g.handle_paging(None, 0), (50, 0, 0))
+        self.assertEqual(g.handle_paging(None, 2), (50, 2, 100))
+        # handle paging must not mess up user preferences
+        self.assertEqual(c.user.get_pref('results_per_page'), None)
+
+        # user has page size preference
+        c.user.set_pref('results_per_page', 100)
+        self.assertEqual(g.handle_paging(None, 0), (100, 0, 0))
+        self.assertEqual(g.handle_paging(None, 2), (100, 2, 200))
+        # handle paging must not mess up user preferences
+        self.assertEqual(c.user.get_pref('results_per_page'), 100)
+
+    def test_without_limit_with_default(self):
+        # default limit is not used when explicitly provided
+        self.assertEqual(g.handle_paging(None, 0, 30), (30, 0, 0))
+        self.assertEqual(g.handle_paging(None, 2, 30), (30, 2, 60))
+        # handle paging must not mess up user preferences
+        self.assertEqual(c.user.get_pref('results_per_page'), None)
+
+        # user has page size preference, which is not affected by default
+        c.user.set_pref('results_per_page', 25)
+        self.assertEqual(g.handle_paging(None, 0, 30), (25, 0, 0))
+        self.assertEqual(g.handle_paging(None, 2, 30), (25, 2, 50))
+        # handle paging must not mess up user preferences
+        self.assertEqual(c.user.get_pref('results_per_page'), 25)


Mime
View raw message