Commits

Olemis Lang committed 990a644

BH Multiproduct #492 : Test cases for report resources and neighborhoods. Skeleton for milestone resource test case

Comments (0)

Files changed (1)

t492/t492_r1464573_product_neighborhoods.diff

 
 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 13:45:41 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/api.py	Fri Apr 05 15:25:36 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 13:45:41 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/env.py	Fri Apr 05 15:25:36 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 13:45:41 2013 -0500
-@@ -0,0 +1,164 @@
++++ b/bloodhound_multiproduct/tests/resource.py	Fri Apr 05 15:25:36 2013 -0500
+@@ -0,0 +1,201 @@
 +# -*- coding: utf-8 -*-
 +#
 +#  Licensed to the Apache Software Foundation (ASF) under one
 +        self.global_env.reset_db()
 +        self.global_env = self.env = None
 +
++
 +class ProductAttachmentResourceTestCase(ProductResourceTestCase):
 +    def setUp(self):
 +        ProductResourceTestCase.setUp(self)
 +        if os.path.exists(self.global_env.path):
 +            shutil.rmtree(self.global_env.path)
 +        os.mkdir(self.global_env.path)
-+        for env in (self.global_env, self.env1):
++        for i, env in enumerate([self.global_env, self.env1]):
 +            attachment = Attachment(env, 'ticket', 1)
-+            attachment.description = 'Bar'
++            attachment.description = 'Bar ' + str(i)
 +            attachment.insert('foo.txt', StringIO(''), 0)
 +        self.resource = resource.Resource('ticket', 
 +                                          1).child('attachment', 'foo.txt')
 +                          resource.get_resource_name(self.env, target))
 +        self.assertEquals("[global:] foo.txt (Ticket #1)", 
 +                          resource.get_resource_shortname(self.env, target))
-+        self.assertEquals('Bar', 
++        self.assertEquals('Bar 0', 
 +                          resource.get_resource_summary(self.env, target))
 +        self.assertEquals('http://example.org/trac.cgi/attachment/ticket/1/foo.txt', 
 +                          resource.get_resource_url(self.env, 
 +                          resource.get_resource_name(self.env, target))
 +        self.assertEquals(u"[product:xü] foo.txt (Ticket #1)", 
 +                          resource.get_resource_shortname(self.env, target))
-+        self.assertEquals('Bar', 
++        self.assertEquals('Bar 1', 
 +                          resource.get_resource_summary(self.env, target))
 +        self.assertEquals('http://example.org/trac.cgi/products/x%C3%BC/attachment/ticket/1/foo.txt', 
 +                          resource.get_resource_url(self.env, 
 +                                                    target, self.env.href))
 +
++
++class ProductMilestoneResourceTestCase(ProductResourceTestCase):
++    resource = resource.Resource('milestone', 'milestone1')
++
++    def test_global_neighborhood_ticket(self):
++        raise NotImplementedError()
++
++    def test_product_neighborhood_ticket(self):
++        raise NotImplementedError()
++
++
++# FIXME: No resource manager for reports in core ?
 +class ProductReportResourceTestCase(ProductResourceTestCase):
-+    def setUp(self):
-+        pass
-+
-+    def tearDown(self):
-+        pass
++    resource = resource.Resource('report', 1)
 +
 +    def test_global_neighborhood_report(self):
-+        raise NotImplementedError()
++        target = resource.Neighborhood('global', None).child(self.resource)
++
++        self.assertEquals("[global:] report:1", 
++                          resource.get_resource_description(self.env, target))
++        self.assertEquals("[global:] report:1", 
++                          resource.get_resource_name(self.env, target))
++        self.assertEquals("[global:] report:1", 
++                          resource.get_resource_shortname(self.env, target))
++        self.assertEquals('[global:] report:1 at version None', 
++                          resource.get_resource_summary(self.env, target))
++        self.assertEquals('http://example.org/trac.cgi/report/1', 
++                          resource.get_resource_url(self.env, 
++                                                    target, self.env.href))
 +
 +    def test_product_neighborhood_report(self):
-+        raise NotImplementedError()
++        target = resource.Neighborhood('product', u'xü').child(self.resource)
++
++        self.assertEquals(u"[product:xü] report:1", 
++                          resource.get_resource_description(self.env, target))
++        self.assertEquals(u"[product:xü] report:1", 
++                          resource.get_resource_name(self.env, target))
++        self.assertEquals(u"[product:xü] report:1", 
++                          resource.get_resource_shortname(self.env, target))
++        self.assertEquals(u"[product:xü] report:1 at version None", 
++                          resource.get_resource_summary(self.env, target))
++        self.assertEquals('http://example.org/trac.cgi/products/x%C3%BC/report/1', 
++                          resource.get_resource_url(self.env, 
++                                                    target, self.env.href))
++
 +
 +class ProductTicketResourceTestCase(ProductResourceTestCase):
 +    def setUp(self):
 +    def test_product_neighborhood_ticket(self):
 +        raise NotImplementedError()
 +
++
 +class ProductVcsResourceTestCase(ProductResourceTestCase):
 +    def setUp(self):
 +        pass
 +    def test_product_neighborhood_versioncontrol(self):
 +        raise NotImplementedError()
 +
++
 +class ProductWikiResourceTestCase(ProductResourceTestCase):
 +    def setUp(self):
 +        pass
 +def test_suite():
 +    return unittest.TestSuite([
 +        unittest.makeSuite(ProductAttachmentResourceTestCase, 'test'),
++        unittest.makeSuite(ProductMilestoneResourceTestCase, 'test'),
 +        unittest.makeSuite(ProductReportResourceTestCase, 'test'),
 +        unittest.makeSuite(ProductTicketResourceTestCase, 'test'),
 +        unittest.makeSuite(ProductVcsResourceTestCase, 'test'),
 +    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 13:45:41 2013 -0500
++++ b/trac/trac/attachment.py	Fri Apr 05 15:25:36 2013 -0500
 @@ -666,17 +666,26 @@
      def get_resource_description(self, resource, format=None, **kwargs):
          if not resource.parent:
          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 13:45:41 2013 -0500
-@@ -654,7 +654,9 @@
++++ b/trac/trac/resource.py	Fri Apr 05 15:25:36 2013 -0500
+@@ -650,11 +650,14 @@
+         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 '') 
++
++    name = u'%s%s:%s' % (nbhprefix, resource.realm, resource.id)
      if format == 'summary':
          name = _('%(name)s at version %(version)s',
-                  name=name, version=resource.version) + \
+-                 name=name, version=resource.version) + \
 -               '' if resource.neighborhood is None else _(' (external)') 
-+               ('' if resource.neighborhood is None \
-+                   else '[%s:%s]' % (resource.neighborhood._realm,
-+                                     resource.neighborhood._id)) 
++                 name=name, version=resource.version)
      return name
  
  def get_resource_name(env, resource):