From 7d32df3d33354dc34c1cb0a086463e4f23d968ce Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 7 Jan 2009 04:15:27 +0000 Subject: - 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. --- docs/narr/MyProject/myproject/tests.py | 2 +- docs/narr/unittesting.rst | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'docs/narr') 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 -- cgit v1.2.3