summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2008-07-19 22:02:33 +0000
committerChris McDonough <chrism@agendaless.com>2008-07-19 22:02:33 +0000
commit8e0dfcc679b965374ad2f13532e6e483dab4c6e0 (patch)
tree67d07b275cb359a8429bb716d9f130dae72d487f
parent54f2bbbc50a8129cb1eb43377f48db38572e0e72 (diff)
downloadpyramid-8e0dfcc679b965374ad2f13532e6e483dab4c6e0.tar.gz
pyramid-8e0dfcc679b965374ad2f13532e6e483dab4c6e0.tar.bz2
pyramid-8e0dfcc679b965374ad2f13532e6e483dab4c6e0.zip
Indicate how to run tests.
-rw-r--r--docs/narr/project.rst25
-rw-r--r--repoze/bfg/paster_template/+package+/tests.py_tmpl45
2 files changed, 69 insertions, 1 deletions
diff --git a/docs/narr/project.rst b/docs/narr/project.rst
index 651f505c5..7c48874b7 100644
--- a/docs/narr/project.rst
+++ b/docs/narr/project.rst
@@ -82,4 +82,27 @@ see the following::
easier, as changes to Python code under ``repoze.bfg`` is not put
into effect until the server restarts.
-
+Running The Tests For Your Application
+--------------------------------------
+
+To run unit tests for your application, you should invoke them like so::
+
+ $ python setup.py test -q
+ running test
+ running egg_info
+ writing requirements to myproject.egg-info/requires.txt
+ writing myproject.egg-info/PKG-INFO
+ writing top-level names to myproject.egg-info/top_level.txt
+ writing dependency_links to myproject.egg-info/dependency_links.txt
+ writing entry points to myproject.egg-info/entry_points.txt
+ reading manifest file 'myproject.egg-info/SOURCES.txt'
+ writing manifest file 'myproject.egg-info/SOURCES.txt'
+ running build_ext
+ .
+ ----------------------------------------------------------------------
+ Ran 1 test in 0.566s
+
+ OK
+
+The tests are found in the ``tests.py`` module in your generated
+project. One sample test exists.
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