summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-11-23 11:24:19 +0000
committerChris McDonough <chrism@agendaless.com>2009-11-23 11:24:19 +0000
commit5453b7bc96005c7607338c24e9ccf858f7cfe153 (patch)
tree36892eef44208cbf494f3d2857f2d7f219f48bd6
parent9ef3b3ec29e3f02e901b41ba04eceb2af86be461 (diff)
downloadpyramid-5453b7bc96005c7607338c24e9ccf858f7cfe153.tar.gz
pyramid-5453b7bc96005c7607338c24e9ccf858f7cfe153.tar.bz2
pyramid-5453b7bc96005c7607338c24e9ccf858f7cfe153.zip
- The ``repoze.bfg.interfaces.ITemplateRendererFactory`` interface was
removed; it has become unused. - Change imperative API.
-rw-r--r--CHANGES.txt3
-rw-r--r--TODO.txt7
-rw-r--r--docs/api/configuration.rst22
-rw-r--r--docs/narr/configuration.rst66
-rw-r--r--repoze/bfg/configuration.py223
-rw-r--r--repoze/bfg/interfaces.py4
-rw-r--r--repoze/bfg/renderers.py5
-rw-r--r--repoze/bfg/tests/test_configuration.py323
-rw-r--r--repoze/bfg/tests/test_renderers.py4
-rw-r--r--repoze/bfg/tests/test_zcml.py2
-rw-r--r--repoze/bfg/zcml.py18
11 files changed, 343 insertions, 334 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 4cb267bcd..0fa189a43 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -116,6 +116,9 @@ Internals
an IDebugLogger unnamed utility. A named utility with the old name
is registered for b/w compat.
+- The ``repoze.bfg.interfaces.ITemplateRendererFactory`` interface was
+ removed; it has become unused.
+
Backwards Incompatibilites
--------------------------
diff --git a/TODO.txt b/TODO.txt
index 5feac6a0c..281310e0a 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -5,6 +5,11 @@
- Finish "configuration" documentation chapter and audit the rest of
the docs for "view configuration" and "route configuration"
- references, etc.
+ references, etc. Add one more view registration (and maybe some
+ other registration) in the narrative.
- Finish Configurator API documentation.
+
+- notfound/forbidden as Configurator API arguments (get rid of
+ set_notfound_view and set_forbidden_view?)
+
diff --git a/docs/api/configuration.rst b/docs/api/configuration.rst
index 12c90260f..fb7c508fc 100644
--- a/docs/api/configuration.rst
+++ b/docs/api/configuration.rst
@@ -7,26 +7,24 @@
.. autoclass:: Configurator(registry=None, package=None, settings=None, root_factory=None, zcml_file=None, authentication_policy=None, authorization_policy=None, renderers=DEFAULT_RENDERERS)
- .. automethod:: route
+ .. automethod:: add_route
- .. automethod:: view
+ .. automethod:: add_view
- .. automethod:: security_policies
+ .. automethod:: add_renderer(name, factory)
- .. automethod:: forbidden(view=None, attr=None, renderer=None, wrapper=None)
+ .. automethod:: add_static_view(name, path, cache_max_age=3600)
- .. automethod:: notfound(view=None, attr=None, renderer=None, wrapper=None)
+ .. automethod:: load_zcml(spec)
- .. automethod:: renderer(factory, name)
+ .. automethod:: make_wsgi_app()
- .. automethod:: resource(to_override, override_with)
+ .. automethod:: override_resource(to_override, override_with)
.. automethod:: scan(package)
- .. automethod:: static(name, path, cache_max_age=3600)
+ .. automethod:: set_forbidden_view(view=None, attr=None, renderer=None, wrapper=None)
- .. automethod:: load_zcml(spec)
-
- .. automethod:: make_wsgi_app()
+ .. automethod:: set_notfound_view(view=None, attr=None, renderer=None, wrapper=None)
-
+ .. automethod:: set_security_policies
diff --git a/docs/narr/configuration.rst b/docs/narr/configuration.rst
index 09e412c30..7f1952c0d 100644
--- a/docs/narr/configuration.rst
+++ b/docs/narr/configuration.rst
@@ -92,7 +92,7 @@ imperatively:
if __name__ == '__main__':
config = Configurator()
- config.view(hello_world)
+ config.add_view(hello_world)
app = config.make_wsgi_app()
simple_server.make_server('', 8080, app).serve_forever()
@@ -191,7 +191,7 @@ imports and function definitions is placed within the confines of an
if __name__ == '__main__':
config = Configurator()
- config.view(hello_world)
+ config.add_view(hello_world)
app = config.make_wsgi_app()
simple_server.make_server('', 8080, app).serve_forever()
@@ -232,28 +232,28 @@ this particular :mod:`repoze.bfg` application. An instance of the
.. code-block:: python
:linenos:
- config.view(hello_world)
+ config.add_view(hello_world)
-This line calls the ``view`` method of the ``Configurator``. The
-``view`` method of a configurator creates a :term:`view configuration`
-within the :term:`application registry`. A :term:`view configuration`
-represents a set of circumstances which must be true for a particular
-:term:`view callable` to be called when a WSGI request is handled by
-:mod:`repoze.bfg`.
+This line calls the ``add_view`` method of the ``Configurator``. The
+``add_view`` method of a configurator creates a :term:`view
+configuration` within the :term:`application registry`. A :term:`view
+configuration` represents a set of circumstances which must be true
+for a particular :term:`view callable` to be called when a WSGI
+request is handled by :mod:`repoze.bfg`.
-The first argument of the configurator's ``view`` method must always
-be a reference to the :term:`view callable` that is meant to be
+The first argument of the configurator's ``add_view`` method must
+always be a reference to the :term:`view callable` that is meant to be
invoked when the view configuration implied by the remainder of the
-arguments passed to ``view`` is found to "match" during a request.
-This particular invocation of the ``view`` method passes no other
+arguments passed to ``add_view`` is found to "match" during a request.
+This particular invocation of the ``add_view`` method passes no other
arguments; this implies that there are no circumstances which would
limit the applicability of this view callable. The view configuration
-implied by this call to ``view`` thus will match during *any* request.
-Since our ``hello_world`` view callable returns a Response instance
-with a body of ``Hello world!```, this means, in the configuration
-implied by the script, that any URL visited by a user agent to a
-server running this application will receive the greeting ``Hello
-world!``.
+implied by this call to ``add_view`` thus will match during *any*
+request. Since our ``hello_world`` view callable returns a Response
+instance with a body of ``Hello world!```, this means, in the
+configuration implied by the script, that any URL visited by a user
+agent to a server running this application will receive the greeting
+``Hello world!``.
WGSI Application Creation
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -279,9 +279,9 @@ method calls to the configurator used to configure it. The Router
consults the registry to obey the policy choices made by a single
application. These policy choices were informed by method calls to
the ``Configurator`` made earlier; in our case, the only policy choice
-made was a single call to the ``view`` method, telling our application
-that it should unconditionally serve up the ``hello_world`` view
-callable to any requestor.
+made was a single call to the ``add_view`` method, telling our
+application that it should unconditionally serve up the
+``hello_world`` view callable to any requestor.
WSGI Application Serving
~~~~~~~~~~~~~~~~~~~~~~~~
@@ -384,14 +384,14 @@ within the ``if __name__ == '__main__'`` section of ``helloworld.py``:
if __name__ == '__main__':
config = Configurator()
- config.view(hello_world)
+ config.add_view(hello_world)
app = config.make_wsgi_app()
simple_server.make_server('', 8080, app).serve_forever()
In our "declarative" code, we've added a ``zcml_file`` argument to the
``Configurator`` constructor's argument list with the value
``configure.zcml``, and we've removed the line which reads
-``config.view(hello_world)``, so that it now reads as:
+``config.add_view(hello_world)``, so that it now reads as:
.. code-block:: python
:linenos:
@@ -500,21 +500,21 @@ The ``configure.zcml`` ZCML file contains this bit of XML after the
/>
This ``<view>`` declaration tag directs :mod:`repoze.bfg` to create a
-:term:`view configuration`. This ``<view>`` tag has an attribute
-(also named ``view``), which points at a :term:`dotted Python name`,
-referencing the ``hello_world`` function defined within the
-``helloworld`` package. This tag is functionally equivalent to a
+:term:`view configuration`. This ``<view>`` tag has an attribute (the
+attribute is also named ``view``), which points at a :term:`dotted
+Python name`, referencing the ``hello_world`` function defined within
+the ``helloworld`` package. This tag is functionally equivalent to a
line we saw previously in our imperatively-configured application:
.. code-block:: python
:linenos:
- config.view(hello_world)
+ config.add_view(hello_world)
-The ``<view>`` declaration tag effectively invokes the ``view`` method
-of the ``Configurator`` object on your behalf. Various attributes can
-be specified on the ``<view>`` tag which influence the :term:`view
-configuration` it creates.
+The ``<view>`` declaration tag effectively invokes the ``add_view``
+method of the ``Configurator`` object on your behalf. Various
+attributes can be specified on the ``<view>`` tag which influence the
+:term:`view configuration` it creates.
The ``<view>`` tag is an example of a :mod:`repoze.bfg` declaration
tag. Other such tags include ``<route>``, ``<scan>``, ``<notfound>``,
diff --git a/repoze/bfg/configuration.py b/repoze/bfg/configuration.py
index ea6f9aa54..356630d8a 100644
--- a/repoze/bfg/configuration.py
+++ b/repoze/bfg/configuration.py
@@ -35,7 +35,6 @@ from repoze.bfg.interfaces import IRouteRequest
from repoze.bfg.interfaces import IRoutesMapper
from repoze.bfg.interfaces import ISettings
from repoze.bfg.interfaces import ISecuredView
-from repoze.bfg.interfaces import ITemplateRendererFactory
from repoze.bfg.interfaces import IView
from repoze.bfg import chameleon_zpt
@@ -143,8 +142,8 @@ class Configurator(object):
if registry is None:
registry = Registry(self.package.__name__)
self.registry = registry
- self.settings(settings)
- self.root_factory(root_factory)
+ self._set_settings(settings)
+ self._set_root_factory(root_factory)
if debug_logger is None:
debug_logger = make_stream_logger('repoze.bfg.debug',
sys.stderr)
@@ -152,28 +151,27 @@ class Configurator(object):
registry.registerUtility(debug_logger, IDebugLogger,
'repoze.bfg.debug') # b /c
if authentication_policy or authorization_policy:
- self.security_policies(authentication_policy,
- authorization_policy)
+ self.set_security_policies(authentication_policy,
+ authorization_policy)
for name, renderer in renderers:
- self.renderer(renderer, name)
+ self.add_renderer(name, renderer)
if zcml_file is not None:
self.load_zcml(zcml_file)
- def settings(self, mapping):
+ def _set_settings(self, mapping):
settings = Settings(mapping or {})
self.registry.registerUtility(settings, ISettings)
- def make_spec(self, path_or_spec):
- package, filename = resolve_resource_spec(path_or_spec,
- self.package.__name__)
- if package is None:
- return filename # absolute filename
- return '%s:%s' % (package, filename)
-
- def split_spec(self, path_or_spec):
- return resolve_resource_spec(path_or_spec, self.package.__name__)
-
- def renderer_from_name(self, path_or_spec):
+ def _set_root_factory(self, factory):
+ """ Add a :term:`root factory` to the current configuration
+ state. If the ``factory`` argument is ``None`` a default root
+ factory will be registered."""
+ if factory is None:
+ factory = DefaultRootFactory
+ self.registry.registerUtility(factory, IRootFactory)
+ self.registry.registerUtility(factory, IDefaultRootFactory) # b/c
+
+ def _renderer_from_name(self, path_or_spec):
if path_or_spec is None:
# check for global default renderer
factory = self.registry.queryUtility(IRendererFactory)
@@ -183,7 +181,7 @@ class Configurator(object):
if '.' in path_or_spec:
name = os.path.splitext(path_or_spec)[1]
- spec = self.make_spec(path_or_spec)
+ spec = self._make_spec(path_or_spec)
else:
name = path_or_spec
spec = path_or_spec
@@ -193,16 +191,74 @@ class Configurator(object):
raise ValueError('No renderer for renderer name %r' % name)
return factory(spec)
- def authentication_policy(self, policy, _info=u''):
+ def _set_authentication_policy(self, policy, _info=u''):
""" Add a :mod:`repoze.bfg` :term:`authentication policy` to
the current configuration."""
self.registry.registerUtility(policy, IAuthenticationPolicy, info=_info)
- def authorization_policy(self, policy, _info=u''):
+ def _set_authorization_policy(self, policy, _info=u''):
""" Add a :mod:`repoze.bfg` :term:`authorization policy` to
the current configuration state."""
self.registry.registerUtility(policy, IAuthorizationPolicy, info=_info)
+ def _make_spec(self, path_or_spec):
+ package, filename = resolve_resource_spec(path_or_spec,
+ self.package.__name__)
+ if package is None:
+ return filename # absolute filename
+ return '%s:%s' % (package, filename)
+
+ def _split_spec(self, path_or_spec):
+ return resolve_resource_spec(path_or_spec, self.package.__name__)
+
+ def _derive_view(self, view, permission=None, predicates=(),
+ attr=None, renderer_name=None, wrapper_viewname=None,
+ viewname=None):
+ renderer = self._renderer_from_name(renderer_name)
+ authn_policy = self.registry.queryUtility(IAuthenticationPolicy)
+ authz_policy = self.registry.queryUtility(IAuthorizationPolicy)
+ settings = self.registry.queryUtility(ISettings)
+ logger = self.registry.queryUtility(IDebugLogger)
+ mapped_view = _map_view(view, attr, renderer, renderer_name)
+ owrapped_view = _owrap_view(mapped_view, viewname, wrapper_viewname)
+ secured_view = _secure_view(owrapped_view, permission,
+ authn_policy, authz_policy)
+ debug_view = _authdebug_view(secured_view, permission,
+ authn_policy, authz_policy, settings,
+ logger)
+ derived_view = _predicate_wrap(debug_view, predicates)
+ return derived_view
+
+
+ def _override(self, package, path, override_package, override_prefix,
+ _info=u'', PackageOverrides=PackageOverrides):
+ pkg_name = package.__name__
+ override_pkg_name = override_package.__name__
+ override = self.registry.queryUtility(
+ IPackageOverrides, name=pkg_name)
+ if override is None:
+ override = PackageOverrides(package)
+ self.registry.registerUtility(override, IPackageOverrides,
+ name=pkg_name, info=_info)
+ override.insert(path, override_pkg_name, override_prefix)
+
+
+ def _system_view(self, iface, view=None, attr=None, renderer=None,
+ wrapper=None, _info=u''):
+ if not view:
+ if renderer:
+ def view(context, request):
+ return {}
+ else:
+ raise ConfigurationError('"view" attribute was not '
+ 'specified and no renderer '
+ 'specified')
+
+ derived_view = self._derive_view(view, attr=attr,
+ renderer_name=renderer,
+ wrapper_viewname=wrapper)
+ self.registry.registerUtility(derived_view, iface, '', info=_info)
+
# API
def make_wsgi_app(self, manager=manager, getSiteManager=getSiteManager):
@@ -246,7 +302,7 @@ class Configurator(object):
# hold the lock. Those registrations will end up in our
# application's registry.
- package_name, filename = self.split_spec(spec)
+ package_name, filename = self._split_spec(spec)
if package_name is None: # absolute filename
package = self.package
else:
@@ -266,7 +322,7 @@ class Configurator(object):
getSiteManager.reset()
return self.registry
- def security_policies(self, authentication, authorization=None):
+ def set_security_policies(self, authentication, authorization=None):
""" Register security policies safely. The ``authentication``
argument represents a :term:`authentication policy`. The
``authorization`` argument represents a :term:`authorization
@@ -280,14 +336,14 @@ class Configurator(object):
'If the "authorization" is passed a vallue, '
'the "authentication" argument musty also be '
'passed a value; authorization requires authentication.')
- self.authentication_policy(authentication)
- self.authorization_policy(authorization)
-
- def view(self, view=None, name="", for_=None, permission=None,
- request_type=None, route_name=None, request_method=None,
- request_param=None, containment=None, attr=None,
- renderer=None, wrapper=None, xhr=False, accept=None,
- header=None, path_info=None, _info=u''):
+ self._set_authentication_policy(authentication)
+ self._set_authorization_policy(authorization)
+
+ def add_view(self, view=None, name="", for_=None, permission=None,
+ request_type=None, route_name=None, request_method=None,
+ request_param=None, containment=None, attr=None,
+ renderer=None, wrapper=None, xhr=False, accept=None,
+ header=None, path_info=None, _info=u''):
""" Add a :term:`view configuration` to the current
configuration state."""
@@ -359,34 +415,16 @@ class Configurator(object):
self.registry.registerAdapter(multiview, (for_, request_type),
IMultiView, name, info=_info)
- def _derive_view(self, view, permission=None, predicates=(),
- attr=None, renderer_name=None, wrapper_viewname=None,
- viewname=None):
- renderer = self.renderer_from_name(renderer_name)
- authn_policy = self.registry.queryUtility(IAuthenticationPolicy)
- authz_policy = self.registry.queryUtility(IAuthorizationPolicy)
- settings = self.registry.queryUtility(ISettings)
- logger = self.registry.queryUtility(IDebugLogger)
- mapped_view = _map_view(view, attr, renderer, renderer_name)
- owrapped_view = _owrap_view(mapped_view, viewname, wrapper_viewname)
- secured_view = _secure_view(owrapped_view, permission,
- authn_policy, authz_policy)
- debug_view = _authdebug_view(secured_view, permission,
- authn_policy, authz_policy, settings,
- logger)
- derived_view = _predicate_wrap(debug_view, predicates)
- return derived_view
-
- def route(self, name, path, view=None, view_for=None,
- permission=None, factory=None, for_=None,
- header=None, xhr=False, accept=None, path_info=None,
- request_method=None, request_param=None,
- view_permission=None, view_request_method=None,
- view_request_param=None,
- view_containment=None, view_attr=None,
- renderer=None, view_renderer=None, view_header=None,
- view_accept=None, view_xhr=False,
- view_path_info=None, _info=u''):
+ def add_route(self, name, path, view=None, view_for=None,
+ permission=None, factory=None, for_=None,
+ header=None, xhr=False, accept=None, path_info=None,
+ request_method=None, request_param=None,
+ view_permission=None, view_request_method=None,
+ view_request_param=None,
+ view_containment=None, view_attr=None,
+ renderer=None, view_renderer=None, view_header=None,
+ view_accept=None, view_xhr=False,
+ view_path_info=None, _info=u''):
""" Add a :term:`route configuration` to the current
configuration state."""
# these are route predicates; if they do not match, the next route
@@ -408,7 +446,7 @@ class Configurator(object):
view_for = view_for or for_
view_permission = view_permission or permission
view_renderer = view_renderer or renderer
- self.view(
+ self.add_view(
permission=view_permission,
for_=view_for,
view=view,
@@ -445,15 +483,14 @@ class Configurator(object):
_info=_info, _configurator=self,
exclude_filter=lambda name: name.startswith('.'))
- def renderer(self, factory, name, _info=u''):
- """ Add a :mod:`repoze.bfg` :term:`renderer` to the current
+ def add_renderer(self, name, renderer, _info=u''):
+ """ Add a :mod:`repoze.bfg` :term:`renderer` factory to the current
configuration state."""
iface = IRendererFactory
- if name.startswith('.'):
- iface = ITemplateRendererFactory
- self.registry.registerUtility(factory, iface, name=name, info=_info)
+ self.registry.registerUtility(renderer, iface, name=name, info=_info)
- def resource(self, to_override, override_with, _info=u'', _override=None,):
+ def override_resource(self, to_override, override_with,
+ _info=u'', _override=None,):
""" Add a :mod:`repoze.bfg` resource override to the current
configuration state. See :ref:`resources_chapter` for more
information about resource overrides."""
@@ -492,62 +529,26 @@ class Configurator(object):
override(package, path, override_package, override_prefix,
_info=_info)
- def _override(self, package, path, override_package, override_prefix,
- _info=u'', PackageOverrides=PackageOverrides):
- pkg_name = package.__name__
- override_pkg_name = override_package.__name__
- override = self.registry.queryUtility(
- IPackageOverrides, name=pkg_name)
- if override is None:
- override = PackageOverrides(package)
- self.registry.registerUtility(override, IPackageOverrides,
- name=pkg_name, info=_info)
- override.insert(path, override_pkg_name, override_prefix)
-
- def forbidden(self, *arg, **kw):
+ def set_forbidden_view(self, *arg, **kw):
""" Add a default forbidden view to the current configuration
state."""
return self._system_view(IForbiddenView, *arg, **kw)
- def notfound(self, *arg, **kw):
+ def set_notfound_view(self, *arg, **kw):
""" Add a default not found view to the current configuration
state."""
return self._system_view(INotFoundView, *arg, **kw)
- def _system_view(self, iface, view=None, attr=None, renderer=None,
- wrapper=None, _info=u''):
- if not view:
- if renderer:
- def view(context, request):
- return {}
- else:
- raise ConfigurationError('"view" attribute was not '
- 'specified and no renderer '
- 'specified')
-
- derived_view = self._derive_view(view, attr=attr,
- renderer_name=renderer,
- wrapper_viewname=wrapper)
- self.registry.registerUtility(derived_view, iface, '', info=_info)
-
- def static(self, name, path, cache_max_age=3600, _info=u''):
+ def add_static_view(self, name, path, cache_max_age=3600, _info=u''):
""" Add a static view to the current configuration state."""
- spec = self.make_spec(path)
+ spec = self._make_spec(path)
view = static(spec, cache_max_age=cache_max_age)
- self.route(name, "%s*subpath" % name, view=view,
- view_for=StaticRootFactory, factory=StaticRootFactory(spec),
- _info=_info)
+ self.add_route(name, "%s*subpath" % name, view=view,
+ view_for=StaticRootFactory,
+ factory=StaticRootFactory(spec),
+ _info=_info)
- def root_factory(self, factory):
- """ Add a :term:`root factory` to the current configuration
- state. If the ``factory`` argument is ``None`` a default root
- factory will be registered."""
- if factory is None:
- factory = DefaultRootFactory
- self.registry.registerUtility(factory, IRootFactory)
- self.registry.registerUtility(factory, IDefaultRootFactory) # b/c
-
def _make_predicates(xhr=None, request_method=None, path_info=None,
request_param=None, header=None, accept=None,
containment=None):
@@ -662,7 +663,7 @@ class BFGViewGrokker(martian.InstanceGrokker):
for settings in config:
config = kw['_configurator']
info = kw.get('_info', u'')
- config.view(view=obj, _info=info, **settings)
+ config.add_view(view=obj, _info=info, **settings)
return bool(config)
class MultiView(object):
diff --git a/repoze/bfg/interfaces.py b/repoze/bfg/interfaces.py
index 0f2d6ce45..614acbb80 100644
--- a/repoze/bfg/interfaces.py
+++ b/repoze/bfg/interfaces.py
@@ -106,10 +106,6 @@ class ITemplateRenderer(IRenderer):
accepts arbitrary keyword arguments and returns a string or
unicode object """
-class ITemplateRendererFactory(IRendererFactory):
- def __call__(path):
- """ Return an object that implements ``ITemplateRenderer`` """
-
class IViewPermission(Interface):
def __call__(context, request):
""" Return True if the permission allows, return False if it denies. """
diff --git a/repoze/bfg/renderers.py b/repoze/bfg/renderers.py
index 424c400ac..2a42ef901 100644
--- a/repoze/bfg/renderers.py
+++ b/repoze/bfg/renderers.py
@@ -62,11 +62,8 @@ def renderer_from_name(path):
from repoze.bfg.configuration import Configurator
reg = get_current_registry()
config = Configurator(reg)
- return config.renderer_from_name(path)
+ return config._renderer_from_name(path)
def _reload_resources():
settings = get_settings()
return settings and settings.get('reload_resources')
-
-
-
diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py
index 624e90c05..c16d738f5 100644
--- a/repoze/bfg/tests/test_configuration.py
+++ b/repoze/bfg/tests/test_configuration.py
@@ -224,77 +224,77 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(dummylock.acquired, True)
self.assertEqual(dummylock.released, True)
- def test_view_view_callable_None_no_renderer(self):
+ def test_add_view_view_callable_None_no_renderer(self):
from zope.configuration.exceptions import ConfigurationError
config = self._makeOne()
- self.assertRaises(ConfigurationError, config.view)
+ self.assertRaises(ConfigurationError, config.add_view)
- def test_view_with_request_type_and_route_name(self):
+ def test_add_view_with_request_type_and_route_name(self):
from zope.configuration.exceptions import ConfigurationError
config = self._makeOne()
view = lambda *arg: 'OK'
- self.assertRaises(ConfigurationError, config.view, view, '', None,
+ self.assertRaises(ConfigurationError, config.add_view, view, '', None,
None, True, True)
- def test_view_view_callable_None_with_renderer(self):
+ def test_add_view_view_callable_None_with_renderer(self):
config = self._makeOne()
self._registerRenderer(config, name='dummy')
- config.view(renderer='dummy')
+ config.add_view(renderer='dummy')
view = self._getViewCallable(config)
self.failUnless('Hello!' in view(None, None).body)
- def test_wrapped_view_is_decorated(self):
+ def test_add_view_wrapped_view_is_decorated(self):
def view(request): # request-only wrapper
""" """
config = self._makeOne()
- config.view(view=view)
+ config.add_view(view=view)
wrapper = self._getViewCallable(config)
self.assertEqual(wrapper.__module__, view.__module__)
self.assertEqual(wrapper.__name__, view.__name__)
self.assertEqual(wrapper.__doc__, view.__doc__)
- def test_view_with_function_callable(self):
+ def test_add_view_with_function_callable(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view)
+ config.add_view(view=view)
wrapper = self._getViewCallable(config)
result = wrapper(None, None)
self.assertEqual(result, 'OK')
- def test_view_with_function_callable_requestonly(self):
+ def test_add_view_with_function_callable_requestonly(self):
def view(request):
return 'OK'
config = self._makeOne()
- config.view(view=view)
+ config.add_view(view=view)
wrapper = self._getViewCallable(config)
result = wrapper(None, None)
self.assertEqual(result, 'OK')
- def test_view_as_instance(self):
+ def test_add_view_as_instance(self):
class AView:
def __call__(self, context, request):
""" """
return 'OK'
view = AView()
config = self._makeOne()
- config.view(view=view)
+ config.add_view(view=view)
wrapper = self._getViewCallable(config)
result = wrapper(None, None)
self.assertEqual(result, 'OK')
- def test_view_as_instance_requestonly(self):
+ def test_add_view_as_instance_requestonly(self):
class AView:
def __call__(self, request):
""" """
return 'OK'
view = AView()
config = self._makeOne()
- config.view(view=view)
+ config.add_view(view=view)
wrapper = self._getViewCallable(config)
result = wrapper(None, None)
self.assertEqual(result, 'OK')
- def test_view_as_oldstyle_class(self):
+ def test_add_view_as_oldstyle_class(self):
class view:
def __init__(self, context, request):
self.context = context
@@ -303,12 +303,12 @@ class ConfiguratorTests(unittest.TestCase):
def __call__(self):
return 'OK'
config = self._makeOne()
- config.view(view=view)
+ config.add_view(view=view)
wrapper = self._getViewCallable(config)
result = wrapper(None, None)
self.assertEqual(result, 'OK')
- def test_view_as_oldstyle_class_requestonly(self):
+ def test_add_view_as_oldstyle_class_requestonly(self):
class view:
def __init__(self, request):
self.request = request
@@ -316,42 +316,42 @@ class ConfiguratorTests(unittest.TestCase):
def __call__(self):
return 'OK'
config = self._makeOne()
- config.view(view=view)
+ config.add_view(view=view)
wrapper = self._getViewCallable(config)
result = wrapper(None, None)
self.assertEqual(result, 'OK')
- def test_view_for_as_class(self):
+ def test_add_view_for_as_class(self):
from zope.interface import implementedBy
view = lambda *arg: 'OK'
class Foo:
pass
config = self._makeOne()
- config.view(for_=Foo, view=view)
+ config.add_view(for_=Foo, view=view)
foo = implementedBy(Foo)
wrapper = self._getViewCallable(config, foo)
self.assertEqual(wrapper, view)
- def test_view_for_as_iface(self):
+ def test_add_view_for_as_iface(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(for_=IDummy, view=view)
+ config.add_view(for_=IDummy, view=view)
wrapper = self._getViewCallable(config, IDummy)
self.assertEqual(wrapper, view)
- def test_view_register_secured_view(self):
+ def test_add_view_register_secured_view(self):
from zope.interface import Interface
from repoze.bfg.interfaces import IRequest
from repoze.bfg.interfaces import ISecuredView
view = lambda *arg: 'OK'
view.__call_permissive__ = view
config = self._makeOne()
- config.view(view=view)
+ config.add_view(view=view)
wrapper = config.registry.adapters.lookup(
(Interface, IRequest), ISecuredView, name='', default=None)
self.assertEqual(wrapper, view)
- def test_view_multiview_replaces_existing_view(self):
+ def test_add_view_multiview_replaces_existing_view(self):
from zope.interface import Interface
from repoze.bfg.interfaces import IRequest
from repoze.bfg.interfaces import IView
@@ -360,12 +360,12 @@ class ConfiguratorTests(unittest.TestCase):
config = self._makeOne()
config.registry.registerAdapter(
view, (Interface, IRequest), IView, name='')
- config.view(view=view)
+ config.add_view(view=view)
wrapper = self._getViewCallable(config)
self.failUnless(IMultiView.providedBy(wrapper))
self.assertEqual(wrapper(None, None), 'OK')
- def test_view_multiview_replaces_multiview(self):
+ def test_add_view_multiview_replaces_multiview(self):
from zope.interface import Interface
from zope.interface import implements
from repoze.bfg.interfaces import IRequest
@@ -386,13 +386,13 @@ class ConfiguratorTests(unittest.TestCase):
config.registry.registerAdapter(view, (Interface, IRequest),
IMultiView, name='')
view2 = lambda *arg: 'OK2'
- config.view(view=view2)
+ config.add_view(view=view2)
wrapper = self._getViewCallable(config)
self.failUnless(IMultiView.providedBy(wrapper))
self.assertEqual(wrapper.views, [view2])
self.assertEqual(wrapper(None, None), 'OK1')
- def test_view_multiview_call_ordering(self):
+ def test_add_view_multiview_call_ordering(self):
from zope.interface import directlyProvides
def view1(context, request): return 'view1'
def view2(context, request): return 'view2'
@@ -403,15 +403,15 @@ class ConfiguratorTests(unittest.TestCase):
def view7(context, request): return 'view7'
def view8(context, request): return 'view8'
config = self._makeOne()
- config.view(view=view1)
- config.view(view=view2, request_method='POST')
- config.view(view=view3,request_param='param')
- config.view(view=view4, containment=IDummy)
- config.view(view=view5, request_method='POST', request_param='param')
- config.view(view=view6, request_method='POST', containment=IDummy)
- config.view(view=view7, request_param='param', containment=IDummy)
- config.view(view=view8, request_method='POST', request_param='param',
- containment=IDummy)
+ config.add_view(view=view1)
+ config.add_view(view=view2, request_method='POST')
+ config.add_view(view=view3,request_param='param')
+ config.add_view(view=view4, containment=IDummy)
+ config.add_view(view=view5, request_method='POST',request_param='param')
+ config.add_view(view=view6, request_method='POST', containment=IDummy)
+ config.add_view(view=view7, request_param='param', containment=IDummy)
+ config.add_view(view=view8, request_method='POST',request_param='param',
+ containment=IDummy)
wrapper = self._getViewCallable(config)
@@ -467,7 +467,7 @@ class ConfiguratorTests(unittest.TestCase):
request.params = {'param':'1'}
self.assertEqual(wrapper(ctx, request), 'view8')
- def test_view_with_template_renderer(self):
+ def test_add_view_with_template_renderer(self):
class view(object):
def __init__(self, context, request):
self.request = request
@@ -478,225 +478,225 @@ class ConfiguratorTests(unittest.TestCase):
config = self._makeOne()
renderer = self._registerRenderer(config)
fixture = 'repoze.bfg.tests:fixtures/minimal.txt'
- config.view(view=view, renderer=fixture)
+ config.add_view(view=view, renderer=fixture)
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
result = wrapper(None, request)
self.assertEqual(result.body, 'Hello!')
self.assertEqual(renderer.path, 'repoze.bfg.tests:fixtures/minimal.txt')
- def test_view_with_template_renderer_no_callable(self):
+ def test_add_view_with_template_renderer_no_callable(self):
config = self._makeOne()
renderer = self._registerRenderer(config)
fixture = 'repoze.bfg.tests:fixtures/minimal.txt'
- config.view(view=None, renderer=fixture)
+ config.add_view(view=None, renderer=fixture)
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
result = wrapper(None, request)
self.assertEqual(result.body, 'Hello!')
self.assertEqual(renderer.path, 'repoze.bfg.tests:fixtures/minimal.txt')
- def test_view_with_request_type_as_iface(self):
+ def test_add_view_with_request_type_as_iface(self):
def view(context, request):
return 'OK'
config = self._makeOne()
- config.view(request_type=IDummy, view=view)
+ config.add_view(request_type=IDummy, view=view)
wrapper = self._getViewCallable(config, None, IDummy)
result = wrapper(None, None)
self.assertEqual(result, 'OK')
- def test_view_with_request_type_as_noniface(self):
+ def test_add_view_with_request_type_as_noniface(self):
from zope.interface import providedBy
def view(context, request):
return 'OK'
config = self._makeOne()
- config.view(request_type=object, view=view)
+ config.add_view(request_type=object, view=view)
request_iface = providedBy(object)
wrapper = self._getViewCallable(config, None, request_iface)
result = wrapper(None, None)
self.assertEqual(result, 'OK')
- def test_view_with_route_name(self):
+ def test_add_view_with_route_name(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, route_name='foo')
+ config.add_view(view=view, route_name='foo')
request_type = self._getRouteRequestIface(config, 'foo')
wrapper = self._getViewCallable(config, None, request_type)
self.assertEqual(wrapper(None, None), 'OK')
- def test_view_with_request_method_true(self):
+ def test_add_view_with_request_method_true(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, request_method='POST')
+ config.add_view(view=view, request_method='POST')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.method = 'POST'
self.assertEqual(wrapper(None, request), 'OK')
- def test_view_with_request_method_false(self):
+ def test_add_view_with_request_method_false(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, request_method='POST')
+ config.add_view(view=view, request_method='POST')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.method = 'GET'
self._assertNotFound(wrapper, None, request)
- def test_view_with_request_param_noval_true(self):
+ def test_add_view_with_request_param_noval_true(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, request_param='abc')
+ config.add_view(view=view, request_param='abc')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.params = {'abc':''}
self.assertEqual(wrapper(None, request), 'OK')
- def test_view_with_request_param_noval_false(self):
+ def test_add_view_with_request_param_noval_false(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, request_param='abc')
+ config.add_view(view=view, request_param='abc')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.params = {}
self._assertNotFound(wrapper, None, request)
- def test_view_with_request_param_val_true(self):
+ def test_add_view_with_request_param_val_true(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, request_param='abc=123')
+ config.add_view(view=view, request_param='abc=123')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.params = {'abc':'123'}
self.assertEqual(wrapper(None, request), 'OK')
- def test_view_with_request_param_val_false(self):
+ def test_add_view_with_request_param_val_false(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, request_param='abc=123')
+ config.add_view(view=view, request_param='abc=123')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.params = {'abc':''}
self._assertNotFound(wrapper, None, request)
- def test_view_with_xhr_true(self):
+ def test_add_view_with_xhr_true(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, xhr=True)
+ config.add_view(view=view, xhr=True)
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.is_xhr = True
self.assertEqual(wrapper(None, request), 'OK')
- def test_view_with_xhr_false(self):
+ def test_add_view_with_xhr_false(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, xhr=True)
+ config.add_view(view=view, xhr=True)
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.is_xhr = False
self._assertNotFound(wrapper, None, request)
- def test_view_with_header_badregex(self):
+ def test_add_view_with_header_badregex(self):
from zope.configuration.exceptions import ConfigurationError
view = lambda *arg: 'OK'
config = self._makeOne()
self.assertRaises(ConfigurationError,
- config.view, view=view, header='Host:a\\')
+ config.add_view, view=view, header='Host:a\\')
- def test_view_with_header_noval_match(self):
+ def test_add_view_with_header_noval_match(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, header='Host')
+ config.add_view(view=view, header='Host')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.headers = {'Host':'whatever'}
self.assertEqual(wrapper(None, request), 'OK')
- def test_view_with_header_noval_nomatch(self):
+ def test_add_view_with_header_noval_nomatch(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, header='Host')
+ config.add_view(view=view, header='Host')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.headers = {'NotHost':'whatever'}
self._assertNotFound(wrapper, None, request)
- def test_view_with_header_val_match(self):
+ def test_add_view_with_header_val_match(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, header=r'Host:\d')
+ config.add_view(view=view, header=r'Host:\d')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.headers = {'Host':'1'}
self.assertEqual(wrapper(None, request), 'OK')
- def test_view_with_header_val_nomatch(self):
+ def test_add_view_with_header_val_nomatch(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, header=r'Host:\d')
+ config.add_view(view=view, header=r'Host:\d')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.headers = {'Host':'abc'}
self._assertNotFound(wrapper, None, request)
- def test_view_with_accept_match(self):
+ def test_add_view_with_accept_match(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, accept='text/xml')
+ config.add_view(view=view, accept='text/xml')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.accept = ['text/xml']
self.assertEqual(wrapper(None, request), 'OK')
- def test_view_with_accept_nomatch(self):
+ def test_add_view_with_accept_nomatch(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, accept='text/xml')
+ config.add_view(view=view, accept='text/xml')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.accept = ['text/html']
self._assertNotFound(wrapper, None, request)
- def test_view_with_containment_true(self):
+ def test_add_view_with_containment_true(self):
from zope.interface import directlyProvides
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, containment=IDummy)
+ config.add_view(view=view, containment=IDummy)
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
context = DummyContext()
directlyProvides(context, IDummy)
self.assertEqual(wrapper(context, None), 'OK')
- def test_view_with_containment_false(self):
+ def test_add_view_with_containment_false(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, containment=IDummy)
+ config.add_view(view=view, containment=IDummy)
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
context = DummyContext()
self._assertNotFound(wrapper, context, None)
- def test_view_with_path_info_badregex(self):
+ def test_add_view_with_path_info_badregex(self):
from zope.configuration.exceptions import ConfigurationError
view = lambda *arg: 'OK'
config = self._makeOne()
self.assertRaises(ConfigurationError,
- config.view, view=view, path_info='\\')
+ config.add_view, view=view, path_info='\\')
- def test_with_path_info_match(self):
+ def test_add_view_with_path_info_match(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, path_info='/foo')
+ config.add_view(view=view, path_info='/foo')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.path_info = '/foo'
self.assertEqual(wrapper(None, request), 'OK')
- def test_with_path_info_nomatch(self):
+ def test_add_view_with_path_info_nomatch(self):
view = lambda *arg: 'OK'
config = self._makeOne()
- config.view(view=view, path_info='/foo')
+ config.add_view(view=view, path_info='/foo')
wrapper = self._getViewCallable(config)
request = self._makeRequest(config)
request.path_info = '/'
@@ -713,15 +713,15 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(len(routes[0].predicates), num_predicates)
return route
- def test_route_defaults(self):
+ def test_add_route_defaults(self):
config = self._makeOne()
- config.route('name', 'path')
+ config.add_route('name', 'path')
self._assertRoute(config, 'name', 'path')
- def test_route_with_xhr(self):
+ def test_add_route_with_xhr(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', xhr=True)
+ config.add_route('name', 'path', xhr=True)
request_type = self._getRouteRequestIface(config, 'name')
route = self._assertRoute(config, 'name', 'path', 1)
predicate = route.predicates[0]
@@ -732,10 +732,10 @@ class ConfiguratorTests(unittest.TestCase):
request.is_xhr = False
self.assertEqual(predicate(None, request), False)
- def test_route_with_request_method(self):
+ def test_add_route_with_request_method(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', request_method='GET')
+ config.add_route('name', 'path', request_method='GET')
request_type = self._getRouteRequestIface(config, 'name')
route = self._assertRoute(config, 'name', 'path', 1)
predicate = route.predicates[0]
@@ -746,10 +746,10 @@ class ConfiguratorTests(unittest.TestCase):
request.method = 'POST'
self.assertEqual(predicate(None, request), False)
- def test_route_with_path_info(self):
+ def test_add_route_with_path_info(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', path_info='/foo')
+ config.add_route('name', 'path', path_info='/foo')
request_type = self._getRouteRequestIface(config, 'name')
route = self._assertRoute(config, 'name', 'path', 1)
predicate = route.predicates[0]
@@ -760,10 +760,10 @@ class ConfiguratorTests(unittest.TestCase):
request.path_info = '/'
self.assertEqual(predicate(None, request), False)
- def test_route_with_request_param(self):
+ def test_add_route_with_request_param(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', request_param='abc')
+ config.add_route('name', 'path', request_param='abc')
request_type = self._getRouteRequestIface(config, 'name')
route = self._assertRoute(config, 'name', 'path', 1)
predicate = route.predicates[0]
@@ -774,10 +774,10 @@ class ConfiguratorTests(unittest.TestCase):
request.params = {}
self.assertEqual(predicate(None, request), False)
- def test_route_with_header(self):
+ def test_add_route_with_header(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', header='Host')
+ config.add_route('name', 'path', header='Host')
request_type = self._getRouteRequestIface(config, 'name')
route = self._assertRoute(config, 'name', 'path', 1)
predicate = route.predicates[0]
@@ -788,10 +788,10 @@ class ConfiguratorTests(unittest.TestCase):
request.headers = {}
self.assertEqual(predicate(None, request), False)
- def test_route_with_accept(self):
+ def test_add_route_with_accept(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', accept='text/xml')
+ config.add_route('name', 'path', accept='text/xml')
request_type = self._getRouteRequestIface(config, 'name')
route = self._assertRoute(config, 'name', 'path', 1)
predicate = route.predicates[0]
@@ -802,19 +802,19 @@ class ConfiguratorTests(unittest.TestCase):
request.accept = ['text/html']
self.assertEqual(predicate(None, request), False)
- def test_route_with_view(self):
+ def test_add_route_with_view(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', view=view)
+ config.add_route('name', 'path', view=view)
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
self.assertEqual(wrapper(None, None), 'OK')
self._assertRoute(config, 'name', 'path')
- def test_route_with_view_for(self):
+ def test_add_route_with_view_for(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', view=view, view_for=IDummy)
+ config.add_route('name', 'path', view=view, view_for=IDummy)
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, IDummy, request_type)
self.assertEqual(wrapper(None, None), 'OK')
@@ -822,10 +822,10 @@ class ConfiguratorTests(unittest.TestCase):
wrapper = self._getViewCallable(config, IOther, request_type)
self.assertEqual(wrapper, None)
- def test_route_with_view_for_alias(self):
+ def test_add_route_with_view_for_alias(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', view=view, for_=IDummy)
+ config.add_route('name', 'path', view=view, for_=IDummy)
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, IDummy, request_type)
self.assertEqual(wrapper(None, None), 'OK')
@@ -833,10 +833,10 @@ class ConfiguratorTests(unittest.TestCase):
wrapper = self._getViewCallable(config, IOther, request_type)
self.assertEqual(wrapper, None)
- def test_route_with_view_request_method(self):
+ def test_add_route_with_view_request_method(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', view=view, view_request_method='GET')
+ config.add_route('name', 'path', view=view, view_request_method='GET')
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
route = self._assertRoute(config, 'name', 'path')
@@ -847,10 +847,10 @@ class ConfiguratorTests(unittest.TestCase):
request.method = 'POST'
self._assertNotFound(wrapper, None, request)
- def test_route_with_view_header(self):
+ def test_add_route_with_view_header(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', view=view, view_header='Host')
+ config.add_route('name', 'path', view=view, view_header='Host')
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
route = self._assertRoute(config, 'name', 'path')
@@ -861,10 +861,10 @@ class ConfiguratorTests(unittest.TestCase):
request.headers = {}
self._assertNotFound(wrapper, None, request)
- def test_route_with_view_xhr(self):
+ def test_add_route_with_view_xhr(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', view=view, view_xhr=True)
+ config.add_route('name', 'path', view=view, view_xhr=True)
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
route = self._assertRoute(config, 'name', 'path')
@@ -875,10 +875,10 @@ class ConfiguratorTests(unittest.TestCase):
request.is_xhr = False
self._assertNotFound(wrapper, None, request)
- def test_route_with_view_path_info(self):
+ def test_add_route_with_view_path_info(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', view=view, view_path_info='/foo')
+ config.add_route('name', 'path', view=view, view_path_info='/foo')
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
route = self._assertRoute(config, 'name', 'path')
@@ -889,10 +889,10 @@ class ConfiguratorTests(unittest.TestCase):
request.path_info = '/'
self._assertNotFound(wrapper, None, request)
- def test_route_with_view_accept(self):
+ def test_add_route_with_view_accept(self):
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', view=view, view_accept='text/xml')
+ config.add_route('name', 'path', view=view, view_accept='text/xml')
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
route = self._assertRoute(config, 'name', 'path')
@@ -903,11 +903,11 @@ class ConfiguratorTests(unittest.TestCase):
request.accept = ['text/html']
self._assertNotFound(wrapper, None, request)
- def test_route_with_view_containment(self):
+ def test_add_route_with_view_containment(self):
from zope.interface import directlyProvides
config = self._makeOne()
view = lambda *arg: 'OK'
- config.route('name', 'path', view=view, view_containment=IDummy)
+ config.add_route('name', 'path', view=view, view_containment=IDummy)
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
route = self._assertRoute(config, 'name', 'path')
@@ -916,29 +916,29 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(wrapper(context, None), 'OK')
self._assertNotFound(wrapper, None, None)
- def test_route_with_view_renderer(self):
+ def test_add_route_with_view_renderer(self):
config = self._makeOne()
self._registerRenderer(config)
view = lambda *arg: 'OK'
- config.route('name', 'path', view=view,
- view_renderer='fixtures/minimal.txt')
+ config.add_route('name', 'path', view=view,
+ view_renderer='fixtures/minimal.txt')
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
route = self._assertRoute(config, 'name', 'path')
self.assertEqual(wrapper(None, None).body, 'Hello!')
- def test_route_with_view_renderer_alias(self):
+ def test_add_route_with_view_renderer_alias(self):
config = self._makeOne()
self._registerRenderer(config)
view = lambda *arg: 'OK'
- config.route('name', 'path', view=view,
- renderer='fixtures/minimal.txt')
+ config.add_route('name', 'path', view=view,
+ renderer='fixtures/minimal.txt')
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
route = self._assertRoute(config, 'name', 'path')
self.assertEqual(wrapper(None, None).body, 'Hello!')
- def test_route_with_view_permission(self):
+ def test_add_route_with_view_permission(self):
from repoze.bfg.interfaces import IAuthenticationPolicy
from repoze.bfg.interfaces import IAuthorizationPolicy
config = self._makeOne()
@@ -946,13 +946,13 @@ class ConfiguratorTests(unittest.TestCase):
config.registry.registerUtility(policy, IAuthenticationPolicy)
config.registry.registerUtility(policy, IAuthorizationPolicy)
view = lambda *arg: 'OK'
- config.route('name', 'path', view=view, view_permission='edit')
+ config.add_route('name', 'path', view=view, view_permission='edit')
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
route = self._assertRoute(config, 'name', 'path')
self.failUnless(hasattr(wrapper, '__call_permissive__'))
- def test_route_with_view_permission_alias(self):
+ def test_add_route_with_view_permission_alias(self):
from repoze.bfg.interfaces import IAuthenticationPolicy
from repoze.bfg.interfaces import IAuthorizationPolicy
config = self._makeOne()
@@ -960,7 +960,7 @@ class ConfiguratorTests(unittest.TestCase):
config.registry.registerUtility(policy, IAuthenticationPolicy)
config.registry.registerUtility(policy, IAuthorizationPolicy)
view = lambda *arg: 'OK'
- config.route('name', 'path', view=view, permission='edit')
+ config.add_route('name', 'path', view=view, permission='edit')
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
route = self._assertRoute(config, 'name', 'path')
@@ -991,13 +991,13 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(overrides.inserted, [('path', 'opackage', 'oprefix')])
self.assertEqual(overrides.package, package)
- def test_static_here_relative(self):
+ def test_add_static_view_here_relative(self):
from repoze.bfg.static import PackageURLParser
from zope.interface import implementedBy
from repoze.bfg.static import StaticRootFactory
from repoze.bfg.interfaces import IView
config = self._makeOne()
- config.static('static', 'fixtures/static')
+ config.add_static_view('static', 'fixtures/static')
request_type = self._getRouteRequestIface(config, 'static')
route = self._assertRoute(config, 'static', 'static*subpath')
self.assertEqual(route.factory.__class__, StaticRootFactory)
@@ -1007,13 +1007,13 @@ class ConfiguratorTests(unittest.TestCase):
request = self._makeRequest(config)
self.assertEqual(wrapped(None, request).__class__, PackageURLParser)
- def test_static_package_relative(self):
+ def test_add_static_view_package_relative(self):
from repoze.bfg.static import PackageURLParser
from zope.interface import implementedBy
from repoze.bfg.static import StaticRootFactory
from repoze.bfg.interfaces import IView
config = self._makeOne()
- config.static('static', 'repoze.bfg.tests:fixtures/static')
+ config.add_static_view('static', 'repoze.bfg.tests:fixtures/static')
request_type = self._getRouteRequestIface(config, 'static')
route = self._assertRoute(config, 'static', 'static*subpath')
self.assertEqual(route.factory.__class__, StaticRootFactory)
@@ -1023,7 +1023,7 @@ class ConfiguratorTests(unittest.TestCase):
request = self._makeRequest(config)
self.assertEqual(wrapped(None, request).__class__, PackageURLParser)
- def test_static_absolute(self):
+ def test_add_static_view_absolute(self):
from paste.urlparser import StaticURLParser
import os
from zope.interface import implementedBy
@@ -1032,7 +1032,7 @@ class ConfiguratorTests(unittest.TestCase):
config = self._makeOne()
here = os.path.dirname(__file__)
static_path = os.path.join(here, 'fixtures', 'static')
- config.static('static', static_path)
+ config.add_static_view('static', static_path)
request_type = self._getRouteRequestIface(config, 'static')
route = self._assertRoute(config, 'static', 'static*subpath')
self.assertEqual(route.factory.__class__, StaticRootFactory)
@@ -1089,39 +1089,39 @@ class ConfiguratorTests(unittest.TestCase):
result = view(context, request)
self.assertEqual(result, 'OK2')
- def test_notfound(self):
+ def test_set_notfound_view(self):
from repoze.bfg.interfaces import INotFoundView
config = self._makeOne()
view = lambda *arg: 'OK'
- config.notfound(view)
+ config.set_notfound_view(view)
request = self._makeRequest(config)
view = config.registry.getUtility(INotFoundView)
result = view(None, request)
self.assertEqual(result, 'OK')
- def test_forbidden(self):
+ def test_set_forbidden_view(self):
from repoze.bfg.interfaces import IForbiddenView
config = self._makeOne()
view = lambda *arg: 'OK'
- config.forbidden(view)
+ config.set_forbidden_view(view)
request = self._makeRequest(config)
view = config.registry.getUtility(IForbiddenView)
result = view(None, request)
self.assertEqual(result, 'OK')
- def test_authentication_policy(self):
+ def test__set_authentication_policy(self):
from repoze.bfg.interfaces import IAuthenticationPolicy
config = self._makeOne()
policy = object()
- config.authentication_policy(policy)
+ config._set_authentication_policy(policy)
self.assertEqual(
config.registry.getUtility(IAuthenticationPolicy), policy)
- def test_authorization_policy(self):
+ def test__set_authorization_policy(self):
from repoze.bfg.interfaces import IAuthorizationPolicy
config = self._makeOne()
policy = object()
- config.authorization_policy(policy)
+ config._set_authorization_policy(policy)
self.assertEqual(
config.registry.getUtility(IAuthorizationPolicy), policy)
@@ -1274,7 +1274,7 @@ class ConfiguratorTests(unittest.TestCase):
"'view_name' against context None): Allowed ("
"no permission registered)")
- def test__derive_view_debug_authorization_permission_authpol_permitted(self):
+ def test__derive_view_debug_auth_permission_authpol_permitted(self):
view = lambda *arg: 'OK'
config = self._makeOne()
self._registerSettings(config, debug_authorization=True,
@@ -1295,7 +1295,7 @@ class ConfiguratorTests(unittest.TestCase):
"debug_authorization of url url (view name "
"'view_name' against context None): True")
- def test__derive_view_debug_authorization_permission_authpol_denied(self):
+ def test__derive_view_debug_auth_permission_authpol_denied(self):
from repoze.bfg.exceptions import Forbidden
view = lambda *arg: 'OK'
config = self._makeOne()
@@ -1317,7 +1317,7 @@ class ConfiguratorTests(unittest.TestCase):
"debug_authorization of url url (view name "
"'view_name' against context None): False")
- def test__derive_view_debug_authorization_permission_authpol_denied2(self):
+ def test__derive_view_debug_auth_permission_authpol_denied2(self):
view = lambda *arg: 'OK'
config = self._makeOne()
self._registerSettings(config,
@@ -1421,27 +1421,27 @@ class ConfiguratorTests(unittest.TestCase):
inner_view, viewname='inner', wrapper_viewname='owrap')
result = self.assertRaises(ValueError, wrapped, None, request)
- def test_resource_samename(self):
+ def test_override_resource_samename(self):
from zope.configuration.exceptions import ConfigurationError
config = self._makeOne()
- self.assertRaises(ConfigurationError, config.resource, 'a', 'a')
+ self.assertRaises(ConfigurationError, config.override_resource,'a', 'a')
- def test_resource_override_directory_with_file(self):
+ def test_override_resource_directory_with_file(self):
from zope.configuration.exceptions import ConfigurationError
config = self._makeOne()
- self.assertRaises(ConfigurationError, config.resource,
+ self.assertRaises(ConfigurationError, config.override_resource,
'a:foo/', 'a:foo.pt')
- def test_resource_override_file_with_directory(self):
+ def test_override_resource_file_with_directory(self):
from zope.configuration.exceptions import ConfigurationError
config = self._makeOne()
- self.assertRaises(ConfigurationError, config.resource,
+ self.assertRaises(ConfigurationError, config.override_resource,
'a:foo.pt', 'a:foo/')
- def test_resource_success(self):
+ def test_override_resource_success(self):
config = self._makeOne()
override = DummyUnderOverride()
- config.resource(
+ config.override_resource(
'repoze.bfg.tests.fixtureapp:templates/foo.pt',
'repoze.bfg.tests.fixtureapp.subpackage:templates/bar.pt',
_override=override)
@@ -1452,6 +1452,15 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(override.override_package, subpackage)
self.assertEqual(override.override_prefix, 'templates/bar.pt')
+ def test_add_renderer(self):
+ from repoze.bfg.interfaces import IRendererFactory
+ config = self._makeOne()
+ renderer = object()
+ config.add_renderer('name', renderer)
+ self.assertEqual(config.registry.getUtility(IRendererFactory, 'name'),
+ renderer)
+
+
class Test__map_view(unittest.TestCase):
def setUp(self):
from repoze.bfg.registry import Registry
diff --git a/repoze/bfg/tests/test_renderers.py b/repoze/bfg/tests/test_renderers.py
index c368228df..687f47906 100644
--- a/repoze/bfg/tests/test_renderers.py
+++ b/repoze/bfg/tests/test_renderers.py
@@ -125,14 +125,14 @@ class TestRendererFromName(unittest.TestCase):
return renderer_from_name(path)
def test_it(self):
- from repoze.bfg.interfaces import ITemplateRendererFactory
+ from repoze.bfg.interfaces import IRendererFactory
import os
here = os.path.dirname(os.path.abspath(__file__))
fixture = os.path.join(here, 'fixtures/minimal.pt')
renderer = {}
def factory(path, **kw):
return renderer
- testing.registerUtility(factory, ITemplateRendererFactory, name='.pt')
+ testing.registerUtility(factory, IRendererFactory, name='.pt')
result = self._callFUT(fixture)
self.assertEqual(result, renderer)
diff --git a/repoze/bfg/tests/test_zcml.py b/repoze/bfg/tests/test_zcml.py
index ec58cc193..b9e70c0bd 100644
--- a/repoze/bfg/tests/test_zcml.py
+++ b/repoze/bfg/tests/test_zcml.py
@@ -543,7 +543,7 @@ class TestResourceDirective(unittest.TestCase):
self.assertEqual(len(actions), 1)
action = actions[0]
self.assertEqual(action['callable'].im_func,
- Configurator.resource.im_func)
+ Configurator.override_resource.im_func)
self.assertEqual(action['discriminator'], None)
self.assertEqual(action['args'], ('a', 'b', None))
diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py
index 9c0f381f1..5d6fdb8d8 100644
--- a/repoze/bfg/zcml.py
+++ b/repoze/bfg/zcml.py
@@ -165,7 +165,7 @@ def view(
def register():
config = Configurator(reg)
- config.view(
+ config.add_view(
permission=permission, for_=for_, view=view, name=name,
request_type=request_type, route_name=route_name,
request_method=request_method, request_param=request_param,
@@ -244,7 +244,7 @@ def route(_context, name, path, view=None, view_for=None,
def register():
config = Configurator(reg)
- config.route(
+ config.add_route(
name,
path,
factory=factory,
@@ -353,7 +353,7 @@ def resource(_context, to_override, override_with):
_context.action(
discriminator = None,
- callable = config.resource,
+ callable = config.override_resource,
args = (to_override, override_with, _context.info),
)
@@ -370,7 +370,7 @@ def repozewho1authenticationpolicy(_context, identifier_name='auth_tkt',
# be found by the view registration machinery
reg = get_current_registry()
config = Configurator(reg)
- config.authentication_policy(policy, _info=_context.info)
+ config._set_authentication_policy(policy, _info=_context.info)
_context.action(discriminator=IAuthenticationPolicy)
class IRemoteUserAuthenticationPolicyDirective(Interface):
@@ -386,7 +386,7 @@ def remoteuserauthenticationpolicy(_context, environ_key='REMOTE_USER',
# be found by the view registration machinery
reg = get_current_registry()
config = Configurator(reg)
- config.authentication_policy(policy, _info=_context.info)
+ config._set_authentication_policy(policy, _info=_context.info)
_context.action(discriminator=IAuthenticationPolicy)
class IAuthTktAuthenticationPolicyDirective(Interface):
@@ -424,7 +424,7 @@ def authtktauthenticationpolicy(_context,
# be found by the view registration machinery
reg = get_current_registry()
config = Configurator(reg)
- config.authentication_policy(policy, _info=_context.info)
+ config._set_authentication_policy(policy, _info=_context.info)
_context.action(discriminator=IAuthenticationPolicy)
class IACLAuthorizationPolicyDirective(Interface):
@@ -436,7 +436,7 @@ def aclauthorizationpolicy(_context):
# found by the view registration machinery
reg = get_current_registry()
config = Configurator(reg)
- config.authorization_policy(policy, _info=_context.info)
+ config._set_authorization_policy(policy, _info=_context.info)
_context.action(discriminator=IAuthorizationPolicy)
class IRendererDirective(Interface):
@@ -453,7 +453,7 @@ def renderer(_context, factory, name=''):
# found by the view machinery
reg = get_current_registry()
config = Configurator(reg)
- config.renderer(factory, name, _info=_context.info)
+ config.add_renderer(name, factory, _info=_context.info)
_context.action(discriminator=(IRendererFactory, name))
class IStaticDirective(Interface):
@@ -484,7 +484,7 @@ def static(_context, name, path, cache_max_age=3600):
_context.action(
discriminator = ('route', name, False, None, None, None, None, None),
- callable=config.static,
+ callable=config.add_static_view,
args = (name, path, cache_max_age, _context.info),
)