summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt8
-rw-r--r--docs/api/testing.rst2
-rw-r--r--docs/narr/unittesting.rst3
-rw-r--r--repoze/bfg/configuration.py18
-rw-r--r--repoze/bfg/testing.py2
-rw-r--r--repoze/bfg/tests/test_testing.py2
-rw-r--r--repoze/bfg/zcml.py12
7 files changed, 32 insertions, 15 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index bd0c1b84f..d6550a5f0 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -41,6 +41,11 @@ Features
added to it via its dictionary API and vice versa. This is a
forward compatibility move based on the goals of "marco".
+- Expose and document ``repoze.bfg.testing.zcml_configure`` API. This
+ function populates a component registry from a ZCML file for testing
+ purposes. It is documented in the "Unit and Integration Testing"
+ chapter.
+
Documentation
-------------
@@ -55,7 +60,8 @@ Documentation
methods in order to encourage this as best practice going forward.
- Added "Creating Integration Tests" section to unit testing narrative
- documentation chapter.
+ documentation chapter. As a result, the name of the unittesting
+ chapter is now "Unit and Integration Testing".
Backwards Incompatibilities
---------------------------
diff --git a/docs/api/testing.rst b/docs/api/testing.rst
index 94c231459..bf3d68589 100644
--- a/docs/api/testing.rst
+++ b/docs/api/testing.rst
@@ -31,6 +31,8 @@
.. autofunction:: cleanUp
+ .. autofunction:: zcml_configure
+
.. autoclass:: DummyModel
:members:
diff --git a/docs/narr/unittesting.rst b/docs/narr/unittesting.rst
index 2fba73e34..580ec4ca1 100644
--- a/docs/narr/unittesting.rst
+++ b/docs/narr/unittesting.rst
@@ -161,8 +161,7 @@ environment.
"""
testing.setUp()
import myapp
- import zope.configuration.xmlconfig
- zope.configuration.xmlconfig.file('configure.zcml', package=myapp)
+ testing.zcml_configure('configure.zcml', package=myapp)
def tearDown(self):
""" Clear out the application registry """
diff --git a/repoze/bfg/configuration.py b/repoze/bfg/configuration.py
index 629a58047..7ea74853c 100644
--- a/repoze/bfg/configuration.py
+++ b/repoze/bfg/configuration.py
@@ -4,6 +4,9 @@ import threading
import zope.component
+from zope.configuration import xmlconfig
+from zope.configuration.config import ConfigurationMachine
+
from zope.component import getGlobalSiteManager
from zope.component import getSiteManager
@@ -23,7 +26,6 @@ from repoze.bfg.settings import get_options
from repoze.bfg.threadlocal import get_current_registry
from repoze.bfg.threadlocal import manager
from repoze.bfg.urldispatch import RoutesRootFactory
-from repoze.bfg.zcml import zcml_configure
def make_registry(root_factory, package=None, filename='configure.zcml',
authentication_policy=None, authorization_policy=None,
@@ -132,3 +134,17 @@ class DefaultRootFactory:
# factory") in BFG 0.9.X and before
self.__dict__.update(environ['bfg.routes.matchdict'])
+def zcml_configure(name, package):
+ """ Given a ZCML filename as ``name`` and a Python package as
+ ``package`` which the filename should be relative to, load the
+ ZCML into the current ZCML registry.
+
+ .. note:: This feature is new as of :mod:`repoze.bfg` 1.1.
+ """
+ context = ConfigurationMachine()
+ xmlconfig.registerCommonDirectives(context)
+ context.package = package
+ xmlconfig.include(context, name, package)
+ context.execute_actions(clear=False)
+ return context.actions
+
diff --git a/repoze/bfg/testing.py b/repoze/bfg/testing.py
index 60a52aa66..50f19cbf7 100644
--- a/repoze/bfg/testing.py
+++ b/repoze/bfg/testing.py
@@ -8,6 +8,7 @@ from zope.interface import Interface
from repoze.bfg.interfaces import IRequest
+from repoze.bfg.configuration import zcml_configure # API import alias
from repoze.bfg.registry import Registry
_marker = object()
@@ -457,6 +458,7 @@ class DummyRequest:
self.root = None
self.virtual_root = None
self.marshalled = params # repoze.monty
+ self.registry = getSiteManager()
self.__dict__.update(kw)
def setUp():
diff --git a/repoze/bfg/tests/test_testing.py b/repoze/bfg/tests/test_testing.py
index 7e468725a..9eab891e3 100644
--- a/repoze/bfg/tests/test_testing.py
+++ b/repoze/bfg/tests/test_testing.py
@@ -406,6 +406,7 @@ class TestDummyRequest(unittest.TestCase):
self.assertEqual(request.environ['PATH_INFO'], '/foo')
def test_defaults(self):
+ from zope.component import getSiteManager
request = self._makeOne()
self.assertEqual(request.method, 'GET')
self.assertEqual(request.application_url, 'http://example.com')
@@ -430,6 +431,7 @@ class TestDummyRequest(unittest.TestCase):
self.assertEqual(request.root, None)
self.assertEqual(request.virtual_root, None)
self.assertEqual(request.virtual_root_path, ())
+ self.assertEqual(request.registry, getSiteManager())
def test_params_explicit(self):
request = self._makeOne(params = {'foo':'bar'})
diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py
index b0f5a2595..a4c18dda9 100644
--- a/repoze/bfg/zcml.py
+++ b/repoze/bfg/zcml.py
@@ -1,9 +1,6 @@
import re
import sys
-from zope.configuration import xmlconfig
-import zope.configuration.config
-
from zope.component import getSiteManager
from zope.component import getUtility
from zope.component import queryUtility
@@ -39,6 +36,7 @@ from repoze.bfg.authentication import RepozeWho1AuthenticationPolicy
from repoze.bfg.authentication import RemoteUserAuthenticationPolicy
from repoze.bfg.authentication import AuthTktAuthenticationPolicy
from repoze.bfg.authorization import ACLAuthorizationPolicy
+from repoze.bfg.configuration import zcml_configure
from repoze.bfg.path import package_name
from repoze.bfg.request import create_route_request_factory
from repoze.bfg.resource import PackageOverrides
@@ -730,13 +728,5 @@ class Uncacheable(object):
""" Include in discriminators of actions which are not cacheable;
this class only exists for backwards compatibility (<0.8.1)"""
-def zcml_configure(name, package):
- context = zope.configuration.config.ConfigurationMachine()
- xmlconfig.registerCommonDirectives(context)
- context.package = package
- xmlconfig.include(context, name, package)
- context.execute_actions(clear=False)
- return context.actions
-
file_configure = zcml_configure # backwards compat (>0.8.1)