summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-10-09 18:53:16 +0000
committerChris McDonough <chrism@agendaless.com>2009-10-09 18:53:16 +0000
commit4867adcf8a68dfc314f6e7f892e2773f0ad5f5e9 (patch)
tree54d4b88e1bc0fe3eac7f69d675a1ec2f478a1e87
parent0f7d2246e338d1fece6e7f345e5f9dbfe8423473 (diff)
downloadpyramid-4867adcf8a68dfc314f6e7f892e2773f0ad5f5e9.tar.gz
pyramid-4867adcf8a68dfc314f6e7f892e2773f0ad5f5e9.tar.bz2
pyramid-4867adcf8a68dfc314f6e7f892e2773f0ad5f5e9.zip
Fix tests in the face of renderers.
Ditch integration tests.
-rw-r--r--repoze/bfg/paster_templates/routesalchemy/+package+/tests.py_tmpl12
-rw-r--r--repoze/bfg/paster_templates/starter/+package+/tests.py_tmpl64
-rw-r--r--repoze/bfg/paster_templates/zodb/+package+/tests.py_tmpl65
3 files changed, 7 insertions, 134 deletions
diff --git a/repoze/bfg/paster_templates/routesalchemy/+package+/tests.py_tmpl b/repoze/bfg/paster_templates/routesalchemy/+package+/tests.py_tmpl
index 50cd91e50..92caa7b8a 100644
--- a/repoze/bfg/paster_templates/routesalchemy/+package+/tests.py_tmpl
+++ b/repoze/bfg/paster_templates/routesalchemy/+package+/tests.py_tmpl
@@ -8,20 +8,14 @@ def _initTestingDB():
class TestMyView(unittest.TestCase):
def setUp(self):
- testing.cleanUp()
_initTestingDB()
- def tearDown(self):
- testing.cleanUp()
-
def _callFUT(self, request):
from {{package}}.views import my_view
return my_view(request)
def test_it(self):
request = testing.DummyRequest()
- renderer = testing.registerDummyRenderer('templates/mytemplate.pt')
- response = self._callFUT(request)
- self.assertEqual(renderer.root.name, 'root')
- self.assertEqual(renderer.request, request)
- self.assertEqual(renderer.project, '{{package}}')
+ info = self._callFUT(request)
+ self.assertEqual(info['root'].name, 'root')
+ self.assertEqual(info['project'], '{{package}}')
diff --git a/repoze/bfg/paster_templates/starter/+package+/tests.py_tmpl b/repoze/bfg/paster_templates/starter/+package+/tests.py_tmpl
index c52ab2762..3d65ce7a5 100644
--- a/repoze/bfg/paster_templates/starter/+package+/tests.py_tmpl
+++ b/repoze/bfg/paster_templates/starter/+package+/tests.py_tmpl
@@ -3,71 +3,11 @@ import unittest
from repoze.bfg import testing
class ViewTests(unittest.TestCase):
-
- """ These tests are unit tests for the view. They test the
- functionality of *only* the view. They register and use dummy
- implementations of repoze.bfg functionality to allow you to avoid
- testing 'too much'"""
-
- def setUp(self):
- """ cleanUp() is required to clear out the application registry
- between tests (done in setUp for good measure too)
- """
- testing.cleanUp()
-
- def tearDown(self):
- """ cleanUp() is required to clear out the application registry
- between tests
- """
- testing.cleanUp()
-
def test_my_view(self):
from {{package}}.views import my_view
context = testing.DummyModel()
request = testing.DummyRequest()
- renderer = testing.registerDummyRenderer('templates/mytemplate.pt')
- response = my_view(context, request)
- renderer.assert_(project='{{project}}')
-
-class ViewIntegrationTests(unittest.TestCase):
- """ These tests are integration tests for the view. These test
- the functionality the view *and* its integration with the rest of
- the repoze.bfg framework. They cause the entire environment to be
- set up and torn down as if your application was running 'for
- real'. This is a heavy-hammer way of making sure that your tests
- have enough context to run properly, and it tests your view's
- integration with the rest of BFG. You should not use this style
- of test to perform 'true' unit testing as tests will run faster
- and will be easier to write if you use the testing facilities
- provided by bfg and only the registrations you need, as in the
- above ViewTests.
- """
- 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).
- """
- testing.cleanUp()
- import {{package}}
- import zope.configuration.xmlconfig
- zope.configuration.xmlconfig.file('configure.zcml',
- package={{package}})
-
- def tearDown(self):
- """ Clear out the application registry """
- testing.cleanUp()
+ info = my_view(context, request)
+ self.assertEqual(info['project'], '{{project}}')
- def test_my_view(self):
- from {{package}}.views import my_view
- context = testing.DummyModel()
- request = testing.DummyRequest()
- result = my_view(context, request)
- self.assertEqual(result.status, '200 OK')
- body = result.app_iter[0]
- self.failUnless('Welcome to' 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))))
diff --git a/repoze/bfg/paster_templates/zodb/+package+/tests.py_tmpl b/repoze/bfg/paster_templates/zodb/+package+/tests.py_tmpl
index c52ab2762..3de012eda 100644
--- a/repoze/bfg/paster_templates/zodb/+package+/tests.py_tmpl
+++ b/repoze/bfg/paster_templates/zodb/+package+/tests.py_tmpl
@@ -3,71 +3,10 @@ import unittest
from repoze.bfg import testing
class ViewTests(unittest.TestCase):
-
- """ These tests are unit tests for the view. They test the
- functionality of *only* the view. They register and use dummy
- implementations of repoze.bfg functionality to allow you to avoid
- testing 'too much'"""
-
- def setUp(self):
- """ cleanUp() is required to clear out the application registry
- between tests (done in setUp for good measure too)
- """
- testing.cleanUp()
-
- def tearDown(self):
- """ cleanUp() is required to clear out the application registry
- between tests
- """
- testing.cleanUp()
-
- def test_my_view(self):
- from {{package}}.views import my_view
- context = testing.DummyModel()
- request = testing.DummyRequest()
- renderer = testing.registerDummyRenderer('templates/mytemplate.pt')
- response = my_view(context, request)
- renderer.assert_(project='{{project}}')
-
-class ViewIntegrationTests(unittest.TestCase):
- """ These tests are integration tests for the view. These test
- the functionality the view *and* its integration with the rest of
- the repoze.bfg framework. They cause the entire environment to be
- set up and torn down as if your application was running 'for
- real'. This is a heavy-hammer way of making sure that your tests
- have enough context to run properly, and it tests your view's
- integration with the rest of BFG. You should not use this style
- of test to perform 'true' unit testing as tests will run faster
- and will be easier to write if you use the testing facilities
- provided by bfg and only the registrations you need, as in the
- above ViewTests.
- """
- 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).
- """
- testing.cleanUp()
- import {{package}}
- import zope.configuration.xmlconfig
- zope.configuration.xmlconfig.file('configure.zcml',
- package={{package}})
-
- def tearDown(self):
- """ Clear out the application registry """
- testing.cleanUp()
-
def test_my_view(self):
from {{package}}.views import my_view
context = testing.DummyModel()
request = testing.DummyRequest()
- result = my_view(context, request)
- self.assertEqual(result.status, '200 OK')
- body = result.app_iter[0]
- self.failUnless('Welcome to' 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))))
+ info = my_view(context, request)
+ self.assertEqual(info['project'], '{{project}}')