Add tests for modify_response_body example

This commit is contained in:
Shadab Zafar 2016-03-07 09:28:09 +05:30
parent c378fe2199
commit 5eca2223d5

View File

@ -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"