diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-10-24 19:19:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-24 19:19:58 -0700 |
commit | ef4e9b2b855337b61a18ecdfbeaad3bb6a011af4 (patch) | |
tree | 0726a559e3212f6947df9566982e0fba7930f6c2 /test | |
parent | ee8c7b31ab0eb468437deb639e3acaef4ec8b638 (diff) | |
parent | e87daa70f3c1e5fd63484cd240b56cd27a67c0e6 (diff) | |
download | mitmproxy-ef4e9b2b855337b61a18ecdfbeaad3bb6a011af4.tar.gz mitmproxy-ef4e9b2b855337b61a18ecdfbeaad3bb6a011af4.tar.bz2 mitmproxy-ef4e9b2b855337b61a18ecdfbeaad3bb6a011af4.zip |
Merge pull request #1656 from mhils/improve-export-2
Improve Flow Export
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/data/test_flow_export/python_get.py | 23 | ||||
-rw-r--r-- | test/mitmproxy/data/test_flow_export/python_patch.py | 26 | ||||
-rw-r--r-- | test/mitmproxy/data/test_flow_export/python_post.py | 11 | ||||
-rw-r--r-- | test/mitmproxy/data/test_flow_export/python_post_json.py | 24 | ||||
-rw-r--r-- | test/mitmproxy/test_flow_export.py | 25 |
5 files changed, 22 insertions, 87 deletions
diff --git a/test/mitmproxy/data/test_flow_export/python_get.py b/test/mitmproxy/data/test_flow_export/python_get.py index af8f7c81..e9ed072a 100644 --- a/test/mitmproxy/data/test_flow_export/python_get.py +++ b/test/mitmproxy/data/test_flow_export/python_get.py @@ -1,22 +1,9 @@ import requests -url = 'http://address/path' - -headers = { - 'header': 'qvalue', - 'content-length': '7', -} - -params = { - 'a': ['foo', 'bar'], - 'b': 'baz', -} - -response = requests.request( - method='GET', - url=url, - headers=headers, - params=params, +response = requests.get( + 'http://address:22/path', + params=[('a', 'foo'), ('a', 'bar'), ('b', 'baz')], + headers={'header': 'qvalue'} ) -print(response.text) +print(response.text)
\ No newline at end of file diff --git a/test/mitmproxy/data/test_flow_export/python_patch.py b/test/mitmproxy/data/test_flow_export/python_patch.py index 159e802f..d83a57b9 100644 --- a/test/mitmproxy/data/test_flow_export/python_patch.py +++ b/test/mitmproxy/data/test_flow_export/python_patch.py @@ -1,24 +1,10 @@ import requests -url = 'http://address/path' - -headers = { - 'header': 'qvalue', - 'content-length': '7', -} - -params = { - 'query': 'param', -} - -data = '''content''' - -response = requests.request( - method='PATCH', - url=url, - headers=headers, - params=params, - data=data, +response = requests.patch( + 'http://address:22/path', + params=[('query', 'param')], + headers={'header': 'qvalue'}, + data=b'content' ) -print(response.text) +print(response.text)
\ No newline at end of file diff --git a/test/mitmproxy/data/test_flow_export/python_post.py b/test/mitmproxy/data/test_flow_export/python_post.py index b13f6441..6254adfb 100644 --- a/test/mitmproxy/data/test_flow_export/python_post.py +++ b/test/mitmproxy/data/test_flow_export/python_post.py @@ -1,13 +1,8 @@ import requests -url = 'http://address/path' - -data = '''content''' - -response = requests.request( - method='POST', - url=url, - data=data, +response = requests.post( + 'http://address:22/path', + data=b'content' ) print(response.text) diff --git a/test/mitmproxy/data/test_flow_export/python_post_json.py b/test/mitmproxy/data/test_flow_export/python_post_json.py index 5ef110f3..d6ae6357 100644 --- a/test/mitmproxy/data/test_flow_export/python_post_json.py +++ b/test/mitmproxy/data/test_flow_export/python_post_json.py @@ -1,23 +1,9 @@ import requests -url = 'http://address/path' - -headers = { - 'content-type': 'application/json', -} - - -json = { - 'email': 'example@example.com', - 'name': 'example', -} - - -response = requests.request( - method='POST', - url=url, - headers=headers, - json=json, +response = requests.post( + 'http://address:22/path', + headers={'content-type': 'application/json'}, + json={'email': 'example@example.com', 'name': 'example'} ) -print(response.text) +print(response.text)
\ No newline at end of file diff --git a/test/mitmproxy/test_flow_export.py b/test/mitmproxy/test_flow_export.py index df0ccb77..86234616 100644 --- a/test/mitmproxy/test_flow_export.py +++ b/test/mitmproxy/test_flow_export.py @@ -34,17 +34,17 @@ def req_patch(): class TestExportCurlCommand: def test_get(self): flow = tutils.tflow(req=req_get()) - result = """curl -H 'header:qvalue' -H 'content-length:7' 'http://address/path?a=foo&a=bar&b=baz'""" + result = """curl -H 'header:qvalue' -H 'content-length:7' 'http://address:22/path?a=foo&a=bar&b=baz'""" assert 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'""" + result = """curl -X POST 'http://address:22/path' --data-binary 'content'""" assert 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'""" + result = """curl -H 'header:qvalue' -H 'content-length:7' -X PATCH 'http://address:22/path?query=param' --data-binary 'content'""" assert export.curl_command(flow) == result @@ -100,25 +100,6 @@ class TestExportLocustTask: python_equals("data/test_flow_export/locust_task_patch.py", export.locust_task(flow)) -class TestIsJson: - def test_empty(self): - assert export.is_json(None, None) is False - - def test_json_type(self): - headers = Headers(content_type="application/json") - assert export.is_json(headers, b"foobar") is False - - def test_valid(self): - headers = Headers(content_type="application/foobar") - j = export.is_json(headers, b'{"name": "example", "email": "example@example.com"}') - assert j is False - - def test_valid2(self): - headers = Headers(content_type="application/json") - j = export.is_json(headers, b'{"name": "example", "email": "example@example.com"}') - assert isinstance(j, dict) - - class TestURL: def test_url(self): flow = tutils.tflow() |