mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Use classes to test a command, move code to separate methods under
classes
This commit is contained in:
parent
0576f579ed
commit
5f044d03b7
@ -20,117 +20,129 @@ req_patch = netlib.tutils.treq(
|
||||
)
|
||||
|
||||
|
||||
def test_curl_command():
|
||||
flow = tutils.tflow(req=req_get)
|
||||
result = """curl -H 'header:qvalue' -H 'content-length:7' 'http://address/path'"""
|
||||
assert flow_export.curl_command(flow) == result
|
||||
class TestExportCurlCommand():
|
||||
|
||||
flow = tutils.tflow(req=req_post)
|
||||
result = """curl -X POST 'http://address/path' --data-binary 'content'"""
|
||||
assert flow_export.curl_command(flow) == result
|
||||
def test_get(self):
|
||||
flow = tutils.tflow(req=req_get)
|
||||
result = """curl -H 'header:qvalue' -H 'content-length:7' 'http://address/path'"""
|
||||
assert flow_export.curl_command(flow) == result
|
||||
|
||||
flow = tutils.tflow(req=req_patch)
|
||||
result = """curl -H 'header:qvalue' -H 'content-length:7' -X PATCH 'http://address/path?query=param' --data-binary 'content'"""
|
||||
assert flow_export.curl_command(flow) == result
|
||||
def test_post(self):
|
||||
flow = tutils.tflow(req=req_post)
|
||||
result = """curl -X POST 'http://address/path' --data-binary 'content'"""
|
||||
assert flow_export.curl_command(flow) == result
|
||||
|
||||
def test_patch(self):
|
||||
flow = tutils.tflow(req=req_patch)
|
||||
result = """curl -H 'header:qvalue' -H 'content-length:7' -X PATCH 'http://address/path?query=param' --data-binary 'content'"""
|
||||
assert flow_export.curl_command(flow) == result
|
||||
|
||||
|
||||
def test_python_code():
|
||||
flow = tutils.tflow(req=req_get)
|
||||
result = dedent("""
|
||||
import requests
|
||||
class TestExportPythonCode():
|
||||
|
||||
url = 'http://address/path'
|
||||
def test_get(self):
|
||||
flow = tutils.tflow(req=req_get)
|
||||
result = dedent("""
|
||||
import requests
|
||||
|
||||
headers = {
|
||||
'header': 'qvalue',
|
||||
'content-length': '7',
|
||||
}
|
||||
url = 'http://address/path'
|
||||
|
||||
response = requests.request(
|
||||
method='GET',
|
||||
url=url,
|
||||
headers=headers,
|
||||
)
|
||||
headers = {
|
||||
'header': 'qvalue',
|
||||
'content-length': '7',
|
||||
}
|
||||
|
||||
print(response.text)
|
||||
""").strip()
|
||||
assert flow_export.python_code(flow) == result
|
||||
response = requests.request(
|
||||
method='GET',
|
||||
url=url,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
flow = tutils.tflow(req=req_post)
|
||||
result = dedent("""
|
||||
import requests
|
||||
print(response.text)
|
||||
""").strip()
|
||||
assert flow_export.python_code(flow) == result
|
||||
|
||||
url = 'http://address/path'
|
||||
def test_post(self):
|
||||
flow = tutils.tflow(req=req_post)
|
||||
result = dedent("""
|
||||
import requests
|
||||
|
||||
data = '''content'''
|
||||
url = 'http://address/path'
|
||||
|
||||
response = requests.request(
|
||||
method='POST',
|
||||
url=url,
|
||||
data=data,
|
||||
)
|
||||
data = '''content'''
|
||||
|
||||
print(response.text)
|
||||
""").strip()
|
||||
assert flow_export.python_code(flow) == result
|
||||
response = requests.request(
|
||||
method='POST',
|
||||
url=url,
|
||||
data=data,
|
||||
)
|
||||
|
||||
flow = tutils.tflow(req=req_patch)
|
||||
result = dedent("""
|
||||
import requests
|
||||
print(response.text)
|
||||
""").strip()
|
||||
assert flow_export.python_code(flow) == result
|
||||
|
||||
url = 'http://address/path'
|
||||
def test_patch(self):
|
||||
flow = tutils.tflow(req=req_patch)
|
||||
result = dedent("""
|
||||
import requests
|
||||
|
||||
headers = {
|
||||
'header': 'qvalue',
|
||||
'content-length': '7',
|
||||
}
|
||||
url = 'http://address/path'
|
||||
|
||||
params = {
|
||||
'query': 'param',
|
||||
}
|
||||
headers = {
|
||||
'header': 'qvalue',
|
||||
'content-length': '7',
|
||||
}
|
||||
|
||||
data = '''content'''
|
||||
params = {
|
||||
'query': 'param',
|
||||
}
|
||||
|
||||
response = requests.request(
|
||||
method='PATCH',
|
||||
url=url,
|
||||
headers=headers,
|
||||
params=params,
|
||||
data=data,
|
||||
)
|
||||
data = '''content'''
|
||||
|
||||
print(response.text)
|
||||
""").strip()
|
||||
assert flow_export.python_code(flow) == result
|
||||
response = requests.request(
|
||||
method='PATCH',
|
||||
url=url,
|
||||
headers=headers,
|
||||
params=params,
|
||||
data=data,
|
||||
)
|
||||
|
||||
print(response.text)
|
||||
""").strip()
|
||||
assert flow_export.python_code(flow) == result
|
||||
|
||||
|
||||
def test_raw_request():
|
||||
flow = tutils.tflow(req=req_get)
|
||||
result = dedent("""
|
||||
GET /path HTTP/1.1\r
|
||||
header: qvalue\r
|
||||
content-length: 7\r
|
||||
host: address:22\r
|
||||
\r
|
||||
""").strip(" ").lstrip()
|
||||
assert flow_export.raw_request(flow) == result
|
||||
def TestRawRequest():
|
||||
|
||||
flow = tutils.tflow(req=req_post)
|
||||
result = dedent("""
|
||||
POST /path HTTP/1.1\r
|
||||
host: address:22\r
|
||||
\r
|
||||
content
|
||||
""").strip()
|
||||
assert flow_export.raw_request(flow) == result
|
||||
def test_get(self):
|
||||
flow = tutils.tflow(req=req_get)
|
||||
result = dedent("""
|
||||
GET /path HTTP/1.1\r
|
||||
header: qvalue\r
|
||||
content-length: 7\r
|
||||
host: address:22\r
|
||||
\r
|
||||
""").strip(" ").lstrip()
|
||||
assert flow_export.raw_request(flow) == result
|
||||
|
||||
flow = tutils.tflow(req=req_patch)
|
||||
result = dedent("""
|
||||
PATCH /path?query=param HTTP/1.1\r
|
||||
header: qvalue\r
|
||||
content-length: 7\r
|
||||
host: address:22\r
|
||||
\r
|
||||
content
|
||||
""").strip()
|
||||
assert flow_export.raw_request(flow) == result
|
||||
def test_post(self):
|
||||
flow = tutils.tflow(req=req_post)
|
||||
result = dedent("""
|
||||
POST /path HTTP/1.1\r
|
||||
host: address:22\r
|
||||
\r
|
||||
content
|
||||
""").strip()
|
||||
assert flow_export.raw_request(flow) == result
|
||||
|
||||
def test_patch(self):
|
||||
flow = tutils.tflow(req=req_patch)
|
||||
result = dedent("""
|
||||
PATCH /path?query=param HTTP/1.1\r
|
||||
header: qvalue\r
|
||||
content-length: 7\r
|
||||
host: address:22\r
|
||||
\r
|
||||
content
|
||||
""").strip()
|
||||
assert flow_export.raw_request(flow) == result
|
||||
|
Loading…
Reference in New Issue
Block a user