allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [1/6] allura git commit: [#7794] ticket:677 Add tests for g.handle_paging
Date Fri, 14 Nov 2014 11:55:49 GMT
Repository: allura
Updated Branches:
  refs/heads/ib/7794 [created] 9aba981f8


[#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/414955b1
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/414955b1
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/414955b1

Branch: refs/heads/ib/7794
Commit: 414955b124474dcf25efd6a5c8a3800d5f0ae636
Parents: 9151524
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Nov 10 13:26:31 2014 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Fri Nov 14 08:57:42 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/414955b1/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