summaryrefslogtreecommitdiff
path: root/docs/narr/MyProject/myproject/tests.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2008-08-24 01:58:26 +0000
committerChris McDonough <chrism@agendaless.com>2008-08-24 01:58:26 +0000
commit2c647036d9ed5e5a27cb6b2a5700a8f0d3a7d2a7 (patch)
treeee9557256044c720a71bb67341df5413dc0c21a6 /docs/narr/MyProject/myproject/tests.py
parent980db5f3a1b2e7c8f46136f42ea521ee6987da7c (diff)
downloadpyramid-2c647036d9ed5e5a27cb6b2a5700a8f0d3a7d2a7.tar.gz
pyramid-2c647036d9ed5e5a27cb6b2a5700a8f0d3a7d2a7.tar.bz2
pyramid-2c647036d9ed5e5a27cb6b2a5700a8f0d3a7d2a7.zip
Second checkin using StudlyCaps version of MyProject.
Diffstat (limited to 'docs/narr/MyProject/myproject/tests.py')
-rw-r--r--docs/narr/MyProject/myproject/tests.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/docs/narr/MyProject/myproject/tests.py b/docs/narr/MyProject/myproject/tests.py
new file mode 100644
index 000000000..d3d4628ff
--- /dev/null
+++ b/docs/narr/MyProject/myproject/tests.py
@@ -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 myproject
+ import zope.configuration.xmlconfig
+ zope.configuration.xmlconfig.file('configure.zcml',
+ package=myproject)
+
+ 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 myproject.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 myproject' 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