Coverage for hookee/plugins/response_info.py: 100.00%

# Coverage for hookee/plugins/response_info.py : 100.00%

## 19 statements

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 from hookee.pluginmanager import RESPONSE_PLUGIN

2 from hookee.util import PrintUtil

3

4 __author__ = "Alex Laird"

5 __copyright__ = "Copyright 2020, Alex Laird"

6 __version__ = "1.2.2"

7

8 plugin_type = RESPONSE_PLUGIN

9 description = "Print the `response`'s status code, headers, and body, if defined."

10

11 print_util = None # type: PrintUtil

12

13

14 def setup(hookee_manager):

15 global print_util

16

17 print_util = hookee_manager.print_util

18

19

20 def run(request, response):

21 print_util.print_basic("Status Code: {}".format(response.status_code), color=print_util.request_color)

22 if response.headers:

23 print_util.print_dict("Headers", dict(response.headers), color=print_util.request_color)

24 if response.data:

25 if response.is_json:

26 print_util.print_dict("Body", response.get_json(), color=print_util.request_color)

27 else:

28 print_util.print_basic("Body: {}".format(response.data.decode("utf-8")), color=print_util.request_color)

29

30 return response