changeset 230:c7ff953ebb07

Fix paging on build configuration page. Closes #55.
author cmlenz
date Wed, 28 Sep 2005 22:26:33 +0000
parents 796803158a30
children 4a9cf87d443f
files bitten/trac_ext/tests/web_ui.py bitten/trac_ext/web_ui.py
diffstat 2 files changed, 43 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/bitten/trac_ext/tests/web_ui.py
+++ b/bitten/trac_ext/tests/web_ui.py
@@ -39,9 +39,9 @@
                             'DefaultPermissionStore')
 
         # Hook up a dummy repository
-        repos = Mock(get_node=lambda path: Mock(get_history=lambda: []),
-                     sync=lambda: None)
-        self.env.get_repository = lambda x: repos
+        self.repos = Mock(get_node=lambda path: Mock(get_history=lambda: []),
+                          sync=lambda: None)
+        self.env.get_repository = lambda x: self.repos
 
     def tearDown(self):
         shutil.rmtree(self.env.path)
@@ -70,14 +70,21 @@
         self.assertEqual('1', req.hdf.get('config.can_create'))
 
     def test_view_config(self):
-        config = BuildConfig(self.env)
-        config.name = 'test'
+        config = BuildConfig(self.env, name='test', path='trunk')
         config.insert()
+        platform = TargetPlatform(self.env, config='test', name='any')
+        platform.insert()
 
         PermissionSystem(self.env).grant_permission('joe', 'BUILD_VIEW')
         req = Mock(Request, cgi_location='', path_info='/build/test', args={},
                    hdf=HDFWrapper(), perm=PermissionCache(self.env, 'joe'))
 
+        root = Mock(get_entries=lambda: ['foo'],
+                    get_history=lambda: [('trunk', rev, 'edit') for rev in
+                                          range(123, 111, -1)])
+        self.repos = Mock(get_node=lambda path, rev=None: root,
+                          sync=lambda: None, normalize_path=lambda path: path)
+
         module = BuildConfigController(self.env)
         assert module.match_request(req)
         module.process_request(req)
@@ -85,6 +92,30 @@
         self.assertEqual('view_config', req.hdf['page.mode'])
         self.assertEqual('0', req.hdf.get('build.config.can_delete', '0'))
         self.assertEqual('0', req.hdf.get('build.config.can_modify', '0'))
+        self.assertEqual(None, req.hdf.get('chrome.links.next.0.href'))
+
+    def test_view_config_paging(self):
+        config = BuildConfig(self.env, name='test', path='trunk')
+        config.insert()
+        platform = TargetPlatform(self.env, config='test', name='any')
+        platform.insert()
+
+        PermissionSystem(self.env).grant_permission('joe', 'BUILD_VIEW')
+        req = Mock(Request, cgi_location='', path_info='/build/test', args={},
+                   hdf=HDFWrapper(), perm=PermissionCache(self.env, 'joe'))
+
+        root = Mock(get_entries=lambda: ['foo'],
+                    get_history=lambda: [('trunk', rev, 'edit') for rev in
+                                          range(123, 110, -1)])
+        self.repos = Mock(get_node=lambda path, rev=None: root,
+                          sync=lambda: None, normalize_path=lambda path: path)
+
+        module = BuildConfigController(self.env)
+        assert module.match_request(req)
+        module.process_request(req)
+
+        self.assertEqual('/trac.cgi/build/test?page=2',
+                         req.hdf.get('chrome.links.next.0.href'))
 
     def test_view_config_admin(self):
         config = BuildConfig(self.env)
--- a/bitten/trac_ext/web_ui.py
+++ b/bitten/trac_ext/web_ui.py
@@ -354,20 +354,16 @@
         repos.sync()
         idx = 0
         for platform, rev, build in collect_changes(repos, config):
-            if idx < (page - 1) * builds_per_page:
-                idx += 1
-                continue
-
-            prefix = 'config.builds.%d' % rev
-            req.hdf[prefix + '.href'] = self.env.href.changeset(rev)
-            if build and build.status != Build.PENDING:
-                build_hdf = _build_to_hdf(self.env, req, build)
-                req.hdf['%s.%s' % (prefix, platform.id)] = build_hdf
-
-            idx += 1
             if idx >= page * builds_per_page:
                 more = True
                 break
+            elif idx > (page - 1) * builds_per_page:
+                prefix = 'config.builds.%d' % rev
+                req.hdf[prefix + '.href'] = self.env.href.changeset(rev)
+                if build and build.status != Build.PENDING:
+                    build_hdf = _build_to_hdf(self.env, req, build)
+                    req.hdf['%s.%s' % (prefix, platform.id)] = build_hdf
+            idx += 1
 
         if page > 1:
             if page == 2:
Copyright (C) 2012-2017 Edgewall Software