Author: astaric Date: Mon May 27 14:34:12 2013 New Revision: 1486635 URL: http://svn.apache.org/r1486635 Log: Moved env creation in ProductWikiTestCase from __init__ to setUp.
Config in product environments is stored in database and should be part of the setUp method. This replaces the quickfix introduced in r1486610. Modified: bloodhound/trunk/bloodhound_multiproduct/tests/env.py bloodhound/trunk/bloodhound_multiproduct/tests/wiki/formatter.py Modified: bloodhound/trunk/bloodhound_multiproduct/tests/env.py URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/tests/env.py?rev=1486635&r1=1486634&r2=1486635&view=diff ============================================================================== --- bloodhound/trunk/bloodhound_multiproduct/tests/env.py (original) +++ bloodhound/trunk/bloodhound_multiproduct/tests/env.py Mon May 27 14:34:12 2013 @@ -47,22 +47,6 @@ from multiproduct.api import MultiProduc from multiproduct.env import ProductEnvironment from multiproduct.model import Product -# unittests in python2.7 run in the same process and share the same connection -# pool. This basically means that all tests share the same in-memory database, -# and calling reset_db in teardown methods destroys data prepared in __init__ -# of other tests. Trac tests do not do prepare data in __init__, but when run -# with a product env, which stores config values to database, this behavior -# causes multiple tests to fail. -# -# We workaround this issue by monkey patching trac's ConnectionPool. We force -# it to establish a separate connection for each DatabaseManager. -from trac.db.pool import ConnectionPool, ConnectionPoolBackend -def ConnectionPool_get_cnx(self, timeout=None): - if not hasattr(self, '_backend'): - self._backend = ConnectionPoolBackend(1) - return self._backend.get_cnx(self._connector, self._kwargs, timeout) -ConnectionPool.get_cnx = ConnectionPool_get_cnx - class ProductEnvironmentStub(ProductEnvironment): r"""A product environment slightly tweaked for testing purposes Modified: bloodhound/trunk/bloodhound_multiproduct/tests/wiki/formatter.py URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/tests/wiki/formatter.py?rev=1486635&r1=1486634&r2=1486635&view=diff ============================================================================== --- bloodhound/trunk/bloodhound_multiproduct/tests/wiki/formatter.py (original) +++ bloodhound/trunk/bloodhound_multiproduct/tests/wiki/formatter.py Mon May 27 14:34:12 2013 @@ -22,6 +22,9 @@ import os.path import re import unittest +from trac.test import Mock, MockPerm, locale_en +from trac.util.datefmt import utc +from trac.web.href import Href from trac.web.main import FakeSession from trac.wiki.tests import formatter @@ -29,42 +32,15 @@ from multiproduct.env import ProductEnvi from multiproduct.model import Product from tests.env import MultiproductTestCase -class ProductWikiTestCase(formatter.WikiTestCase, MultiproductTestCase): - maxDiff = None - @property - def env(self): - env = getattr(self, '_env', None) - if env is None: - all_test_components = [ - formatter.HelloWorldMacro, formatter.DivHelloWorldMacro, - formatter.TableHelloWorldMacro, formatter.DivCodeMacro, - formatter.DivCodeElementMacro, formatter.DivCodeStreamMacro, - formatter.NoneMacro, formatter.WikiProcessorSampleMacro, - formatter.SampleResolver] - self.global_env = self._setup_test_env( - enable=['trac.*', 'multiproduct.*'] + all_test_components - ) - self._upgrade_mp(self.global_env) - self._load_product_from_data(self.global_env, self.default_product) - prefix = self.default_product - if self.mpctx: - prefix = self.mpctx.get('setup_product', prefix) - if prefix and prefix != self.default_product: - self._load_product_from_data(self.global_env, prefix) - if prefix: - self._env = env = ProductEnvironment( - self.global_env, prefix or self.default_product) - else: - self._env = env = self.global_env - return env - @env.setter - def env(self, value): - pass +class ProductWikiTestCase(formatter.WikiTestCase, MultiproductTestCase): + maxDiff = None def setUp(self): + self._prepare_env() + self._setup_test_log(self.global_env) formatter.WikiTestCase.setUp(self) if self.context.req: @@ -79,13 +55,60 @@ class ProductWikiTestCase(formatter.Wiki prefix = self.mpctx.get('main_product', NotImplemented) if prefix is None: - self._env = self.global_env + self.env = self.global_env elif prefix is not NotImplemented \ and (self.env is self.global_env or prefix != self.env.product.prefix): - self._env = ProductEnvironment(self.global_env, prefix) + self.env = ProductEnvironment(self.global_env, prefix) # Enable multi-product components - self._env.config.set('components', 'multiproduct.*', 'enabled') + self.env.config.set('components', 'multiproduct.*', 'enabled') + + def _prepare_env(self): + all_test_components = [ + formatter.HelloWorldMacro, formatter.DivHelloWorldMacro, + formatter.TableHelloWorldMacro, formatter.DivCodeMacro, + formatter.DivCodeElementMacro, formatter.DivCodeStreamMacro, + formatter.NoneMacro, formatter.WikiProcessorSampleMacro, + formatter.SampleResolver] + self.global_env = self._setup_test_env( + enable=['trac.*', 'multiproduct.*'] + all_test_components + ) + + self._upgrade_mp(self.global_env) + self._load_product_from_data(self.global_env, self.default_product) + prefix = self.default_product + if self.mpctx: + prefix = self.mpctx.get('setup_product', prefix) + if prefix and prefix != self.default_product: + self._load_product_from_data(self.global_env, prefix) + if prefix: + self.env = ProductEnvironment(self.global_env, + prefix or self.default_product) + else: + self.env = self.global_env + + self.env.path = '' + config = self.env.config + # -- intertrac support + config.set('intertrac', 'trac.title', "Trac's Trac") + config.set('intertrac', 'trac.url', + "http://trac.edgewall.org") + config.set('intertrac', 't', 'trac') + config.set('intertrac', 'th.title', "Trac Hacks") + config.set('intertrac', 'th.url', + "http://trac-hacks.org") + config.set('intertrac', 'th.compat', 'false') + # -- safe schemes + config.set('wiki', 'safe_schemes', + 'file,ftp,http,https,svn,svn+ssh,' + 'rfc-2396.compatible,rfc-2396+under_score') + + req = Mock(href=Href('/'), abs_href=Href('http://www.example.com/'), + authname='anonymous', perm=MockPerm(), tz=utc, args={}, + locale=locale_en, lc_time=locale_en) + + self.env.href = req.href + self.env.abs_href = req.abs_href def tearDown(self): self.global_env.reset_db()