[Checkins] SVN: zope.app.testing/trunk/src/zope/app/testing/ add support for product configuration in the functional test layer
Fred L. Drake, Jr.
fdrake at gmail.com
Wed Aug 20 11:39:19 EDT 2008
Log message for revision 90025:
add support for product configuration in the functional test layer
Changed:
A zope.app.testing/trunk/src/zope/app/testing/empty.zcml
U zope.app.testing/trunk/src/zope/app/testing/functional.py
U zope.app.testing/trunk/src/zope/app/testing/tests.py
-=-
Added: zope.app.testing/trunk/src/zope/app/testing/empty.zcml
===================================================================
--- zope.app.testing/trunk/src/zope/app/testing/empty.zcml (rev 0)
+++ zope.app.testing/trunk/src/zope/app/testing/empty.zcml 2008-08-20 15:39:19 UTC (rev 90025)
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configure xmlns="http://namespaces.zope.com/zope"/>
Property changes on: zope.app.testing/trunk/src/zope/app/testing/empty.zcml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
Modified: zope.app.testing/trunk/src/zope/app/testing/functional.py
===================================================================
--- zope.app.testing/trunk/src/zope/app/testing/functional.py 2008-08-20 15:29:26 UTC (rev 90024)
+++ zope.app.testing/trunk/src/zope/app/testing/functional.py 2008-08-20 15:39:19 UTC (rev 90025)
@@ -163,7 +163,8 @@
__shared_state = { '_init': False }
- def __init__(self, config_file=None, database_names=None):
+ def __init__(self, config_file=None, database_names=None,
+ product_config=None):
"""Initializes Zope 3 framework.
Creates a volatile memory storage. Parses Zope3 configuration files.
@@ -187,6 +188,15 @@
# Make it silent but keep the log available for debugging
logging.root.addHandler(logging.StreamHandler(self.log))
+ product_configs = []
+ if product_config:
+ configs = zope.app.appsetup.product.loadConfiguration(
+ StringIO(product_config))
+ zope.app.appsetup.product.setProductConfigurations([
+ zope.app.appsetup.product.FauxConfiguration(name, values)
+ for name, values in configs.items()
+ ])
+
self._base_storages = {}
self.db = multi_database(
BaseDatabaseFactory(name, self._base_storages)
@@ -196,6 +206,7 @@
self.connection = None
self._config_file = config_file
+ self._product_config = product_config
self._database_names = database_names
self._init = True
@@ -212,6 +223,10 @@
raise NotImplementedError('Already configured'
' with a different config file')
+ elif product_config and product_config != self._product_config:
+ raise NotImplementedError('Already configured'
+ ' with different product configuration')
+
elif database_names and database_names != self._database_names:
# Running different tests with different configurations is not
# supported at the moment
@@ -262,6 +277,7 @@
"""Cleans up the setup done by the constructor."""
zope.app.testing.setup.placefulTearDown()
self._config_file = False
+ self._product_config = None
self._database_names = None
self._init = False
@@ -283,14 +299,17 @@
__bases__ = ()
- def __init__(self, config_file, module, name, allow_teardown=False):
+ def __init__(self, config_file, module, name, allow_teardown=False,
+ product_config=None):
self.config_file = config_file
self.__module__ = module
self.__name__ = name
self.allow_teardown = allow_teardown
+ self.product_config = product_config
def setUp(self):
- self.setup = FunctionalTestSetup(self.config_file)
+ self.setup = FunctionalTestSetup(
+ self.config_file, product_config=self.product_config)
def tearDown(self):
self.setup.tearDownCompletely()
Modified: zope.app.testing/trunk/src/zope/app/testing/tests.py
===================================================================
--- zope.app.testing/trunk/src/zope/app/testing/tests.py 2008-08-20 15:29:26 UTC (rev 90024)
+++ zope.app.testing/trunk/src/zope/app/testing/tests.py 2008-08-20 15:39:19 UTC (rev 90025)
@@ -50,8 +50,8 @@
This is the response body.
"""
-directory = os.path.join(os.path.split(zope.app.testing.__file__)[0],
- 'recorded')
+here = os.path.dirname(zope.app.testing.__file__)
+directory = os.path.join(here, 'recorded')
expected = r'''
@@ -404,8 +404,7 @@
self.assertEqual(response.getStatus(), 500)
-ftesting_zcml = os.path.join(os.path.split(zope.app.testing.__file__)[0],
- 'ftesting.zcml')
+ftesting_zcml = os.path.join(here, 'ftesting.zcml')
def doctest_FunctionalTestSetup_clears_global_utilities():
"""Test that FunctionalTestSetup doesn't leave global utilities.
@@ -427,6 +426,75 @@
"""
+empty_zcml = os.path.join(here, 'empty.zcml')
+
+def doctest_FunctionalTestSetup_supports_product_config():
+ """Test that FunctionalTestSetup configures products.
+
+ We want to apply the following product configuration before opening
+ databases:
+
+ >>> product_config = '''
+ ... <product-config abc>
+ ... key1 value1
+ ... key2 value2
+ ... </product-config>
+ ... '''
+
+ Since we expect the product configuration to be available when the layer
+ is initialized, we'll register a subscriber for the IDatabaseOpenedEvent
+ event, The normal CA-provided handling of the event is of no use to use,
+ since the functional layer controls the configuration of that, but a
+ low-level zoe.event subscriber will do the job:
+
+ >>> import zope.event
+
+ >>> def handle_database_open(event):
+ ... global config
+ ... IDbOE = zope.app.appsetup.interfaces.IDatabaseOpenedEvent
+ ... if IDbOE.providedBy(event):
+ ... config = zope.app.appsetup.product.getProductConfiguration(
+ ... 'abc')
+
+ >>> zope.event.subscribers.append(handle_database_open)
+
+ The product configuration is passed to the layer setup and installed by
+ the setUp method:
+
+ >>> import pprint
+ >>> import zope.app.appsetup.product
+
+ >>> setup = FunctionalTestSetup(
+ ... empty_zcml, product_config=product_config)
+
+ >>> setup.setUp()
+
+ The configuration was visible to our database-opened subscriber:
+
+ >>> pprint.pprint(config, width=1)
+ {'key1': 'value1',
+ 'key2': 'value2'}
+
+ >>> config = zope.app.appsetup.product.getProductConfiguration(
+ ... 'abc')
+ >>> pprint.pprint(config, width=1)
+ {'key1': 'value1',
+ 'key2': 'value2'}
+
+ >>> setup.tearDown()
+
+ After the layer is cleaned up, there's no longer any product
+ configuration:
+
+ >>> zope.event.subscribers.remove(handle_database_open)
+ >>> setup.tearDownCompletely()
+
+ >>> zope.app.appsetup.product.saveConfiguration()
+ {}
+
+ """
+
+
def test_suite():
checker = RENormalizing([
(re.compile(r'^HTTP/1.1 (\d{3}) .*?\n'), 'HTTP/1.1 \\1\n')
More information about the Checkins
mailing list