Commits

Anonymous committed 9e9304a Draft

Dashboard code import: BH_Dashboard: TicketReportWidget test cases 100% ok in Trac=0.11

PS: As a side-effect XmlRpcPlugin added as testing dependency and used in test case code

Comments (0)

Files changed (5)

bhdashboard/api.py

                 if param_spec.get('required'):
                     raise InvalidWidgetArgument(p,
                             "Required parameter expected")
+                elif param_spec.get('default') is not None :
+                    return param_spec['default']
+                else:
+                    return None
         return (get_and_check(param) for param in params)
 
 # Maybe it is better to move these to a separate file 

bhdashboard/tests/__init__.py

       db = self.env.get_db_cnx()
       cursor = db.cursor()
       for table in db_default.schema:
-        if trac_version < (0, 13) : # FIXME: Should it be (0, 12)
+        if trac_version < (0, 13) : # FIXME: Should it be (0, 12) ?
             cursor.execute("DELETE FROM " + table.name)
         else:
             cursor.execute("DROP TABLE " + table.name)
         except InvalidIdentifier:
           self.partial_setup()
 
+  # Load trac built-in components and RPC handlers by default
+  default_packages = ['trac']
+
 #------------------------------------------------------
 #    Helper functions used in test cases
 #------------------------------------------------------

bhdashboard/tests/test_report.py

   l = MultiTestLoader(
         [defaultTestLoader, \
           DocTestWidgetLoader(extraglobs=magic_vars, \
-                            enable=['trac.[a-uw-z]*', 'bhdashboard.*'], \
+                            enable=['trac.[a-uw-z]*', 'tracrpc.*', \
+                                        'bhdashboard.*'], \
                             default_data=True, \
-                            optionflags=ELLIPSIS | # REPORT_UDIFF | \
+                            optionflags=ELLIPSIS | REPORT_UDIFF | \
                                         NORMALIZE_WHITESPACE) \
         ])
   
                   'type': <type 'int'>}}
       """,
     '|TicketReport: Render My Tickets report' : r"""
-      >>> widget.render_widget('TicketReport', ctx, {
+
+      # Add tickets
+      >>> from tracrpc.ticket import TicketRPC
+      >>> tcktrpc = TicketRPC(env)
+      >>> for td in ticket_data :
+      ...   tcktrpc.create(auth_req, *td)
+      ... 
+      1
+      2
+      3
+      4
+      5
+      6
+      7
+      8
+      9
+
+      >>> if all(tcktrpc.get(auth_req, tid)[-1].get('status') == 'new' \
+      ...            for tid in xrange(1, 10)):
+      ...   # RPC considers ticket workflow
+      ...   prepare_ticket_workflow(tcktrpc, ticket_data, auth_req)
+      ...
+      
+      # Check everything is ok with tickets
+      >>> for tid in xrange(1, 10):
+      ...   d = tcktrpc.get(auth_req, tid)[-1]
+      ...   print tuple(d.get(attr) or '' for attr in TICKET_ATTRS)
+      (u'Ticket 1', u'Description 1', u'major', u'milestone1', 
+          u'defect', u'murphy', u'accepted', u'component1', u'1.0')
+      (u'Ticket 2', u'Description 2', u'major', u'milestone4', 
+          u'task', u'murphy', u'accepted', '', '')
+      (u'Ticket 3', u'Description 3', u'critical', u'milestone3', 
+          u'enhancement', u'tester', u'new', '', u'2.0')
+      (u'Ticket 4', u'Description 4', u'minor', u'milestone3', 
+          u'task', u'murphy', u'closed', u'component1', u'1.0')
+      (u'Ticket 5', u'Description 5', u'minor', u'milestone3', 
+          u'task', u'murphy', u'new', '', u'2.0')
+      (u'Ticket 6', u'Description 6', u'minor', u'milestone1', 
+          u'task', u'tester', u'assigned', u'component2', u'1.0')
+      (u'Ticket 7', u'Description 7', u'critical', '', u'enhancement', 
+          u'murphy', u'closed', '', '')
+      (u'Ticket 8', u'Description 8', u'major', '', u'task', 
+          u'murphy', u'closed', u'component1', '')
+      (u'Ticket 9', u'Description 9', u'minor', '', u'enhancement', 
+          u'tester', u'closed', '', u'2.0')
+
+      >>> pprint(widget.render_widget('TicketReport', ctx, {
       ...     'args' : {'id' : 7}
-      ...   })
+      ...   }))
       ...
+      ('widget_grid.html', [], <Context >)
+
+      >>> pprint(widget.render_widget('TicketReport', auth_ctx, {
+      ...     'args' : {'id' : 7}
+      ...   }))
+      ...
+      ('widget_grid.html',
+       [{u'__color__': u'3',
+         u'__group__': u'Accepted',
+         u'_changetime': ...,
+         u'_description': u'Description 1',
+         u'_reporter': u'murphy',
+         u'component': u'component1',
+         u'created': ...,
+         u'milestone': u'milestone1',
+         u'priority': u'major',
+         u'summary': u'Ticket 1',
+         u'ticket': 1,
+         u'type': u'defect',
+         u'version': u'1.0'},
+        {u'__color__': u'3',
+         u'__group__': u'Accepted',
+         u'_changetime': ...,
+         u'_description': u'Description 2',
+         u'_reporter': u'murphy',
+         u'component': None,
+         u'created': ...,
+         u'milestone': u'milestone4',
+         u'priority': u'major',
+         u'summary': u'Ticket 2',
+         u'ticket': 2,
+         u'type': u'task',
+         u'version': None},
+        {u'__color__': u'4',
+         u'__group__': u'Owned',
+         u'_changetime': ...,
+         u'_description': u'Description 5',
+         u'_reporter': u'murphy',
+         u'component': None,
+         u'created': ...,
+         u'milestone': u'milestone3',
+         u'priority': u'minor',
+         u'summary': u'Ticket 5',
+         u'ticket': 5,
+         u'type': u'task',
+         u'version': u'2.0'}],
+       <Context >)
       """,
     '|TicketReport: Render a subset of My Tickets report' : r"""
-      >>> widget.render_widget('TicketReport', ctx, {
-      ...     'args' : {'id' : 7}
-      ...   })
+
+      # Add tickets
+      >>> from tracrpc.ticket import TicketRPC
+      >>> tcktrpc = TicketRPC(env)
+      >>> for td in ticket_data :
+      ...   tcktrpc.create(auth_req, *td)
+      ... 
+      1
+      2
+      3
+      4
+      5
+      6
+      7
+      8
+      9
+
+      >>> if all(tcktrpc.get(auth_req, tid)[-1].get('status') == 'new' \
+      ...            for tid in xrange(1, 10)):
+      ...   # RPC considers ticket workflow
+      ...   prepare_ticket_workflow(tcktrpc, ticket_data, auth_req)
       ...
+      
+      # Check everything is ok with tickets
+      >>> for tid in xrange(1, 10):
+      ...   d = tcktrpc.get(auth_req, tid)[-1]
+      ...   print tuple(d.get(attr) or '' for attr in TICKET_ATTRS)
+      (u'Ticket 1', u'Description 1', u'major', u'milestone1', 
+          u'defect', u'murphy', u'accepted', u'component1', u'1.0')
+      (u'Ticket 2', u'Description 2', u'major', u'milestone4', 
+          u'task', u'murphy', u'accepted', '', '')
+      (u'Ticket 3', u'Description 3', u'critical', u'milestone3', 
+          u'enhancement', u'tester', u'new', '', u'2.0')
+      (u'Ticket 4', u'Description 4', u'minor', u'milestone3', 
+          u'task', u'murphy', u'closed', u'component1', u'1.0')
+      (u'Ticket 5', u'Description 5', u'minor', u'milestone3', 
+          u'task', u'murphy', u'new', '', u'2.0')
+      (u'Ticket 6', u'Description 6', u'minor', u'milestone1', 
+          u'task', u'tester', u'assigned', u'component2', u'1.0')
+      (u'Ticket 7', u'Description 7', u'critical', '', u'enhancement', 
+          u'murphy', u'closed', '', '')
+      (u'Ticket 8', u'Description 8', u'major', '', u'task', 
+          u'murphy', u'closed', u'component1', '')
+      (u'Ticket 9', u'Description 9', u'minor', '', u'enhancement', 
+          u'tester', u'closed', '', u'2.0')
+
+      >>> pprint(widget.render_widget('TicketReport', auth_ctx, {
+      ...     'args' : {'id' : 7, 'limit' : 2}
+      ...   }))
+      ...
+      ('widget_grid.html',
+       [{u'__color__': u'3',
+         u'__group__': u'Accepted',
+         u'_changetime': ...,
+         u'_description': u'Description 1',
+         u'_reporter': u'murphy',
+         u'component': u'component1',
+         u'created': ...,
+         u'milestone': u'milestone1',
+         u'priority': u'major',
+         u'summary': u'Ticket 1',
+         u'ticket': 1,
+         u'type': u'defect',
+         u'version': u'1.0'},
+        {u'__color__': u'3',
+         u'__group__': u'Accepted',
+         u'_changetime': ...,
+         u'_description': u'Description 2',
+         u'_reporter': u'murphy',
+         u'component': None,
+         u'created': ...,
+         u'milestone': u'milestone4',
+         u'priority': u'major',
+         u'summary': u'Ticket 2',
+         u'ticket': 2,
+         u'type': u'task',
+         u'version': None}],
+       <Context >)
       """,
     '|TicketReport: Invalid widget name' : r"""
       >>> widget.render_widget('OlkswSk', ctx, {
       InvalidWidgetArgument: Invalid argument `id`. Required parameter expected
 
       >>> widget.render_widget('TicketReport', ctx, {
-      ...     'args' : {}
+      ...     'args' : {'limit' : 4}
       ...   })
       ...
       Traceback (most recent call last):
       InvalidWidgetArgument: Invalid argument `id`. Required parameter expected
       """,
     '|TicketReport: Invalid widget parameter' : r"""
-      >>> widget.render_widget('TicketReport', ctx, {
-      ...     'args' : {'newjums' : 7, 'id' : 3}
-      ...   })
+
+      # Add tickets
+      >>> from tracrpc.ticket import TicketRPC
+      >>> tcktrpc = TicketRPC(env)
+      >>> for td in ticket_data :
+      ...   tcktrpc.create(auth_req, *td)
+      ... 
+      1
+      2
+      3
+      4
+      5
+      6
+      7
+      8
+      9
+
+      >>> if all(tcktrpc.get(auth_req, tid)[-1].get('status') == 'new' \
+      ...            for tid in xrange(1, 10)):
+      ...   # RPC considers ticket workflow
+      ...   prepare_ticket_workflow(tcktrpc, ticket_data, auth_req)
       ...
+      
+      # Check everything is ok with tickets
+      >>> for tid in xrange(1, 10):
+      ...   d = tcktrpc.get(auth_req, tid)[-1]
+      ...   print tuple(d.get(attr) or '' for attr in TICKET_ATTRS)
+      (u'Ticket 1', u'Description 1', u'major', u'milestone1', 
+          u'defect', u'murphy', u'accepted', u'component1', u'1.0')
+      (u'Ticket 2', u'Description 2', u'major', u'milestone4', 
+          u'task', u'murphy', u'accepted', '', '')
+      (u'Ticket 3', u'Description 3', u'critical', u'milestone3', 
+          u'enhancement', u'tester', u'new', '', u'2.0')
+      (u'Ticket 4', u'Description 4', u'minor', u'milestone3', 
+          u'task', u'murphy', u'closed', u'component1', u'1.0')
+      (u'Ticket 5', u'Description 5', u'minor', u'milestone3', 
+          u'task', u'murphy', u'new', '', u'2.0')
+      (u'Ticket 6', u'Description 6', u'minor', u'milestone1', 
+          u'task', u'tester', u'assigned', u'component2', u'1.0')
+      (u'Ticket 7', u'Description 7', u'critical', '', u'enhancement', 
+          u'murphy', u'closed', '', '')
+      (u'Ticket 8', u'Description 8', u'major', '', u'task', 
+          u'murphy', u'closed', u'component1', '')
+      (u'Ticket 9', u'Description 9', u'minor', '', u'enhancement', 
+          u'tester', u'closed', '', u'2.0')
+
+      >>> pprint(widget.render_widget('TicketReport', auth_ctx, {
+      ...     'args' : {'newjums' : 7, 'id' : 7, 'limit' : 1}
+      ...   }))
+      ...
+      ('widget_grid.html',
+       [{u'__color__': u'3',
+         u'__group__': u'Accepted',
+         u'_changetime': ...,
+         u'_description': u'Description 1',
+         u'_reporter': u'murphy',
+         u'component': u'component1',
+         u'created': ...,
+         u'milestone': u'milestone1',
+         u'priority': u'major',
+         u'summary': u'Ticket 1',
+         u'ticket': 1,
+         u'type': u'defect',
+         u'version': u'1.0'}],
+       <Context >)
       """,
     '|TicketReport: Invalid report definition' : r"""
       >>> raise NotImplementedError()

bhdashboard/widgets/report.py

 """
 
 from datetime import datetime, date, time
-from itertools import imap
+from itertools import imap, islice
 
 from trac.core import implements, TracError
 from trac.ticket.report import ReportModule
             rptid, limit = self.bind_params(name, options, 'id', 'limit')
             metadata = self.get(req, rptid)
             # TODO: Should metadata also contain columns definition ?
-            data = list(self.execute(req, rptid))
+            data = list(self.execute(req, rptid, limit))
         except TracError, exc:
             if metadata is not None :
                 exc.title = metadata.get('title', 'TracReports')
                 exc.title = 'TracReports'
             raise
         else:
-            return 'widget_grid', data, context
+            return 'widget_grid.html', data, context
 
     render_widget = pretty_wrapper(render_widget, check_widget_name)
 
                 kwargs = dict(limit=limit)
             except AttributeError:
                 # Legacy exec (<=0.10)
-                exec_proc = repmdl.execute_report
+                if limit > 0:
+                    exec_proc = lambda *args, **kwargs: \
+                        islice(repmdl.execute_report(*args, **kwargs), limit)
+                else:
+                    exec_proc = repmdl.execute_report
                 kwargs = {}
             return exec_proc(req, db, id, sql, args, **kwargs)[:2]
         except Exception, e:
     version=latest,
     description=DESC.split('\n', 1)[0],
     requires = ['trac'],
-    tests_require = ['dutest>=0.2.4'],
+    tests_require = ['dutest>=0.2.4', 'TracXMLRPC'],
     install_requires = [
         'setuptools>=0.6b1',
         'Trac>=0.11',