incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g..@apache.org
Subject svn commit: r1307961 - in /incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard: tests/__init__.py tests/test_report.py widgets/report.py
Date Sun, 01 Apr 2012 00:36:38 GMT
Author: gjm
Date: Sun Apr  1 00:36:37 2012
New Revision: 1307961

URL: http://svn.apache.org/viewvc?rev=1307961&view=rev
Log:
Dashboard code import: BH_Dashboard: Test cases passing using Trac=0.13

Modified:
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/__init__.py
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_report.py
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/report.py

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/__init__.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/__init__.py?rev=1307961&r1=1307960&r2=1307961&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/__init__.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/__init__.py Sun Apr
 1 00:36:37 2012
@@ -55,16 +55,25 @@ class EnvironmentStub(EnvironmentStub):
   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.
@@ -120,7 +129,7 @@ from types import MethodType
 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 
@@ -138,7 +147,7 @@ class DocTestTracLoader(DocTestLoader):
 
   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 
@@ -174,16 +183,24 @@ class DocTestTracLoader(DocTestLoader):
                             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 
@@ -197,9 +214,16 @@ class DocTestTracLoader(DocTestLoader):
     @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 
@@ -242,6 +266,9 @@ class DocTestTracLoader(DocTestLoader):
       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())

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_report.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_report.py?rev=1307961&r1=1307960&r2=1307961&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_report.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/tests/test_report.py Sun Apr
 1 00:36:37 2012
@@ -55,20 +55,27 @@ def test_suite():
   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__])
 
@@ -113,7 +120,7 @@ def prepare_ticket_workflow(tcktrpc, tic
   ticket workflow. Needed for TracRpc>=1.0.6
   """
   from time import sleep
-  
+
   TICKET_ACTIONS = {'accepted': 'accept', 'closed' : 'resolve',
                     'assigned': 'reassign'}
   sleep(1)
@@ -150,7 +157,8 @@ __test__ = {
       """,
     '|TicketReport: Render My Tickets report' : r"""
 
-      # Add tickets
+      Add tickets
+
       >>> from tracrpc.ticket import TicketRPC
       >>> tcktrpc = TicketRPC(env)
       >>> for td in ticket_data :
@@ -171,11 +179,13 @@ __test__ = {
       ...   # 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', 
@@ -199,57 +209,65 @@ __test__ = {
       ...     '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 :
@@ -270,8 +288,9 @@ __test__ = {
       ...   # 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)
@@ -325,7 +344,7 @@ __test__ = {
          u'ticket': 2,
          u'type': u'task',
          u'version': None}],
-       <Context >)
+       <...Context >)
       """,
     '|TicketReport: Invalid widget name' : r"""
       >>> widget.render_widget('OlkswSk', ctx, {
@@ -364,7 +383,8 @@ __test__ = {
       """,
     '|TicketReport: Invalid widget parameter' : r"""
 
-      # Add tickets
+      Add tickets
+
       >>> from tracrpc.ticket import TicketRPC
       >>> tcktrpc = TicketRPC(env)
       >>> for td in ticket_data :
@@ -385,8 +405,9 @@ __test__ = {
       ...   # 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)
@@ -427,7 +448,7 @@ __test__ = {
          u'ticket': 1,
          u'type': u'defect',
          u'version': u'1.0'}],
-       <Context >)
+       <...Context >)
       """,
     '|TicketReport: Invalid report definition' : r"""
       >>> raise NotImplementedError()

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/report.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/report.py?rev=1307961&r1=1307960&r2=1307961&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/report.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/report.py Sun Apr
 1 00:36:37 2012
@@ -93,12 +93,8 @@ class TicketReportWidget(WidgetBase):
                           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:



Mime
View raw message