summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2008-11-09 03:25:39 +0000
committerChris McDonough <chrism@agendaless.com>2008-11-09 03:25:39 +0000
commit76c80642d615fa8239966dd73eab79d300e997c1 (patch)
treee3daca81b258f776280b457205ce3ce171d3b54e
parentb4cafa974c8c6452a4a924838df352c95c0901aa (diff)
downloadpyramid-76c80642d615fa8239966dd73eab79d300e997c1.tar.gz
pyramid-76c80642d615fa8239966dd73eab79d300e997c1.tar.bz2
pyramid-76c80642d615fa8239966dd73eab79d300e997c1.zip
registerTemplateRenderer -> registerDummyRenderer
-rw-r--r--docs/api/testing.rst2
-rw-r--r--docs/narr/unittesting.rst6
-rw-r--r--repoze/bfg/testing.py26
-rw-r--r--repoze/bfg/tests/test_testing.py4
4 files changed, 17 insertions, 21 deletions
diff --git a/docs/api/testing.rst b/docs/api/testing.rst
index 2b6e1f8ae..51b017fbf 100644
--- a/docs/api/testing.rst
+++ b/docs/api/testing.rst
@@ -11,7 +11,7 @@
.. autofunction:: registerEventListener
- .. autofunction:: registerTemplateRenderer
+ .. autofunction:: registerDummyRenderer
.. autofunction:: registerView
diff --git a/docs/narr/unittesting.rst b/docs/narr/unittesting.rst
index 8e9894c3f..b3b2321dd 100644
--- a/docs/narr/unittesting.rst
+++ b/docs/narr/unittesting.rst
@@ -58,7 +58,7 @@ unittest TestCase that used the testing API.
def test_view_fn_not_submitted(self):
from my.package import view_fn
- renderer = testing.registerTemplateRenderer('templates/show.pt')
+ renderer = testing.registerDummyRenderer('templates/show.pt')
context = testing.DummyModel()
request = testing.DummyRequest()
response = view_fn(context, request)
@@ -66,7 +66,7 @@ unittest TestCase that used the testing API.
def test_view_fn_submitted(self):
from my.package import view_fn
- renderer = testing.registerTemplateRenderer('templates/submitted.pt')
+ renderer = testing.registerDummyRenderer('templates/submitted.pt')
context = testing.DummyModel()
request = testing.DummyRequest()
request.params['say'] = 'Yo'
@@ -82,7 +82,7 @@ The first test method, ``test_view_fn_not_submitted`` tests the
``view_fn`` function in the case that no "form" values (represented by
request.params) have been submitted. Its first line registers a
"dummy template renderer" named ``templates/show.pt`` via the
-``registerTemplateRenderer`` function (a ``repoze.bfg.testing`` API);
+``registerDummyRenderer`` function (a ``repoze.bfg.testing`` API);
this function returns a DummyTemplateRenderer instance which we hang
on to for later. We then create a ``DummyRequest`` object (it
simulates a WebOb request object), and we create a ``DummyModel``
diff --git a/repoze/bfg/testing.py b/repoze/bfg/testing.py
index 2a186cf26..d32934031 100644
--- a/repoze/bfg/testing.py
+++ b/repoze/bfg/testing.py
@@ -24,9 +24,9 @@ def registerDummySecurityPolicy(userid=None, groupids=(), permissive=True):
def registerModels(models):
""" Registers a dictionary of models. This is most useful for
testing code that wants to call the
- ``repoze.bfg.traversal.find_model`` API. This API is called with
- a path as one of its arguments. If the dictionary you register
- when calling this method contains that path as a key
+ ``repoze.bfg.traversal.find_model`` API. The ``find_model`` API
+ is called with a path as one of its arguments. If the dictionary
+ you register when calling this method contains that path as a key
(e.g. '/foo/bar' or 'foo'), the corresponding value will be
returned to ``find_model`` (and thus to your code)."""
traverser = make_traverser_factory(models)
@@ -47,20 +47,16 @@ def registerEventListener(event_iface=Interface):
registerSubscriber(subscriber, event_iface)
return L
-def registerTemplateRenderer(path, renderer=None, for_=None):
+def registerDummyRenderer(path):
""" Create and register a dummy template renderer at ``path``
(usually a relative filename ala ``templates/foo.pt``) and return
- the renderer object. If ``renderer`` is not ``None``, it will be
- registered as the renderer and returned (no dummy renderer object
- will be created). This function is useful when testing code that
- calls the ``render_template_to_response`` or any other
- ``render_template*`` API of the built-in templating systems. """
- if for_ is None:
- from repoze.bfg.interfaces import ITestingTemplateRenderer
- for_ = ITestingTemplateRenderer
- if renderer is None:
- renderer = DummyTemplateRenderer()
- return registerUtility(renderer, for_, path)
+ the renderer object. This function is useful when testing code
+ that calls the ``render_template_to_response`` or any other
+ ``render_template*`` API of any of the built-in templating
+ systems."""
+ from repoze.bfg.interfaces import ITestingTemplateRenderer
+ renderer = DummyTemplateRenderer()
+ return registerUtility(renderer, ITestingTemplateRenderer, path)
def registerView(name, result='', view=None, for_=(Interface, Interface)):
""" Registers ``repoze.bfg`` view function under the name
diff --git a/repoze/bfg/tests/test_testing.py b/repoze/bfg/tests/test_testing.py
index 03f5bd938..5ef66e759 100644
--- a/repoze/bfg/tests/test_testing.py
+++ b/repoze/bfg/tests/test_testing.py
@@ -47,9 +47,9 @@ class TestTestingFunctions(unittest.TestCase, PlacelessSetup):
from repoze.bfg.traversal import find_model
self.assertEqual(find_model(None, '/ob1'), ob1)
- def test_registerTemplateRenderer(self):
+ def test_registerDummyRenderer(self):
from repoze.bfg import testing
- template = testing.registerTemplateRenderer('templates/foo')
+ template = testing.registerDummyRenderer('templates/foo')
from repoze.bfg.testing import DummyTemplateRenderer
self.failUnless(isinstance(template, DummyTemplateRenderer))
from repoze.bfg.chameleon_zpt import render_template_to_response