Files
deb-python-falcon/tests/test_response_context.py
Kurt Griffiths a085a34b85 feat(Response): Add context property to the Response class (#821)
Add a context property to the Response class, to mirror the context
property that is already available on the Request class.
2016-07-19 17:01:50 -05:00

40 lines
1.0 KiB
Python

from falcon import Response
import falcon.testing as testing
class TestRequestContext(testing.TestBase):
def test_default_response_context(self):
resp = Response()
self.assertIsInstance(resp.context, dict)
def test_custom_response_context(self):
class MyCustomContextType(object):
pass
class MyCustomResponse(Response):
context_type = MyCustomContextType
resp = MyCustomResponse()
self.assertIsInstance(resp.context, MyCustomContextType)
def test_custom_response_context_failure(self):
class MyCustomResponse(Response):
context_type = False
self.assertRaises(TypeError, MyCustomResponse)
def test_custom_response_context_factory(self):
def create_context(resp):
return {'resp': resp}
class MyCustomResponse(Response):
context_type = create_context
resp = MyCustomResponse()
self.assertIsInstance(resp.context, dict)
self.assertIs(resp.context['resp'], resp)