aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/mitmproxy/test_flow_export.py61
1 files changed, 27 insertions, 34 deletions
diff --git a/test/mitmproxy/test_flow_export.py b/test/mitmproxy/test_flow_export.py
index ae0649d2..516ee4eb 100644
--- a/test/mitmproxy/test_flow_export.py
+++ b/test/mitmproxy/test_flow_export.py
@@ -21,62 +21,54 @@ def python_equals(testdata, text):
assert clean_blanks(text).rstrip() == clean_blanks(d).rstrip()
-req_get = netlib.tutils.treq(
- method='GET',
- content='',
-)
+req_get = lambda: netlib.tutils.treq(method='GET', content='')
-req_post = netlib.tutils.treq(
- method='POST',
- headers=None,
-)
+req_post = lambda: netlib.tutils.treq(method='POST', headers=None)
-req_patch = netlib.tutils.treq(
- method='PATCH',
- path=b"/path?query=param",
-)
+req_patch = lambda: netlib.tutils.treq(method='PATCH', path=b"/path?query=param")
class TestExportCurlCommand():
def test_get(self):
- flow = tutils.tflow(req=req_get)
+ 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
def test_post(self):
- flow = tutils.tflow(req=req_post)
+ 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)
+ 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
class TestExportPythonCode():
def test_get(self):
- flow = tutils.tflow(req=req_get)
+ flow = tutils.tflow(req=req_get())
python_equals("test_flow_export/python_get.py", flow_export.python_code(flow))
def test_post(self):
- flow = tutils.tflow(req=req_post)
+ flow = tutils.tflow(req=req_post())
python_equals("test_flow_export/python_post.py", flow_export.python_code(flow))
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)
+ p = req_post()
+ p.content = '{"name": "example", "email": "example@example.com"}'
+ p.headers = Headers(content_type="application/json")
+ flow = tutils.tflow(req=p)
python_equals("test_flow_export/python_post_json.py", flow_export.python_code(flow))
def test_patch(self):
- flow = tutils.tflow(req=req_patch)
+ flow = tutils.tflow(req=req_patch())
python_equals("test_flow_export/python_patch.py", flow_export.python_code(flow))
class TestRawRequest():
def test_get(self):
- flow = tutils.tflow(req=req_get)
+ flow = tutils.tflow(req=req_get())
result = dedent("""
GET /path HTTP/1.1\r
header: qvalue\r
@@ -87,18 +79,17 @@ class TestRawRequest():
assert flow_export.raw_request(flow) == result
def test_post(self):
- flow = tutils.tflow(req=req_post)
+ flow = tutils.tflow(req=req_post())
result = dedent("""
POST /path HTTP/1.1\r
- content-type: application/json\r
host: address:22\r
\r
- {"name": "example", "email": "example@example.com"}
+ content
""").strip()
assert flow_export.raw_request(flow) == result
def test_patch(self):
- flow = tutils.tflow(req=req_patch)
+ flow = tutils.tflow(req=req_patch())
result = dedent("""
PATCH /path?query=param HTTP/1.1\r
header: qvalue\r
@@ -112,31 +103,33 @@ class TestRawRequest():
class TestExportLocustCode():
def test_get(self):
- flow = tutils.tflow(req=req_get)
+ flow = tutils.tflow(req=req_get())
python_equals("test_flow_export/locust_get.py", flow_export.locust_code(flow))
def test_post(self):
- req_post.content = '''content'''
- req_post.headers = ''
- flow = tutils.tflow(req=req_post)
+ p = req_post()
+ print p
+ p.content = '''content'''
+ p.headers = ''
+ flow = tutils.tflow(req=p)
python_equals("test_flow_export/locust_post.py", flow_export.locust_code(flow))
def test_patch(self):
- flow = tutils.tflow(req=req_patch)
+ flow = tutils.tflow(req=req_patch())
python_equals("test_flow_export/locust_patch.py", flow_export.locust_code(flow))
class TestExportLocustTask():
def test_get(self):
- flow = tutils.tflow(req=req_get)
+ flow = tutils.tflow(req=req_get())
python_equals("test_flow_export/locust_task_get.py", flow_export.locust_task(flow))
def test_post(self):
- flow = tutils.tflow(req=req_post)
+ flow = tutils.tflow(req=req_post())
python_equals("test_flow_export/locust_task_post.py", flow_export.locust_task(flow))
def test_patch(self):
- flow = tutils.tflow(req=req_patch)
+ flow = tutils.tflow(req=req_patch())
python_equals("test_flow_export/locust_task_patch.py", flow_export.locust_task(flow))