From 5eca2223d538752721ead11c63118df7689bb52d Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Mon, 7 Mar 2016 09:28:09 +0530 Subject: [PATCH] Add tests for modify_response_body example --- test/mitmproxy/test_examples.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py index 88bd90bf7..c7fa90c84 100644 --- a/test/mitmproxy/test_examples.py +++ b/test/mitmproxy/test_examples.py @@ -10,9 +10,14 @@ from examples import ( add_header, modify_form, modify_querystring, + modify_response_body, ) +class DummyContext(object): + pass + + def test_load_scripts(): example_dir = utils.Data(__name__).path("../../examples") scripts = glob.glob("%s/*.py" % example_dir) @@ -57,3 +62,14 @@ def test_modify_querystring(): modify_querystring.request({}, flow) assert flow.request.query["mitmproxy"] == ["rocks"] + +def test_modify_response_body(): + ctx = DummyContext() + tutils.raises(ValueError, modify_response_body.start, ctx, []) + + modify_response_body.start(ctx, ["modify-response-body.py", "mitmproxy", "rocks"]) + assert ctx.old == "mitmproxy" and ctx.new == "rocks" + + flow = tutils.tflow(resp=netutils.tresp(content="I <3 mitmproxy")) + modify_response_body.response(ctx, flow) + assert flow.response.content == "I <3 rocks" \ No newline at end of file