diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-01-16 18:58:16 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-01-16 18:58:16 +0000 |
| commit | 5a7f9a4d57424f14a1e072cc06b6bf7a191a7d08 (patch) | |
| tree | b44448198ddf8031b3e09b83dd731f2ae1d6623a /repoze/bfg/tests/test_integration.py | |
| parent | 4856cc54bcd5feb97db49f1cca923afb01c0bf02 (diff) | |
| download | pyramid-5a7f9a4d57424f14a1e072cc06b6bf7a191a7d08.tar.gz pyramid-5a7f9a4d57424f14a1e072cc06b6bf7a191a7d08.tar.bz2 pyramid-5a7f9a4d57424f14a1e072cc06b6bf7a191a7d08.zip | |
Features
--------
- The functionality of ``repoze.bfg.convention`` has been merged into
the core. Applications which make use of ``repoze.bfg.convention``
will continue to work indefinitely, but it is recommended that apps
stop depending upon it. To do so, substitute imports of
``repoze.bfg.convention.bfg_view`` with imports of
``repoze.bfg.view.bfg_view``, and change the stanza in ZCML from
``<convention package=".">`` to ``<grok package=".">``. As a result
of the merge, bfg has grown a new dependency: ``martian``.
- View functions which use the pushpage decorator are now pickleable
(meaning their use won't prevent a ``configure.zcml.cache`` file
from being written to disk).
Implementation Changes
----------------------
- The ``wsgiapp`` decorator now uses ``webob.Request.get_response`` to
do its work rather than relying on howgrown WSGI code.
Diffstat (limited to 'repoze/bfg/tests/test_integration.py')
| -rw-r--r-- | repoze/bfg/tests/test_integration.py | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/repoze/bfg/tests/test_integration.py b/repoze/bfg/tests/test_integration.py new file mode 100644 index 000000000..76004af7b --- /dev/null +++ b/repoze/bfg/tests/test_integration.py @@ -0,0 +1,152 @@ +import unittest + +from repoze.bfg.wsgi import wsgiapp +from repoze.bfg.view import bfg_view +from repoze.bfg.push import pushpage + +from zope.interface import Interface + +from zope.testing.cleanup import cleanUp + +class INothing(Interface): + pass + +@bfg_view(for_=INothing) +@wsgiapp +def wsgiapptest(environ, start_response): + """ """ + return '123' + +class WGSIAppPlusBFGViewTests(unittest.TestCase): + def setUp(self): + cleanUp() + + def tearDown(self): + cleanUp() + + def test_it(self): + import types + self.assertEqual(wsgiapptest.__is_bfg_view__, True) + self.failUnless(type(wsgiapptest) is types.FunctionType) + context = DummyContext() + request = DummyRequest() + result = wsgiapptest(context, request) + self.assertEqual(result, '123') + + def test_grokkage(self): + from repoze.bfg.interfaces import IRequest + from repoze.bfg.interfaces import IView + from repoze.bfg.zcml import grok + context = DummyContext() + from repoze.bfg.tests import test_integration + grok(context, test_integration) + actions = context.actions + self.assertEqual(len(actions), 2) + action = actions[1] + self.assertEqual(action['args'], + ('registerAdapter', + wsgiapptest, (INothing, IRequest), IView, '', None)) + +@bfg_view(for_=INothing) +@pushpage('fake.pt') +def pushtest(context, request): + """ """ + return {'a':1} + +class PushPagePlusBFGViewTests(unittest.TestCase): + def setUp(self): + cleanUp() + + def tearDown(self): + cleanUp() + + def test_it(self): + import types + import os + from repoze.bfg.testing import registerDummyRenderer + path = os.path.join(os.path.dirname(__file__), 'fake.pt') + renderer = registerDummyRenderer(path) + self.assertEqual(pushtest.__is_bfg_view__, True) + self.failUnless(type(pushtest) is types.FunctionType) + context = DummyContext() + request = DummyRequest() + result = pushtest(context, request) + self.assertEqual(result.status, '200 OK') + + def test_grokkage(self): + from repoze.bfg.interfaces import IRequest + from repoze.bfg.interfaces import IView + from repoze.bfg.zcml import grok + context = DummyContext() + from repoze.bfg.tests import test_integration + grok(context, test_integration) + actions = context.actions + self.assertEqual(len(actions), 2) + action = actions[0] + self.assertEqual(action['args'], + ('registerAdapter', + pushtest, (INothing, IRequest), IView, '', None)) + +class TestFixtureApp(unittest.TestCase): + def setUp(self): + cleanUp() + + def tearDown(self): + cleanUp() + + def test_registry_actions_can_be_pickled_and_unpickled(self): + import repoze.bfg.tests.fixtureapp as package + from zope.configuration import config + from zope.configuration import xmlconfig + context = config.ConfigurationMachine() + xmlconfig.registerCommonDirectives(context) + context.package = package + xmlconfig.include(context, 'configure.zcml', package) + context.execute_actions(clear=False) + actions = context.actions + import cPickle + dumped = cPickle.dumps(actions, -1) + new = cPickle.loads(dumped) + self.assertEqual(len(actions), len(new)) + +class TestGrokkedApp(unittest.TestCase): + def setUp(self): + cleanUp() + + def tearDown(self): + cleanUp() + + def test_registry_actions_cannot_be_pickled_and_unpickled(self): + import repoze.bfg.tests.grokkedapp as package + + from zope.configuration import config + from zope.configuration import xmlconfig + context = config.ConfigurationMachine() + xmlconfig.registerCommonDirectives(context) + context.package = package + xmlconfig.include(context, 'configure.zcml', package) + actions = context.actions + import cPickle + self.assertRaises(cPickle.PicklingError, cPickle.dumps, actions, -1) + self.assertEqual(len(actions), 5) + +class DummyContext: + pass + +class DummyRequest: + subpath = ('__init__.py',) + environ = {'REQUEST_METHOD':'GET', 'wsgi.version':(1,0)} + def get_response(self, application): + return application(None, None) + +class DummyContext: + def __init__(self): + self.actions = [] + self.info = None + + def action(self, discriminator, callable, args): + self.actions.append( + {'discriminator':discriminator, + 'callable':callable, + 'args':args} + ) |
