diff options
author | Shadab Zafar <dufferzafar0@gmail.com> | 2016-03-04 01:06:09 +0530 |
---|---|---|
committer | Shadab Zafar <dufferzafar0@gmail.com> | 2016-03-04 01:06:09 +0530 |
commit | 48f1c9afc2e5d02c8de717e2fc9030a7884d493b (patch) | |
tree | 9d8bdc3f3f8076d597f578471b4946f6c051130c | |
parent | 9540ede11222cf1e0d796d34b82481173405c520 (diff) | |
download | mitmproxy-48f1c9afc2e5d02c8de717e2fc9030a7884d493b.tar.gz mitmproxy-48f1c9afc2e5d02c8de717e2fc9030a7884d493b.tar.bz2 mitmproxy-48f1c9afc2e5d02c8de717e2fc9030a7884d493b.zip |
Add a test for json request
-rw-r--r-- | test/mitmproxy/test_flow_export.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/mitmproxy/test_flow_export.py b/test/mitmproxy/test_flow_export.py index 2dce3fd6..3dc07427 100644 --- a/test/mitmproxy/test_flow_export.py +++ b/test/mitmproxy/test_flow_export.py @@ -1,6 +1,8 @@ +import json from textwrap import dedent import netlib.tutils +from netlib.http import Headers from mitmproxy import flow_export from . import tutils @@ -81,6 +83,35 @@ class TestExportPythonCode(): """).strip() assert flow_export.python_code(flow) == result + def test_post_json(self): + req_post.content = '{"name": "example", "email": "example@example.com"}' + req_post.headers = Headers(content_type="application/json") + flow = tutils.tflow(req=req_post) + result = dedent(""" + import requests + + url = 'http://address/path' + + headers = { + 'content-type': 'application/json', + } + + json = { + "name": "example", + "email": "example@example.com" + } + + response = requests.request( + method='POST', + url=url, + headers=headers, + json=json, + ) + + print(response.text) + """).strip() + assert flow_export.python_code(flow) == result + def test_patch(self): flow = tutils.tflow(req=req_patch) result = dedent(""" |