Commits

Olemis Lang  committed 0c5ff81

BH Multiproduct #438 : Improve handling of component managers in extension points

  • Participants
  • Parent commits dc8055e
  • Branches t438_product_perm

Comments (0)

Files changed (2)

-t438/t438_r1456016_product_perms.diff
-t404/t404_r1456016_revert_r1449636.diff
+t438/t438_r1457691_cpmngr_xtpt.diff
+#t438/t438_r1456016_product_perms.diff
+#t404/t404_r1456016_revert_r1449636.diff

File t438/t438_r1457691_cpmngr_xtpt.diff

+# HG changeset patch
+# Parent 0332d9547db57118973276154bf214943dba1c84
+BH Multiproduct #438 : Component managers in extension points
+
+diff -r 0332d9547db5 trac/trac/core.py
+--- a/trac/trac/core.py	Mon Mar 18 09:58:11 2013 +0000
++++ b/trac/trac/core.py	Mon Mar 18 11:30:47 2013 -0500
+@@ -208,7 +208,10 @@
+         if not self.is_enabled(cls):
+             return None
+         component = self.components.get(cls)
+-        if not component:
++
++        # Leave other manager components out of extension point lists
++        # see bh:comment:5:ticket:438 and ticket:11121
++        if not component and not issubclass(cls, ComponentManager) :
+             if cls not in ComponentMeta._components:
+                 raise TracError('Component "%s" not registered' % cls.__name__)
+             try:
+diff -r 0332d9547db5 trac/trac/tests/core.py
+--- a/trac/trac/tests/core.py	Mon Mar 18 09:58:11 2013 +0000
++++ b/trac/trac/tests/core.py	Mon Mar 18 11:30:47 2013 -0500
+@@ -300,6 +300,71 @@
+         self.assertEquals('x', tests.next().test())
+         self.assertRaises(StopIteration, tests.next)
+ 
++    def test_component_manager_component_isolation(self):
++        """
++        Verify that a component manager that is also a component will only
++        be listed in extension points for components instantiated in
++        its scope.
++
++        See bh:comment:5:ticket:438 and #11121
++        """
++        from trac.core import ComponentManager
++        class ManagerComponent(ComponentManager, Component):
++            tests = ExtensionPoint(ITest)
++            def __init__(self, foo, bar):
++                ComponentManager.__init__(self)
++                self.foo, self.bar = foo, bar
++
++        class YetAnotherManagerComponent(ComponentManager, Component):
++            implements(ITest)
++            def __init__(self, foo, bar):
++                ComponentManager.__init__(self)
++                self.foo, self.bar = foo, bar
++
++            # ITest methods
++            def test(self):
++                return self.foo + self.bar
++
++        class ComponentA(Component):
++            tests = ExtensionPoint(ITest)
++
++        class Extender(Component):
++            implements(ITest)
++            def test(self):
++                return 'x'
++
++        mgr = ManagerComponent('Test', 42)
++        yamc = YetAnotherManagerComponent('y', 'z')
++
++        assert yamc[ManagerComponent] is None 
++        assert mgr[YetAnotherManagerComponent] is None 
++        assert yamc[ComponentManager] is None 
++        assert self.compmgr[YetAnotherManagerComponent] is None 
++        assert mgr[ComponentManager] is None 
++        assert self.compmgr[ManagerComponent] is None 
++
++        self.assertTrue(any(c.__class__ is YetAnotherManagerComponent
++                            for c in ComponentA(yamc).tests))
++        self.assertFalse(any(c.__class__ is YetAnotherManagerComponent
++                             for c in ComponentA(self.compmgr).tests))
++        self.assertFalse(any(c.__class__ is YetAnotherManagerComponent
++                             for c in ComponentA(mgr).tests))
++        self.assertFalse(any(c.__class__ is ManagerComponent
++                             for c in ComponentA(yamc).tests))
++        self.assertFalse(any(c.__class__ is YetAnotherManagerComponent
++                             for c in mgr.tests))
++
++        results = [test.test() for test in ComponentA(yamc).tests]
++        self.assertEquals(['x', 'yz'], sorted(results))
++
++        results = [test.test() for test in ComponentA(self.compmgr).tests]
++        self.assertEquals(['x'], sorted(results))
++
++        results = [test.test() for test in ComponentA(mgr).tests]
++        self.assertEquals(['x'], sorted(results))
++        results = [test.test() for test in mgr.tests]
++        self.assertEquals(['x'], sorted(results))
++
+     def test_instantiation_doesnt_enable(self):
+         """
+         Make sure that a component disabled by the ComponentManager is not
+@@ -315,7 +380,6 @@
+         instance = ComponentA(mgr)
+         self.assertEqual(None, mgr[ComponentA])
+ 
+-
+ def suite():
+     return unittest.makeSuite(ComponentTestCase, 'test')
+