Commits

Olemis Lang committed aef5717

BH Multiproduct #115 : Rewrite 'test_set_and_save_inherit' and 'test_set_and_save' to avoid reading config file ... [ok]

Ran 27 tests in 2.495s

  • Participants
  • Parent commits 73514a6
  • Branches t115_product_env

Comments (0)

Files changed (1)

t115/t115_r1423431_product_envs_testing.diff

 # HG changeset patch
-# Parent c6fafb51b2b92507642309cd9dee8a3978fa4873
+# Parent 3ff6f332771a5ea5c61370fcf58e51f3e520969f
 BH Theme #115 : Test cases for product environments
 
-diff -r c6fafb51b2b9 bloodhound_multiproduct/tests/config.py
+diff -r 3ff6f332771a bloodhound_multiproduct/tests/config.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/tests/config.py	Tue Jan 08 00:26:52 2013 -0500
-@@ -0,0 +1,124 @@
-+
++++ b/bloodhound_multiproduct/tests/config.py	Tue Jan 08 01:46:58 2013 -0500
+@@ -0,0 +1,197 @@
++# -*- coding: utf-8 -*-
++#
 +#  Licensed to the Apache Software Foundation (ASF) under one
 +#  or more contributor license agreements.  See the NOTICE file
 +#  distributed with this work for additional information
 +"""Tests for Apache(TM) Bloodhound's product configuration objects"""
 +
 +from ConfigParser import ConfigParser
++from itertools import groupby
 +import os.path
 +import shutil
 +from StringIO import StringIO
 +        finally:
 +            os.remove(sitename)
 +
++    def _dump_settings(self, config):
++        product = config.product
++        fields = ('section', 'option', 'value')
++        rows = [tuple(getattr(s, f, None) for f in fields) for s in 
++                ProductSetting.select(config.env, where={'product' : product})]
++
++        dump = []
++        for section, group in groupby(sorted(rows), lambda row: row[0]):
++            dump.append('[%s]\n' % (section,))
++            for row in group:
++                dump.append('%s = %s\n' % (row[1], row[2]))
++        return dump
++
++    # Test cases rewritten to avoid reading config file. 
++    # It does make sense for product config as it's stored in the database
++
++    def test_set_and_save(self):
++        config = self._read()
++        config.set('b', u'öption0', 'y')
++        config.set(u'aä', 'öption0', 'x')
++        config.set('aä', 'option2', "Voilà l'été")  # UTF-8
++        config.set(u'aä', 'option1', u"Voilà l'été") # unicode
++        # Note: the following would depend on the locale.getpreferredencoding()
++        # config.set('a', 'option3', "Voil\xe0 l'\xe9t\xe9") # latin-1
++        self.assertEquals('x', config.get(u'aä', u'öption0'))
++        self.assertEquals(u"Voilà l'été", config.get(u'aä', 'option1'))
++        self.assertEquals(u"Voilà l'été", config.get(u'aä', 'option2'))
++        config.save()
++
++        dump = self._dump_settings(config)
++        self.assertEquals([
++                           u'[aä]\n',
++                           u"option1 = Voilà l'été\n", 
++                           u"option2 = Voilà l'été\n", 
++                           u'öption0 = x\n', 
++                           # u"option3 = Voilà l'été\n", 
++                           u'[b]\n',
++                           u'öption0 = y\n', 
++                           ],
++                          dump)
++        config2 = self._read()
++        self.assertEquals('x', config2.get(u'aä', u'öption0'))
++        self.assertEquals(u"Voilà l'été", config2.get(u'aä', 'option1'))
++        self.assertEquals(u"Voilà l'été", config2.get(u'aä', 'option2'))
++        # self.assertEquals(u"Voilà l'été", config2.get('a', 'option3'))
++
++    def test_set_and_save_inherit(self):
++        def testcb():
++            config = self._read()
++            config.set('a', 'option2', "Voilà l'été")  # UTF-8
++            config.set('a', 'option1', u"Voilà l'été") # unicode
++            self.assertEquals('x', config.get('a', 'option'))
++            self.assertEquals(u"Voilà l'été", config.get('a', 'option1'))
++            self.assertEquals(u"Voilà l'été", config.get('a', 'option2'))
++            config.save()
++
++            dump = self._dump_settings(config)
++            self.assertEquals([
++                               u'[a]\n',
++                               u"option1 = Voilà l'été\n", 
++                               u"option2 = Voilà l'été\n", 
++                               u'[inherit]\n',
++                               u"file = trac-site.ini\n", 
++                               ],
++                              dump)
++            config2 = self._read()
++            self.assertEquals('x', config2.get('a', 'option'))
++            self.assertEquals(u"Voilà l'été", config2.get('a', 'option1'))
++            self.assertEquals(u"Voilà l'été", config2.get('a', 'option2'))
++        self._test_with_inherit(testcb)
++
 +
 +def suite():
 +    return unittest.makeSuite(ProductConfigTestCase,'test')
 +if __name__ == '__main__':
 +    unittest.main(defaultTest='suite')
 +
-diff -r c6fafb51b2b9 bloodhound_multiproduct/tests/env.py
+diff -r 3ff6f332771a bloodhound_multiproduct/tests/env.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/tests/env.py	Tue Jan 08 00:26:52 2013 -0500
++++ b/bloodhound_multiproduct/tests/env.py	Tue Jan 08 01:46:58 2013 -0500
 @@ -0,0 +1,139 @@
 +
 +#  Licensed to the Apache Software Foundation (ASF) under one