File size: 1,052 Bytes
fc0f7bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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)