1. Olemis Lang
  2. bloodhound-mq

Commits

Olemis Lang  committed 45dfb01

BH Multiproduct #115 : Unicode strings , options and further minor enhancements ... (failures=1, errors=11)

Ran 27 tests in 2.452s

  • Participants
  • Parent commits eb81639
  • Branches t115_product_env

Comments (0)

Files changed (2)

File t115/t115_r1423431_product_envs_testing.diff

View file
  • Ignore whitespace
 
 diff -r 101ff51010dc bloodhound_multiproduct/tests/config.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/tests/config.py	Sun Jan 06 23:59:36 2013 -0500
-@@ -0,0 +1,94 @@
++++ b/bloodhound_multiproduct/tests/config.py	Mon Jan 07 01:38:36 2013 -0500
+@@ -0,0 +1,99 @@
 +
 +#  Licensed to the Apache Software Foundation (ASF) under one
 +#  or more contributor license agreements.  See the NOTICE file
 +from StringIO import StringIO
 +import unittest
 +
-+from trac.config import Option, _to_utf8
++from trac.config import Option
 +from trac.tests.config import ConfigurationTestCase
++from trac.util.text import to_unicode
 +
 +from multiproduct.api import MultiProductSystem
 +from multiproduct.config import Configuration
 +        """
 +        if product is None:
 +            product = self.default_product
++        product = to_unicode(product)
 +        fp = StringIO(('\n'.join(lines + [''])).encode('utf-8'))
 +        parser = ConfigParser()
 +        parser.readfp(fp, 'bh-product-test')
 +                setting.delete()
 +            # Insert new options
 +            for section in parser.sections():
-+                option_key = dict(section=_to_utf8(section), product=product)
++                option_key = dict(
++                        section=to_unicode(section), 
++                        product=to_unicode(product)
++                    )
 +                for option, value in parser.items(section):
-+                    option_key.update(dict(option=_to_utf8(option)))
++                    option_key.update(dict(option=to_unicode(option)))
 +                    setting = ProductSetting(self.env)
 +                    setting._data.update(option_key)
-+                    setting._data['value'] = _to_utf8(value)
++                    setting._data['value'] = to_unicode(value)
 +                    setting.insert()
 +
 +def suite():
 +
 diff -r 101ff51010dc bloodhound_multiproduct/tests/env.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/tests/env.py	Sun Jan 06 23:59:36 2013 -0500
++++ b/bloodhound_multiproduct/tests/env.py	Mon Jan 07 01:38:36 2013 -0500
 @@ -0,0 +1,139 @@
 +
 +#  Licensed to the Apache Software Foundation (ASF) under one

File t115/t115_r1427886_product_config.diff

View file
  • Ignore whitespace
 
 diff -r 56bf5ca5136d bloodhound_dashboard/bhdashboard/model.py
 --- a/bloodhound_dashboard/bhdashboard/model.py	Sun Jan 06 12:53:47 2013 -0500
-+++ b/bloodhound_dashboard/bhdashboard/model.py	Sun Jan 06 22:52:47 2013 -0500
++++ b/bloodhound_dashboard/bhdashboard/model.py	Mon Jan 07 01:40:49 2013 -0500
 @@ -117,8 +117,9 @@
                  self._update_from_row(row)
                  break
      
      def delete(self):
          """Deletes the matching record from the database"""
-@@ -207,7 +208,7 @@
+@@ -151,7 +152,8 @@
+                                      for k in self._meta['unique_fields']])}
+         if sdata:
+             sdata.update(self._meta)
+-            raise TracError('%(object_name)s %(keys)s already exists' %
++            sdata['values'] = self._data
++            raise TracError('%(object_name)s %(keys)s already exists %(values)s' %
+                             sdata)
+             
+         for key in self._meta['key_fields']:
+@@ -207,7 +209,7 @@
              TicketSystem(self._env).reset_ticket_fields()
      
      @classmethod
          """Query the database to get a set of records back"""
          rows = []
          fields = cls._meta['key_fields']+cls._meta['non_key_fields']
-@@ -218,7 +219,11 @@
+@@ -218,7 +220,11 @@
          wherestr, values = dict_to_kv_str(where)
          if wherestr:
              wherestr = ' WHERE ' + wherestr
              data = dict([(fields[i], row[i]) for i in range(len(fields))])
 diff -r 56bf5ca5136d bloodhound_multiproduct/multiproduct/api.py
 --- a/bloodhound_multiproduct/multiproduct/api.py	Sun Jan 06 12:53:47 2013 -0500
-+++ b/bloodhound_multiproduct/multiproduct/api.py	Sun Jan 06 22:52:47 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/api.py	Mon Jan 07 01:40:49 2013 -0500
 @@ -31,9 +31,9 @@
  from trac.util.translation import _, N_
  from trac.web.chrome import ITemplateProvider
      def get_version(self):
 diff -r 56bf5ca5136d bloodhound_multiproduct/multiproduct/config.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/multiproduct/config.py	Sun Jan 06 22:52:47 2013 -0500
-@@ -0,0 +1,279 @@
++++ b/bloodhound_multiproduct/multiproduct/config.py	Mon Jan 07 01:40:49 2013 -0500
+@@ -0,0 +1,291 @@
 +
 +#  Licensed to the Apache Software Foundation (ASF) under one
 +#  or more contributor license agreements.  See the NOTICE file
 +import os.path
 +
 +from trac.config import Configuration, ConfigurationError, Option, Section, \
-+        _to_utf8, _use_default
++        _use_default
++from trac.resource import ResourceNotFound
 +from trac.util.text import to_unicode
 +
 +from multiproduct.model import ProductSetting
 +        """
 +        self.env = env
 +        self.parents = (parents or []) + [self.env.config]
-+        self.product = product
++        self.product = to_unicode(product)
 +        self._sections = {}
 +
 +    def __getitem__(self, name):
 +        for section, default_options in self.defaults(compmgr).items():
 +            for name, value in default_options.items():
 +                if not ProductSetting.exists(self.env, self.product,
-+                        _to_utf8(section), _to_utf8(name)):
++                        section, name):
 +                    if any(parent[section].contains(name, defaults=False)
 +                           for parent in self.parents):
 +                        value = None
 +
 +    def __init__(self, config, name):
 +        self.config = config
-+        self.name = name
++        self.name = to_unicode(name)
 +        self.overridden = {}
 +        self._cache = {}
 +
 +        return self.config.product
 +
 +    def contains(self, key, defaults=True):
-+        if ProductSetting.exists(self.env, self.product, 
-+                _to_utf8(self.name), _to_utf8(key)):
++        key = to_unicode(key)
++        if ProductSetting.exists(self.env, self.product, self.name, key):
 +            return True
 +        for parent in self.config.parents:
 +            if parent[self.name].contains(key, defaults=False):
 +        components that are enabled in the given `ComponentManager`.
 +        """
 +        options = set()
-+        name_str = _to_utf8(self.name)
++        name_str = self.name
 +        for setting in ProductSetting.select(self.env,
 +                where={'product':self.product, 'section':name_str}):
 +            option = to_unicode(setting.option)
 +        cached = self._cache.get(key, _use_default)
 +        if cached is not _use_default:
 +            return cached
-+        name_str = _to_utf8(self.name)
-+        key_str = _to_utf8(key)
++        name_str = self.name
++        key_str = to_unicode(key)
 +        settings = ProductSetting.select(self.env, 
 +                where={'product':self.product, 'section':name_str,
 +                        'option':key_str})
 +
 +        Like for `set()`, the changes won't persist until `save()` gets called.
 +        """
++        key_str = to_unicode(key)
 +        option_key = {
 +                'product' : self.product, 
-+                'section' : _to_utf8(self.name),
-+                'option' : _to_utf8(key),
++                'section' : self.name,
++                'option' : key_str,
 +            }
-+        setting = ProductSetting(self.env, keys=option_key)
-+        if settings._exists:
++        try:
++            setting = ProductSetting(self.env, keys=option_key)
++        except ResourceNotFound:
++            self.env.log.warning("No record for product option %s", option_key)
++        else:
 +            self._cache.pop(key, None)
 +            settings.delete()
++            self.env.log.info("Removing product option %s", option_key)
 +
 +    def set(self, key, value):
 +        """Change a configuration value.
 +
 +        These changes will be persistent right away.
 +        """
-+        self._cache.pop(key, None)
++        key_str = to_unicode(key)
++        value_str = value
++        self._cache.pop(key_str, None)
 +        option_key = {
 +                'product' : self.product, 
-+                'section' : _to_utf8(self.name),
-+                'option' : _to_utf8(key),
++                'section' : self.name,
++                'option' : key_str,
 +            }
-+        setting = ProductSetting(self.env)
-+        setting._data.update(option_key)
-+
-+        if setting._exists :
++        try:
++            setting = ProductSetting(self.env, option_key)
++        except ResourceNotFound:
++            if value is not None:
++                # Insert new record in the database
++                setting = ProductSetting(self.env)
++                setting._data.update(option_key)
++                setting._data['value'] = value_str
++                self.env.log.debug('Writing option %s', setting._data)
++                setting.insert()
++        else:
 +            if value is None:
 +                # Delete existing record from the database
++                # FIXME : Why bother with setting overriden
 +                self.overridden[key] = True
 +                setting.delete()
 +            else:
 +                # Update existing record
-+                setting.value = _to_utf8(value)
++                setting.value = value
 +                setting.update()
-+        elif value is not None:
-+            # Insert new record in the database
-+            setting.value = _to_utf8(value)
-+            setting.insert()
 +
 diff -r 56bf5ca5136d bloodhound_multiproduct/multiproduct/model.py
 --- a/bloodhound_multiproduct/multiproduct/model.py	Sun Jan 06 12:53:47 2013 -0500
-+++ b/bloodhound_multiproduct/multiproduct/model.py	Sun Jan 06 22:52:47 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/model.py	Mon Jan 07 01:40:49 2013 -0500
 @@ -18,6 +18,7 @@
  
  """Models to support multi-product"""