incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1444707 - in /incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct: multiproduct/config.py multiproduct/dbcursor.py multiproduct/env.py tests/config.py tests/env.py
Date Mon, 11 Feb 2013 10:04:31 GMT
Author: jure
Date: Mon Feb 11 10:04:31 2013
New Revision: 1444707

URL: http://svn.apache.org/r1444707
Log:
#355, patch t355_r1442601_trac_test_env_cmp_enabled.diff (from Olemis) applied, improve algorithm
to determine whether component is enabled/disabled in product scope


Modified:
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/config.py
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py
    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/config.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/config.py?rev=1444707&r1=1444706&r2=1444707&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/config.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/config.py
Mon Feb 11 10:04:31 2013
@@ -298,7 +298,7 @@ class Section(Section):
                 setting.delete()
             else:
                 # Update existing record
-                setting.value = value
+                setting._data['value'] = value
                 setting.update()
 
     # Helper methods

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py?rev=1444707&r1=1444706&r2=1444707&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/dbcursor.py
Mon Feb 11 10:04:31 2013
@@ -65,6 +65,8 @@ class BloodhoundIterableCursor(trac.db.u
                                                                  TRANSLATE_TABLES,
                                                                  PRODUCT_COLUMN,
                                                                  product_prefix)
+        if self.log:
+            self.log.debug('Original SQl: %s', sql)
         return self._translator.translate(sql) if (self._translator is not None) else sql
 
     def execute(self, sql, args=None):

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=1444707&r1=1444706&r2=1444707&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
Mon Feb 11 10:04:31 2013
@@ -117,6 +117,42 @@ class EnvironmentStub(trac.test.Environm
         except OperationalError:
             pass
 
+    @staticmethod
+    def enable_component_in_config(env, cls):
+        """Keep track of enabled state in configuration as well 
+        during test runs. This is closer to reality than 
+        inherited `enable_component` method.
+        """
+        env.config['components'].set(env._component_name(cls), 'enabled')
+        env.enabled.clear()
+        env.components.pop(cls, None)
+        try:
+            del env._rules
+        except AttributeError:
+            pass
+        # FIXME: Shall we ?
+        #env.config.save()
+
+    @staticmethod
+    def disable_component_in_config(env, component):
+        """Keep track of disabled state in configuration as well 
+        during test runs. This is closer to reality than 
+        inherited `disable_component` method.
+        """
+        if isinstance(component, type):
+            cls = component
+        else:
+            cls = component.__class__
+        env.config['components'].set(env._component_name(cls), 'disabled')
+        env.enabled.clear()
+        env.components.pop(cls, None)
+        try:
+            del env._rules
+        except AttributeError:
+            pass
+        # FIXME: Shall we ?
+        #env.config.save()
+
     def reset_db(self, default_data=None):
         from multiproduct.api import DB_VERSION
         schema_version = -1
@@ -127,6 +163,7 @@ class EnvironmentStub(trac.test.Environm
             with self.db_direct_transaction as db:
                 self.mpsystem._update_db_version(db, DB_VERSION)
 
+
 # replace trac.test.EnvironmentStub
 trac.test.EnvironmentStub = EnvironmentStub
 
@@ -337,7 +374,7 @@ class ProductEnvironment(Component, Comp
         `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):
+        if self.parent[cls] is None:
             return False
         return self.is_component_enabled_local(cls)
 

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=1444707&r1=1444706&r2=1444707&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
Mon Feb 11 10:04:31 2013
@@ -188,6 +188,12 @@ class ProductConfigTestCase(Configuratio
             self.assertEquals(u"Voilà l'été", config2.get('a', 'option2'))
         self._test_with_inherit(testcb)
 
+    def test_overwrite(self):
+        config = self._read()
+        config.set('a', 'option', 'value1')
+        self.assertEquals('value1', config.get('a', 'option'))
+        config.set('a', 'option', 'value2')
+        self.assertEquals('value2', config.get('a', 'option'))
 
 def test_suite():
     return unittest.makeSuite(ProductConfigTestCase,'test')

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=1444707&r1=1444706&r2=1444707&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
Mon Feb 11 10:04:31 2013
@@ -38,6 +38,8 @@ from trac.core import Component
 from trac.env import Environment
 from trac.test import EnvironmentStub
 from trac.tests.env import EnvironmentTestCase
+from trac.ticket.report import ReportModule
+from trac.ticket.web_ui import TicketModule
 
 from multiproduct.api import MultiProductSystem
 from multiproduct.env import ProductEnvironment
@@ -159,6 +161,8 @@ class MultiproductTestCase(unittest.Test
     def _upgrade_mp(self, env):
         r"""Apply multi product upgrades
         """
+        env.disable_component(TicketModule)
+        env.disable_component(ReportModule)
         self.mpsystem = MultiProductSystem(env)
         try:
             self.mpsystem.upgrade_environment(env.db_transaction)
@@ -215,6 +219,13 @@ class ProductEnvApiTestCase(Multiproduct
 
     def tearDown(self):
         # Release reference to transient environment mock object
+        if self.env is not None:
+            try:
+                self.env.reset_db()
+            except OperationalError:
+                # "Database not found ...",
+                # "OperationalError: no such table: system" or the like
+                pass
         self.env = None
         self.product_env = None
 
@@ -303,53 +314,102 @@ class ProductEnvApiTestCase(Multiproduct
 
         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 _test_component_enabled(cls):
+            cname = global_env._component_name(cls)
+            disable_component_in_config = global_env.disable_component_in_config
+            enable_component_in_config = global_env.enable_component_in_config
+
+            # cls initially disabled in both envs
+            disable_component_in_config(global_env, cls)
+            disable_component_in_config(product_env, cls)
+
+            expected_rules = {
+                    'multiproduct' : True,
+                    'trac' : True,
+                    'trac.db' : True,
+                    cname : False,
+                }
+            self.assertEquals(expected_rules, global_env._component_rules)
+            self.assertEquals(expected_rules, product_env._component_rules)
+
+            self.assertFalse(global_env.is_component_enabled(cls))
+            self.assertFalse(product_env.is_component_enabled_local(cls))
+            self.assertIs(global_env[cls], None)
+            self.assertIs(product_env[cls], None)
+
+            # cls enabled in product env but not in global env
+            disable_component_in_config(global_env, cls)
+            enable_component_in_config(product_env, cls)
+
+            expected_rules[cname] = False
+            self.assertEquals(expected_rules, global_env._component_rules)
+            expected_rules[cname] = True
+            self.assertEquals(expected_rules, product_env._component_rules)
+
+            self.assertFalse(global_env.is_component_enabled(cls))
+            self.assertTrue(product_env.is_component_enabled_local(cls))
+            self.assertIs(global_env[cls], None)
+            self.assertIs(product_env[cls], None)
+
+            # cls enabled in both envs
+            enable_component_in_config(global_env, cls)
+            enable_component_in_config(product_env, cls)
+
+            expected_rules[cname] = True
+            self.assertEquals(expected_rules, global_env._component_rules)
+            expected_rules[cname] = True
+            self.assertEquals(expected_rules, product_env._component_rules)
+
+            self.assertTrue(global_env.is_component_enabled(cls))
+            self.assertTrue(product_env.is_component_enabled_local(cls))
+            self.assertIsNot(global_env[cls], None)
+            self.assertIsNot(product_env[cls], None)
+
+            # cls enabled in global env but not in product env
+            enable_component_in_config(global_env, cls)
+            disable_component_in_config(product_env, cls)
+
+            expected_rules[cname] = True
+            self.assertEquals(expected_rules, global_env._component_rules)
+            expected_rules[cname] = False
+            self.assertEquals(expected_rules, product_env._component_rules)
+
+            self.assertTrue(global_env.is_component_enabled(cls))
+            self.assertFalse(product_env.is_component_enabled_local(cls))
+            self.assertIsNot(global_env[cls], None)
+            self.assertIs(product_env[cls], None)
+
+        # Test the rules against custom , external component
+        _test_component_enabled(C)
+
+        for env in (global_env, product_env):
+            env.config.remove('components', env._component_name(C))
+
+         # Test the rules against Trac component class
+        _test_component_enabled(TicketModule)
 
     def test_path(self):
         """Testing env.path"""
         self.assertEqual(self.product_env.path, 
                 os.path.join(self.env.path, 'products', self.default_product))
 
+    def test_env_config_inheritance(self):
+        """Testing env.config"""
+        global_config = self.env.config
+        product_config = self.product_env.config
+
+        # By default inherit global settings ...
+        global_config['section'].set('key', 'value1')
+        self.assertEquals('value1', global_config['section'].get('key'))
+        self.assertEquals('value1', product_config['section'].get('key'))
+
+        # ... but allow for overrides in product scope
+        product_config['section'].set('key', 'value2')
+        self.assertEquals('value1', global_config['section'].get('key'))
+        self.assertEquals('value2', product_config['section'].get('key'))
+
+
 def test_suite():
     return unittest.TestSuite([
             unittest.makeSuite(ProductEnvTestCase,'test'),



Mime
View raw message