summaryrefslogtreecommitdiff
path: root/docs/narr
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-01-07 04:15:27 +0000
committerChris McDonough <chrism@agendaless.com>2009-01-07 04:15:27 +0000
commit7d32df3d33354dc34c1cb0a086463e4f23d968ce (patch)
treedc33728f73b23a35111eb2d6a5a0077426320266 /docs/narr
parentd67c741ef82c0a14778c691281139ec364c34a27 (diff)
downloadpyramid-7d32df3d33354dc34c1cb0a086463e4f23d968ce.tar.gz
pyramid-7d32df3d33354dc34c1cb0a086463e4f23d968ce.tar.bz2
pyramid-7d32df3d33354dc34c1cb0a086463e4f23d968ce.zip
- Add a method named ``assert_`` to the DummyTemplateRenderer. This
method accepts keyword arguments. Each key/value pair in the keyword arguments causes an assertion to be made that the renderer received this key with a value equal to the asserted value. - Projects generated by the paster templates now use the ``DummyTemplateRenderer.assert_`` method in their view tests.
Diffstat (limited to 'docs/narr')
-rw-r--r--docs/narr/MyProject/myproject/tests.py2
-rw-r--r--docs/narr/unittesting.rst9
2 files changed, 7 insertions, 4 deletions
diff --git a/docs/narr/MyProject/myproject/tests.py b/docs/narr/MyProject/myproject/tests.py
index 4c2f6a9ec..64314616d 100644
--- a/docs/narr/MyProject/myproject/tests.py
+++ b/docs/narr/MyProject/myproject/tests.py
@@ -28,7 +28,7 @@ class ViewTests(unittest.TestCase):
request = testing.DummyRequest()
renderer = testing.registerDummyRenderer('templates/mytemplate.pt')
response = my_view(context, request)
- self.assertEqual(renderer.project, 'myproject')
+ renderer.assert_(project='myproject')
class ViewIntegrationTests(unittest.TestCase):
""" These tests are integration tests for the view. These test
diff --git a/docs/narr/unittesting.rst b/docs/narr/unittesting.rst
index 165e92411..34a0740e9 100644
--- a/docs/narr/unittesting.rst
+++ b/docs/narr/unittesting.rst
@@ -62,7 +62,7 @@ unittest TestCase that used the testing API.
context = testing.DummyModel()
request = testing.DummyRequest()
response = view_fn(context, request)
- self.assertEqual(renderer.say, 'Hello')
+ renderer.assert_(say='Hello')
def test_view_fn_submitted(self):
from my.package import view_fn
@@ -71,7 +71,7 @@ unittest TestCase that used the testing API.
request = testing.DummyRequest()
request.params['say'] = 'Yo'
response = view_fn(context, request)
- self.assertEqual(renderer.say, 'Yo')
+ renderer.assert_(say='Yo')
In the above example, we create a ``MyTest`` test case that inherits
from ``unittest.TestCase``. If it's in our :mod:`repoze.bfg`
@@ -94,7 +94,10 @@ the dummy renderer is called, it will set attributes on itself
corresponding to the non-path keyword arguments provided to the
``render_template_to_response`` function. We check that the ``say``
parameter sent into the template rendering function was ``Hello`` in
-this specific example.
+this specific example. The ``assert_`` method of the renderer we've
+created will raise an ``AssertionError`` if the value passed to the
+renderer as ``say`` does not equal ``Hello`` (any number of keyword
+arguments are supported).
The second test method, named ``test_view_fn_submitted`` tests the
alternate case, where the ``say`` form value has already been set in