mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Add a test for json request
This commit is contained in:
parent
9540ede112
commit
48f1c9afc2
@ -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("""
|
||||
|
Loading…
Reference in New Issue
Block a user