Commits

Anonymous committed 774ea22 Draft

Dashboard code import: BH_Dashboard: Test cases passing using Trac=0.13

Comments (0)

Files changed (3)

bhdashboard/tests/__init__.py

   def enable_component(self, clsdef):
     r"""Enable a plugin temporarily at testing time.
     """
-    if clsdef not in self.enabled_components :
-      self.enabled_components.append(clsdef)
+    if trac_version <= (0.13):      # Check whether this should be 0.12 instead
+      # `enabled_components` should be enough in this case
+      if clsdef not in self.enabled_components :
+        self.enabled_components.append(clsdef)
+    else:
+      # Use environment configuration otherwise
+      raise NotImplementedError("TODO: Enable components in Trac>=0.13")
 
   def disable_component(self, clsdef):
     r"""Disable a plugin temporarily at testing time.
     """
-    try:
-      self.enabled_components.remove(clsdef)
-    except ValueError :
-      self.log.warning("Component %s was not enabled", clsdef)
+    if trac_version < (0, 13):
+      try:
+        self.enabled_components.remove(clsdef)
+      except ValueError :
+        self.log.warning("Component %s was not enabled", clsdef)
+    else:
+      # Use environment configuration otherwise
+      raise NotImplementedError("TODO: Disable components in Trac>=0.13")
 
   def rip_component(self, cls):
     r"""Disable a plugin forever and RIP it using the super-laser beam.
 from bhdashboard.util import dummy_request
 
 # Hide this module from tracebacks written into test results.
-__unittest = False
+__unittest = True
 
 class DocTestTracLoader(DocTestLoader):
   r"""A generic XUnit loader that allows to load doctests written 
 
   def __init__(self, dt_finder=None, globs=None, extraglobs=None, \
                           load=None, default_data=False, enable=None, \
-                          **opts):
+                          disable=None, **opts):
     r"""Initialization. It basically works like `DocTestLoader`'s 
     initializer but creates also the Trac environment used for 
     testing purposes. The default behavior is to create an instance 
                             components need to be enabled by default 
                             at testing time. This parameter should be 
                             handled by `createTracEnv` method.
+    @param disable          a list of UNIX patterns specifying which 
+                            components need to be disabled by default 
+                            at testing time. Ignored in Trac<=0.11 .
+                            This parameter should be 
+                            handled by `createTracEnv` method.
     """
     super(DocTestTracLoader, self).__init__(dt_finder, globs, \
                                               extraglobs, **opts)
+    if trac_version >= (0, 13) :
+        opts['disable'] = disable
     self.env = self.createTracEnv(default_data, enable, **opts)
     self.load_components(load is None and self.default_packages or load)
 
   # Load trac built-in components by default
   default_packages = ['trac']
 
-  def createTracEnv(self, default_data=False, enable=None, **params):
+  def createTracEnv(self, default_data=False, enable=None, 
+      disable=None, **params):
     r"""Create the Trac environment used for testing purposes. The 
     default behavior is to create an instance of `EnvironmentStub` 
     class. Subclasses can override this decision and add more specific 
     @param enable           a list of UNIX patterns specifying which 
                             components need to be enabled by default 
                             at testing time.
+    @param disable          a list of UNIX patterns specifying which 
+                            components need to be disabled by default 
+                            at testing time. Ignored in Trac<0.13
     @return                 the environment used for testing purpose.
     """
-    return EnvironmentStub(default_data, enable)
+    if trac_version >= (0, 13):
+      kwargs = {'disable' : disable}
+    else :
+      kwargs = {}
+    return EnvironmentStub(default_data, enable, **kwargs)
 
   def load_components(self, pkgs):
     r"""Load some packages to ensure that the components they 
       running the doctests. Besides, clean up environment data and 
       include only default data.
       """
+      from pprint import pprint
+      from trac.core import ComponentMeta
+
       globs = self.globalns
       req = self.new_request(args=dict())
       auth_req = self.new_request(uname=self.username, args=dict())

bhdashboard/tests/test_report.py

   from doctest import NORMALIZE_WHITESPACE, ELLIPSIS, REPORT_UDIFF
   from dutest import MultiTestLoader
   from unittest import defaultTestLoader
-  
-  from __init__ import DocTestWidgetLoader, ticket_data
-  
+
+  from bhdashboard.tests import DocTestWidgetLoader, ticket_data, trac_version
+
   magic_vars = dict(ticket_data=ticket_data)
+  if trac_version < (0, 13): # FIXME: Should it be (0, 12) ?
+    kwargs = {'enable': ['trac.[a-uw-z]*', 'tracrpc.*', 'bhdashboard.*']}
+  else:
+    kwargs = {
+            'enable': ['trac.*', 'tracrpc.*', 'bhdashboard.*'],
+            'disable': ['trac.versioncontrol.*']
+        }
+
   l = MultiTestLoader(
         [defaultTestLoader, \
           DocTestWidgetLoader(extraglobs=magic_vars, \
-                            enable=['trac.[a-uw-z]*', 'tracrpc.*', \
-                                        'bhdashboard.*'], \
                             default_data=True, \
                             optionflags=ELLIPSIS | REPORT_UDIFF | \
-                                        NORMALIZE_WHITESPACE) \
+                                        NORMALIZE_WHITESPACE, \
+                            **kwargs) \
         ])
-  
+
   import sys
   return l.loadTestsFromModule(sys.modules[__name__])
 
   ticket workflow. Needed for TracRpc>=1.0.6
   """
   from time import sleep
-  
+
   TICKET_ACTIONS = {'accepted': 'accept', 'closed' : 'resolve',
                     'assigned': 'reassign'}
   sleep(1)
       """,
     '|TicketReport: Render My Tickets report' : r"""
 
-      # Add tickets
+      Add tickets
+
       >>> from tracrpc.ticket import TicketRPC
       >>> tcktrpc = TicketRPC(env)
       >>> for td in ticket_data :
       ...   # RPC considers ticket workflow
       ...   prepare_ticket_workflow(tcktrpc, ticket_data, auth_req)
       ...
-      
-      # Check everything is ok with tickets
+
+      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', 
       ...     'args' : {'id' : 7}
       ...   }))
       ...
-      ('widget_grid.html', [], <Context >)
+      ('widget_grid.html', [], <...Context >)
 
-      >>> pprint(widget.render_widget('TicketReport', auth_ctx, {
+      >>> template, data, rptctx = 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 >)
+      >>> template
+      'widget_grid.html'
+
+      In Trac=0.13 (0.12 ?) My Tickets report adds another group
+      So perform common check in here.
+
+      >>> pprint([x for x in data if x.get('__group__') != 'Reported'])
+      [{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'}]
+      >>> rptctx is auth_ctx
+      True
       """,
     '|TicketReport: Render a subset of My Tickets report' : r"""
 
-      # Add tickets
+      Add tickets
+
       >>> from tracrpc.ticket import TicketRPC
       >>> tcktrpc = TicketRPC(env)
       >>> for td in ticket_data :
       ...   # RPC considers ticket workflow
       ...   prepare_ticket_workflow(tcktrpc, ticket_data, auth_req)
       ...
-      
-      # Check everything is ok with tickets
+
+      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': 2,
          u'type': u'task',
          u'version': None}],
-       <Context >)
+       <...Context >)
       """,
     '|TicketReport: Invalid widget name' : r"""
       >>> widget.render_widget('OlkswSk', ctx, {
       """,
     '|TicketReport: Invalid widget parameter' : r"""
 
-      # Add tickets
+      Add tickets
+
       >>> from tracrpc.ticket import TicketRPC
       >>> tcktrpc = TicketRPC(env)
       >>> for td in ticket_data :
       ...   # RPC considers ticket workflow
       ...   prepare_ticket_workflow(tcktrpc, ticket_data, auth_req)
       ...
-      
-      # Check everything is ok with tickets
+
+      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'type': u'defect',
          u'version': u'1.0'}],
-       <Context >)
+       <...Context >)
       """,
     '|TicketReport: Invalid report definition' : r"""
       >>> raise NotImplementedError()

bhdashboard/widgets/report.py

                           been granted to the client performing the 
                           request. Otherwise it is empty.
         """
-        if 'REPORT_SQL_VIEW' in req.perm:
-            sql = "SELECT id,title,query,description from report " \
-                   "WHERE id=%s" % (id,)
-        else :
-            sql = "SELECT id,title,NULL,description from report " \
-                   "WHERE id=%s" % (id,)
+        sql = "SELECT id,title,query,description from report " \
+                "WHERE id=%s" % (id,)
         db = self.env.get_db_cnx()
         cursor = db.cursor()
         try: