[test] test page_size problem (related to #8123231)
authorArthur Lutz <arthur.lutz@logilab.fr>
Wed, 04 Nov 2015 12:04:33 +0100
changeset 10827 768d332de17b
parent 10826 dff28956f37e
child 10828 0e5a9a03a79d
[test] test page_size problem (related to #8123231)
test/unittest_predicates.py
--- a/test/unittest_predicates.py	Wed Nov 04 11:26:22 2015 +0100
+++ b/test/unittest_predicates.py	Wed Nov 04 12:04:33 2015 +0100
@@ -26,8 +26,9 @@
 from cubicweb import Binary
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.predicates import (is_instance, adaptable, match_kwargs, match_user_groups,
-                                multi_lines_rset, score_entity, is_in_state,
-                                rql_condition, relation_possible, match_form_params)
+                                 multi_lines_rset, score_entity, is_in_state,
+                                 rql_condition, relation_possible, match_form_params,
+                                 paginated_rset)
 from cubicweb.selectors import on_transition # XXX on_transition is deprecated
 from cubicweb.view import EntityAdapter
 from cubicweb.web import action
@@ -487,6 +488,33 @@
         self.assertEqual(str(cm.exception),
                          "match_form_params() positional arguments must be strings")
 
+class PaginatedTC(CubicWebTC):
+    """tests for paginated_rset predicate"""
+
+    def setup_database(self):
+        with self.admin_access.repo_cnx() as cnx:
+            for i in xrange(30):
+                cnx.execute('INSERT CWGroup G: G name "group{}"'.format(i))
+            cnx.commit()
+
+    def test_paginated_rset(self):
+        default_nb_pages = 1
+        web_request = self.admin_access.web_request
+        with web_request() as req:
+            rset = req.execute('Any G WHERE G is CWGroup')
+        self.assertEqual(len(rset), 34)
+        with web_request(vid='list', page_size='10') as req:
+            self.assertEqual(paginated_rset()(None, req, rset), default_nb_pages)
+        with web_request(vid='list', page_size='20') as req:
+            self.assertEqual(paginated_rset()(None, req, rset), default_nb_pages)
+        with web_request(vid='list', page_size='50') as req:
+            self.assertEqual(paginated_rset()(None, req, rset), 0)
+        with web_request(vid='list', page_size='10/') as req:
+            self.assertEqual(paginated_rset()(None, req, rset), 0)
+        with web_request(vid='list', page_size='.1') as req:
+            self.assertEqual(paginated_rset()(None, req, rset), 0)
+        with web_request(vid='list', page_size='not_an_int') as req:
+            self.assertEqual(paginated_rset()(None, req, rset), 0)
 
 if __name__ == '__main__':
     unittest_main()