Created
April 18, 2014 12:14
-
-
Save chrisgeo/11040944 to your computer and use it in GitHub Desktop.
Test add_request_method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TestFooAddRequest(unittest.TestCase): | |
| def setUp(self, environ=None): | |
| self.wsgi_app = self.config.make_wsgi_app() | |
| from webtest import TestApp | |
| self.test_app = TestApp( | |
| self.wsgi_app | |
| ) | |
| def _makeRequest(self, environ=None): | |
| if environ is None: | |
| environ = {} | |
| from pyramid.testing import DummyRequest | |
| request = DummyRequest(environ) | |
| request.registry = self.config.registry | |
| return request | |
| def _makeBeforeRender(self, system, val=None): | |
| from pyramid.events import BeforeRender | |
| return BeforeRender(system, val) | |
| def _makeConfig(self): | |
| from pyramid import testing | |
| config = testing.setUp() | |
| return config | |
| def test_foo(self): | |
| from bar import foo | |
| self.config.add_request_method(foo, name='foo') | |
| class DummyRegistry(object): | |
| #{ | |
| # 'force_account_type': None, | |
| # 'disable_features': False | |
| #} | |
| def __init__(self): | |
| self.settings = {} | |
| def queryUtility(self, *arg, **kw): | |
| pass | |
| class DummyResponse(object): | |
| def __init__(self): | |
| self.headerlist = [] | |
| class DummyUser(object): | |
| id = 2 | |
| def __init__(self): | |
| pass | |
| def to_dict(self): | |
| return self.__dict__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TestFooAddRequest(unittest.TestCase): | |
| def _makeRequest(self, environ=None): | |
| if environ is None: | |
| environ = {} | |
| from pyramid.testing import DummyRequest | |
| request = DummyRequest(environ) | |
| request.registry = self.config.registry | |
| return request | |
| def _makeBeforeRender(self, system, val=None): | |
| from pyramid.events import BeforeRender | |
| return BeforeRender(system, val) | |
| def _makeConfig(self): | |
| from pyramid import testing | |
| config = testing.setUp() | |
| return config | |
| def test_foo(self): | |
| from bar import foo | |
| config = self._makeConfig() | |
| config.set_request_factory(self._makeRequest()) | |
| config.add_request_method(foo, name='foo') | |
| assert request.foo() == 'foobarbaz' | |
| class DummyRegistry(object): | |
| #{ | |
| # 'force_account_type': None, | |
| # 'disable_features': False | |
| #} | |
| def __init__(self): | |
| self.settings = {} | |
| def queryUtility(self, *arg, **kw): | |
| pass | |
| class DummyResponse(object): | |
| def __init__(self): | |
| self.headerlist = [] | |
| class DummyUser(object): | |
| id = 2 | |
| def __init__(self): | |
| pass | |
| def to_dict(self): | |
| return self.__dict__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment