From 8e0dfcc679b965374ad2f13532e6e483dab4c6e0 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 19 Jul 2008 22:02:33 +0000 Subject: Indicate how to run tests. --- repoze/bfg/paster_template/+package+/tests.py_tmpl | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 repoze/bfg/paster_template/+package+/tests.py_tmpl (limited to 'repoze') diff --git a/repoze/bfg/paster_template/+package+/tests.py_tmpl b/repoze/bfg/paster_template/+package+/tests.py_tmpl new file mode 100644 index 000000000..dc8dc11f3 --- /dev/null +++ b/repoze/bfg/paster_template/+package+/tests.py_tmpl @@ -0,0 +1,45 @@ +import unittest + +class ViewTests(unittest.TestCase): + def setUp(self): + # This sets up the application registry with the registrations + # your application declares in its configure.zcml (including + # dependent registrations for repoze.bfg itself). This is a + # heavy-hammer way of making sure that your tests have enough + # context to run properly. But tests will run faster if you + # use only the registrations you need programmatically, so you + # should explore ways to do that rather than rely on ZCML (see + # the repoze.bfg tests for inspiration). + self._cleanup() + import {{project}} + import zope.configuration.xmlconfig + zope.configuration.xmlconfig.file('configure.zcml', + package={{project}}) + + def tearDown(self): + self._cleanup() + + def _cleanup(self): + # this clears the application registry + from zope.testing.cleanup import cleanUp + cleanUp() + + def test_my_view(self): + from {{project}}.views import my_view + context = DummyContext() + request = DummyRequest() + result = my_view(context, request) + self.assertEqual(result.status, '200 OK') + body = result.app_iter[0] + self.failUnless('Welcome to {{project}}' in body) + self.assertEqual(len(result.headerlist), 2) + self.assertEqual(result.headerlist[0], + ('content-type', 'text/html; charset=UTF-8')) + self.assertEqual(result.headerlist[1], ('Content-Length', + str(len(body)))) + +class DummyContext: + pass + +class DummyRequest: + pass -- cgit v1.2.3