aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-10-22 20:32:39 -0700
committerMaximilian Hils <git@maximilianhils.com>2016-10-22 20:32:39 -0700
commite87daa70f3c1e5fd63484cd240b56cd27a67c0e6 (patch)
treea1ac84d1145efb6e7d34bfcd2eaa9aed76e6e6e4 /test
parentc09cedd0f850a863665c67ecc0a6166488a0f8cb (diff)
downloadmitmproxy-e87daa70f3c1e5fd63484cd240b56cd27a67c0e6.tar.gz
mitmproxy-e87daa70f3c1e5fd63484cd240b56cd27a67c0e6.tar.bz2
mitmproxy-e87daa70f3c1e5fd63484cd240b56cd27a67c0e6.zip
improve flow export
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/data/test_flow_export/python_get.py23
-rw-r--r--test/mitmproxy/data/test_flow_export/python_patch.py26
-rw-r--r--test/mitmproxy/data/test_flow_export/python_post.py11
-rw-r--r--test/mitmproxy/data/test_flow_export/python_post_json.py24
-rw-r--r--test/mitmproxy/test_flow_export.py25
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()