incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1433893 - in /incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct: multiproduct/env.py tests/config.py tests/env.py
Date Wed, 16 Jan 2013 10:51:48 GMT
Author: jure
Date: Wed Jan 16 10:51:48 2013
New Revision: 1433893

URL: http://svn.apache.org/viewvc?rev=1433893&view=rev
Log:
Applied #350 patch t350_r1433322_product_component_enable.diff (from olemis)


Modified:
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/config.py
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py?rev=1433893&r1=1433892&r2=1433893&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/env.py
Wed Jan 16 10:51:48 2013
@@ -29,6 +29,7 @@ from trac.util.compat import sha1
 from trac.versioncontrol import RepositoryManager
 from trac.web.href import Href
 
+from multiproduct.config import Configuration
 from multiproduct.model import Product
 from multiproduct.dbcursor import BloodhoundIterableCursor
 
@@ -129,7 +130,7 @@ class ProductEnvironment(Component, Comp
         get_log_dir, backup
         """
         try:
-            if attrnm == 'parent':
+            if attrnm in ('parent', '_rules'):
                 raise AttributeError
             return getattr(self.parent, attrnm)
         except AttributeError:
@@ -281,7 +282,23 @@ class ProductEnvironment(Component, Comp
     enable_component = trac.env.Environment.enable_component.im_func
     get_known_users = trac.env.Environment.get_known_users.im_func
     get_repository = trac.env.Environment.get_repository.im_func
-    is_component_enabled = trac.env.Environment.is_component_enabled.im_func
+
+    is_component_enabled_local = trac.env.Environment.is_component_enabled.im_func
+
+    def is_component_enabled(self, cls):
+        """Implemented to only allow activation of components already 
+        activated in the global environment that are in turn not disabled in
+        the configuration.
+
+        This is called by the `ComponentManager` base class when a
+        component is about to be activated. If this method returns
+        `False`, the component does not get activated. If it returns
+        `None`, the component only gets activated if it is located in
+        the `plugins` directory of the environment.
+        """
+        if not self.parent.is_component_enabled(cls):
+            return False
+        return self.is_component_enabled_local(cls)
 
     def get_db_cnx(self):
         """Return a database connection from the connection pool
@@ -427,8 +444,8 @@ class ProductEnvironment(Component, Comp
     def setup_config(self):
         """Load the configuration object.
         """
-        # FIXME: Install product-specific configuration object
-        self.config = self.parent.config
+        # FIXME: Inherit global environment setting ?
+        self.config = Configuration(self.parent, self.product.prefix)
         self.setup_log()
 
     def setup_log(self):

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/config.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/config.py?rev=1433893&r1=1433892&r2=1433893&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/config.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/config.py
Wed Jan 16 10:51:48 2013
@@ -189,9 +189,9 @@ class ProductConfigTestCase(Configuratio
         self._test_with_inherit(testcb)
 
 
-def suite():
+def test_suite():
     return unittest.makeSuite(ProductConfigTestCase,'test')
 
 if __name__ == '__main__':
-    unittest.main(defaultTest='suite')
+    unittest.main(defaultTest='test_suite')
 

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py?rev=1433893&r1=1433892&r2=1433893&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/tests/env.py
Wed Jan 16 10:51:48 2013
@@ -34,6 +34,7 @@ else:
     from unittest.case import _AssertRaisesContext
 
 from trac.config import Option
+from trac.core import Component
 from trac.env import Environment
 from trac.test import EnvironmentStub
 from trac.tests.env import EnvironmentTestCase
@@ -209,6 +210,7 @@ class ProductEnvApiTestCase(Multiproduct
         self.product_env = ProductEnvironment(self.env, self.default_product)
 
     def test_attr_forward_parent(self):
+        """Testing env.__getattr__"""
         class EnvironmentAttrSandbox(EnvironmentStub):
             """Limit the impact of class edits so as to avoid race conditions
             """
@@ -258,7 +260,7 @@ class ProductEnvApiTestCase(Multiproduct
 
         for attrnm in 'component_activated _component_rules ' \
                 'enable_component get_known_users get_repository ' \
-                'is_component_enabled _component_name'.split():
+                '_component_name'.split():
             original = getattr(Environment, attrnm)
             if isinstance(original, MethodType):
                 translation = getattr(self.product_env, attrnm)
@@ -272,6 +274,7 @@ class ProductEnvApiTestCase(Multiproduct
                         "'%s' property differs in product env" % (attrnm,))
 
     def test_typecheck(self):
+        """Testing env.__init__"""
         self._load_product_from_data(self.env, 'tp2')
         with self.assertRaises(TypeError) as cm_test:
             new_env = ProductEnvironment(self.product_env, 'tp2')
@@ -282,6 +285,57 @@ class ProductEnvApiTestCase(Multiproduct
                 "(got multiproduct.env.ProductEnvironment instance instead)"
         self.assertEqual(msg, expected_msg)
 
+    def test_component_enable(self):
+        """Testing env.is_component_enabled"""
+        class C(Component):
+            pass
+        # Let's pretend this was declared elsewhere
+        C.__module__ = 'dummy_module'
+
+        global_env = self.env
+        product_env = self.product_env
+        
+        def clear_component_rules(env):
+            del env._rules
+            env.enabled.clear()
+
+        # C initially disabled in both envs
+        self.assertFalse(global_env.is_component_enabled(C))
+        self.assertFalse(product_env.is_component_enabled_local(C))
+        self.assertIs(global_env[C], None)
+        self.assertIs(product_env[C], None)
+
+        clear_component_rules(global_env)
+        clear_component_rules(product_env)
+
+        # C enabled in product env but not in global env
+        product_env.enable_component(C)
+        self.assertFalse(global_env.is_component_enabled(C))
+        self.assertTrue(product_env.is_component_enabled_local(C))
+        self.assertIs(global_env[C], None)
+        self.assertIs(product_env[C], None)
+
+        clear_component_rules(global_env)
+        clear_component_rules(product_env)
+
+        # C enabled in both envs
+        product_env.enable_component(C)
+        global_env.enable_component(C)
+        self.assertTrue(global_env.is_component_enabled(C))
+        self.assertTrue(product_env.is_component_enabled_local(C))
+        self.assertIsNot(global_env[C], None)
+        self.assertIsNot(product_env[C], None)
+
+        clear_component_rules(global_env)
+        clear_component_rules(product_env)
+
+        # C enabled in global env but not in product env
+        global_env.enable_component(C)
+        self.assertTrue(global_env.is_component_enabled(C))
+        self.assertFalse(product_env.is_component_enabled_local(C))
+        self.assertIsNot(global_env[C], None)
+        self.assertIs(product_env[C], None)
+
     def tearDown(self):
         # Release reference to transient environment mock object
         self.env = None



Mime
View raw message