summaryrefslogtreecommitdiff
path: root/pecan/tests/test_base.py
diff options
context:
space:
mode:
authorRyan Petrello <lists@ryanpetrello.com>2014-06-25 11:19:43 -0400
committerRyan Petrello <lists@ryanpetrello.com>2014-06-25 11:41:53 -0400
commit21f70bbba74ab940b3bf24bfb4cc859fe8926492 (patch)
treeab41f4d7fbc115680355babfbc05049d14984acd /pecan/tests/test_base.py
parent6c7a8b3ee9658c4bb2a2d72f241720861d1da56f (diff)
downloadpecan-21f70bbba74ab940b3bf24bfb4cc859fe8926492.tar.gz
Add support for specifying custom request and response implementations.
I noticed that people using pecan have taken to writing custom webob req/resp subclasses and monkeypatching onto `pecan.request` and `pecan.response`. Let's give them what they need to do this properly. Change-Id: If0ac953e381cec3a744388000a3b3afc0ea2525c
Diffstat (limited to 'pecan/tests/test_base.py')
-rw-r--r--pecan/tests/test_base.py39
1 files changed, 37 insertions, 2 deletions
diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py
index 81471ec..89b7a43 100644
--- a/pecan/tests/test_base.py
+++ b/pecan/tests/test_base.py
@@ -14,8 +14,8 @@ from six import b as b_
from six.moves import cStringIO as StringIO
from pecan import (
- Pecan, expose, request, response, redirect, abort, make_app,
- override_template, render
+ Pecan, Request, Response, expose, request, response, redirect,
+ abort, make_app, override_template, render
)
from pecan.templating import (
_builtin_renderers as builtin_renderers, error_formatters
@@ -954,6 +954,41 @@ class TestManualResponse(PecanTestCase):
assert r.body == b_('Hello, World!')
+class TestCustomResponseandRequest(PecanTestCase):
+
+ def test_custom_objects(self):
+
+ class CustomRequest(Request):
+
+ @property
+ def headers(self):
+ headers = super(CustomRequest, self).headers
+ headers['X-Custom-Request'] = 'ABC'
+ return headers
+
+ class CustomResponse(Response):
+
+ @property
+ def headers(self):
+ headers = super(CustomResponse, self).headers
+ headers['X-Custom-Response'] = 'XYZ'
+ return headers
+
+ class RootController(object):
+ @expose()
+ def index(self):
+ return request.headers.get('X-Custom-Request')
+
+ app = TestApp(Pecan(
+ RootController(),
+ request_cls=CustomRequest,
+ response_cls=CustomResponse
+ ))
+ r = app.get('/')
+ assert r.body == b_('ABC')
+ assert r.headers.get('X-Custom-Response') == 'XYZ'
+
+
class TestThreadLocalState(PecanTestCase):
def test_thread_local_dir(self):