1. Olemis Lang
  2. bloodhound-mq

Commits

Olemis Lang  committed 93bcf90

BH Multiproduct #492 : Test cases for milestone resources and neighborhoods

  • Participants
  • Parent commits 990a644
  • Branches t492_product_resources

Comments (0)

Files changed (1)

File t492/t492_r1464573_product_neighborhoods.diff

View file
 
 diff -r 95b401d89137 bloodhound_multiproduct/multiproduct/api.py
 --- a/bloodhound_multiproduct/multiproduct/api.py	Fri Apr 05 12:14:45 2013 -0500
-+++ b/bloodhound_multiproduct/multiproduct/api.py	Fri Apr 05 15:25:36 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/api.py	Fri Apr 05 16:06:48 2013 -0500
 @@ -28,9 +28,10 @@
  from trac.config import Option, PathOption
  from trac.core import Component, TracError, implements, Interface
      short_syntax_delimiter = u'->'
 diff -r 95b401d89137 bloodhound_multiproduct/multiproduct/env.py
 --- a/bloodhound_multiproduct/multiproduct/env.py	Fri Apr 05 12:14:45 2013 -0500
-+++ b/bloodhound_multiproduct/multiproduct/env.py	Fri Apr 05 15:25:36 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/env.py	Fri Apr 05 16:06:48 2013 -0500
 @@ -878,6 +878,7 @@
          else:
              global_env = env
          elif isinstance(env, ProductEnvironment) and \
 diff -r 95b401d89137 bloodhound_multiproduct/tests/resource.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/tests/resource.py	Fri Apr 05 15:25:36 2013 -0500
-@@ -0,0 +1,201 @@
++++ b/bloodhound_multiproduct/tests/resource.py	Fri Apr 05 16:06:48 2013 -0500
+@@ -0,0 +1,227 @@
 +# -*- coding: utf-8 -*-
 +#
 +#  Licensed to the Apache Software Foundation (ASF) under one
 +
 +from trac.attachment import Attachment
 +from trac import resource 
++import trac.ticket.report       # report resources ?
++import trac.ticket.roadmap      # milestone resources
 +
 +from multiproduct.api import MultiProductSystem
 +from multiproduct.env import ProductEnvironment
 +class ProductMilestoneResourceTestCase(ProductResourceTestCase):
 +    resource = resource.Resource('milestone', 'milestone1')
 +
-+    def test_global_neighborhood_ticket(self):
-+        raise NotImplementedError()
++    def test_global_neighborhood_milestone(self):
++        target = resource.Neighborhood('global', None).child(self.resource)
 +
-+    def test_product_neighborhood_ticket(self):
-+        raise NotImplementedError()
++        self.assertEquals("[global:] Milestone milestone1", 
++                          resource.get_resource_description(self.env, target))
++        self.assertEquals("[global:] Milestone milestone1", 
++                          resource.get_resource_name(self.env, target))
++        self.assertEquals("milestone1", 
++                          resource.get_resource_shortname(self.env, target))
++        self.assertEquals("[global:] Milestone milestone1", 
++                          resource.get_resource_summary(self.env, target))
++        self.assertEquals('http://example.org/trac.cgi/milestone/milestone1', 
++                          resource.get_resource_url(self.env, 
++                                                    target, self.env.href))
++
++    def test_product_neighborhood_milestone(self):
++        target = resource.Neighborhood('product', u'xü').child(self.resource)
++
++        self.assertEquals(u"[product:xü] Milestone milestone1", 
++                          resource.get_resource_description(self.env, target))
++        self.assertEquals(u"[product:xü] Milestone milestone1", 
++                          resource.get_resource_name(self.env, target))
++        self.assertEquals(u"milestone1", 
++                          resource.get_resource_shortname(self.env, target))
++        self.assertEquals(u"[product:xü] Milestone milestone1", 
++                          resource.get_resource_summary(self.env, target))
++        self.assertEquals('http://example.org/trac.cgi/products/x%C3%BC/milestone/milestone1', 
++                          resource.get_resource_url(self.env, 
++                                                    target, self.env.href))
 +
 +
 +# FIXME: No resource manager for reports in core ?
 +    unittest.main(defaultTest='test_suite')
 diff -r 95b401d89137 trac/trac/attachment.py
 --- a/trac/trac/attachment.py	Fri Apr 05 12:14:45 2013 -0500
-+++ b/trac/trac/attachment.py	Fri Apr 05 15:25:36 2013 -0500
-@@ -666,17 +666,26 @@
++++ b/trac/trac/attachment.py	Fri Apr 05 16:06:48 2013 -0500
+@@ -666,17 +666,22 @@
      def get_resource_description(self, resource, format=None, **kwargs):
          if not resource.parent:
              return _("Unparented attachment %(id)s", id=resource.id)
-+        if resource.neighborhood is not None:
-+            # Absolute resource ID
-+            nbhprefix = '[%s:%s] ' % (_(resource.neighborhood._realm), 
-+                                      resource.neighborhood._id or '')
-+        else:
-+            nbhprefix = ''
++        nbhprefix = ResourceSystem(self.env).neighborhood_prefix(
++                resource.neighborhood)
          if format == 'compact':
 -            return '%s (%s)' % (resource.id,
 +            return '%s%s (%s)' % (nbhprefix, resource.id,
          try:
 diff -r 95b401d89137 trac/trac/resource.py
 --- a/trac/trac/resource.py	Fri Apr 05 12:14:45 2013 -0500
-+++ b/trac/trac/resource.py	Fri Apr 05 15:25:36 2013 -0500
-@@ -650,11 +650,14 @@
++++ b/trac/trac/resource.py	Fri Apr 05 16:06:48 2013 -0500
+@@ -540,6 +540,11 @@
+         target = rsys.load_component_manager(neighborhood, compmgr)
+         return rsys if target is compmgr else (componentclass or cls)(target)
+ 
++    def neighborhood_prefix(self, neighborhood):
++        return '' if neighborhood is None \
++                  else '[%s:%s] ' % (neighborhood._realm,
++                                     neighborhood._id or '') 
++
+     # -- Utilities to trigger resources event notifications
+ 
+     def resource_created(self, resource, context=None):
+@@ -650,11 +655,12 @@
          manager = rsys.get_resource_manager(resource.realm)
          if manager and hasattr(manager, 'get_resource_description'):
              return manager.get_resource_description(resource, format, **kwargs)
 -    name = u'%s:%s' % (resource.realm, resource.id)
-+    nbhprefix = '' if resource.neighborhood is None \
-+                 else '[%s:%s] ' % (resource.neighborhood._realm,
-+                                   resource.neighborhood._id or '') 
++    nbhprefix = rsys.neighborhood_prefix(resource.neighborhood) 
 +
 +    name = u'%s%s:%s' % (nbhprefix, resource.realm, resource.id)
      if format == 'summary':
      return name
  
  def get_resource_name(env, resource):
+diff -r 95b401d89137 trac/trac/ticket/roadmap.py
+--- a/trac/trac/ticket/roadmap.py	Fri Apr 05 12:14:45 2013 -0500
++++ b/trac/trac/ticket/roadmap.py	Fri Apr 05 16:06:48 2013 -0500
+@@ -933,9 +933,11 @@
+ 
+     def get_resource_description(self, resource, format=None, context=None,
+                                  **kwargs):
++        nbhprefix = ResourceSystem(self.env).neighborhood_prefix(
++                resource.neighborhood)
+         desc = resource.id
+         if format != 'compact':
+-            desc =  _('Milestone %(name)s', name=resource.id)
++            desc =  nbhprefix + _('Milestone %(name)s', name=resource.id)
+         if context:
+             return self._render_link(context, resource.id, desc)
+         else: