Commits

Olemis Lang committed b02f8db

BH Multiproduct #355 : Bug fixed : Overwrite existing product config option

Comments (0)

Files changed (1)

t355/t355_r1442601_trac_test_env_cmp_enabled.diff

 # Parent 25f5af82c0ce83f1318165a3a2ffce8bdc4f705d
 BH Multiproduct #355 : ProductEnvironment.is_conponent_enabled enhanced to cope with trac.* built-in components
 
+diff -r 25f5af82c0ce bloodhound_multiproduct/multiproduct/config.py
+--- a/bloodhound_multiproduct/multiproduct/config.py	Thu Feb 07 14:50:28 2013 +0000
++++ b/bloodhound_multiproduct/multiproduct/config.py	Fri Feb 08 03:21:30 2013 -0500
+@@ -298,7 +298,7 @@
+                 setting.delete()
+             else:
+                 # Update existing record
+-                setting.value = value
++                setting._data['value'] = value
+                 setting.update()
+ 
+     # Helper methods
+diff -r 25f5af82c0ce bloodhound_multiproduct/multiproduct/dbcursor.py
+--- a/bloodhound_multiproduct/multiproduct/dbcursor.py	Thu Feb 07 14:50:28 2013 +0000
++++ b/bloodhound_multiproduct/multiproduct/dbcursor.py	Fri Feb 08 03:21:30 2013 -0500
+@@ -65,6 +65,8 @@
+                                                                  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):
 diff -r 25f5af82c0ce bloodhound_multiproduct/multiproduct/env.py
 --- a/bloodhound_multiproduct/multiproduct/env.py	Thu Feb 07 14:50:28 2013 +0000
-+++ b/bloodhound_multiproduct/multiproduct/env.py	Fri Feb 08 00:51:50 2013 -0500
-@@ -117,6 +117,40 @@
++++ b/bloodhound_multiproduct/multiproduct/env.py	Fri Feb 08 03:21:30 2013 -0500
+@@ -117,6 +117,42 @@
          except OperationalError:
              pass
  
-+    def enable_component_in_config(self, cls):
++    @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.
 +        """
-+        self.config['components'].set(self._component_name(cls), 'enabled')
-+        self.enabled.clear()
-+        self.components.pop(cls, None)
++        env.config['components'].set(env._component_name(cls), 'enabled')
++        env.enabled.clear()
++        env.components.pop(cls, None)
 +        try:
-+            del self._rules
++            del env._rules
 +        except AttributeError:
 +            pass
 +        # FIXME: Shall we ?
-+        #self.config.save()
++        #env.config.save()
 +
-+    def disable_component_in_config(self, component):
++    @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.
 +            cls = component
 +        else:
 +            cls = component.__class__
-+        self.config['components'].set(self._component_name(cls), 'disabled')
-+        self.enabled.clear()
-+        self.components.pop(cls, None)
++        env.config['components'].set(env._component_name(cls), 'disabled')
++        env.enabled.clear()
++        env.components.pop(cls, None)
 +        try:
-+            del self._rules
++            del env._rules
 +        except AttributeError:
 +            pass
 +        # FIXME: Shall we ?
-+        #self.config.save()
++        #env.config.save()
 +
      def reset_db(self, default_data=None):
          from multiproduct.api import DB_VERSION
          schema_version = -1
-@@ -127,6 +161,7 @@
+@@ -127,6 +163,7 @@
              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 +372,7 @@
+@@ -337,7 +374,7 @@
          `None`, the component only gets activated if it is located in
          the `plugins` directory of the environment.
          """
              return False
          return self.is_component_enabled_local(cls)
  
+diff -r 25f5af82c0ce bloodhound_multiproduct/tests/config.py
+--- a/bloodhound_multiproduct/tests/config.py	Thu Feb 07 14:50:28 2013 +0000
++++ b/bloodhound_multiproduct/tests/config.py	Fri Feb 08 03:21:30 2013 -0500
+@@ -188,6 +188,12 @@
+             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')
 diff -r 25f5af82c0ce bloodhound_multiproduct/tests/env.py
 --- a/bloodhound_multiproduct/tests/env.py	Thu Feb 07 14:50:28 2013 +0000
-+++ b/bloodhound_multiproduct/tests/env.py	Fri Feb 08 00:51:50 2013 -0500
++++ b/bloodhound_multiproduct/tests/env.py	Fri Feb 08 03:21:30 2013 -0500
 @@ -38,6 +38,8 @@
  from trac.env import Environment
  from trac.test import EnvironmentStub
          self.env = None
          self.product_env = None
  
-@@ -303,53 +314,84 @@
+@@ -303,53 +314,99 @@
  
          global_env = self.env
          product_env = self.product_env
 -        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
  
 -        clear_component_rules(global_env)
 -        clear_component_rules(product_env)
 +            # cls initially disabled in both envs
-+            global_env.disable_component_in_config(cls)
-+            product_env.disable_component_in_config(cls)
++            disable_component_in_config(global_env, cls)
++            disable_component_in_config(product_env, cls)
  
 -        # C enabled in product env but not in global env
 -        product_env.enable_component(C)
 +                }
 +            self.assertEquals(expected_rules, global_env._component_rules)
 +            self.assertEquals(expected_rules, product_env._component_rules)
+ 
+-        clear_component_rules(global_env)
+-        clear_component_rules(product_env)
 +            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)
  
--        clear_component_rules(global_env)
--        clear_component_rules(product_env)
-+            # cls enabled in product env but not in global env
-+            global_env.disable_component_in_config(cls)
-+            expected_rules[cname] = False
-+            self.assertEquals(expected_rules, global_env._component_rules)
-+            product_env.enable_component_in_config(cls)
- 
 -        # C enabled in both envs
 -        product_env.enable_component(C)
 -        global_env.enable_component(C)
 -        self.assertTrue(product_env.is_component_enabled_local(C))
 -        self.assertIsNot(global_env[C], None)
 -        self.assertIsNot(product_env[C], 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)
+ 
+-        clear_component_rules(global_env)
+-        clear_component_rules(product_env)
 +            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)
- 
--        clear_component_rules(global_env)
--        clear_component_rules(product_env)
-+            # cls enabled in both envs
-+            global_env.enable_component_in_config(cls)
-+            product_env.enable_component_in_config(cls)
-+            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)
  
 -        # C enabled in global env but not in product env
 -        global_env.enable_component(C)
 -        self.assertFalse(product_env.is_component_enabled_local(C))
 -        self.assertIsNot(global_env[C], None)
 -        self.assertIs(product_env[C], None)
++            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
-+            global_env.enable_component_in_config(cls)
-+            product_env.disable_component_in_config(cls)
++            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)
 +
 +        # Test the rules against custom , external component
 +        _test_component_enabled(C)
++
 +        # Test the rules against Trac component class
 +        _test_component_enabled(TicketModule)