aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_flow_export.py
diff options
context:
space:
mode:
authorShadab Zafar <dufferzafar0@gmail.com>2016-02-09 21:58:29 +0530
committerShadab Zafar <dufferzafar0@gmail.com>2016-02-09 21:58:29 +0530
commit5f044d03b7c9d95be910f2eb643b6c8a9036d8de (patch)
tree412596beae76021d315d499b55efaa072ed49714 /test/test_flow_export.py
parent0576f579ed1e97f150b37c1511d0e7b9b43a329c (diff)
downloadmitmproxy-5f044d03b7c9d95be910f2eb643b6c8a9036d8de.tar.gz
mitmproxy-5f044d03b7c9d95be910f2eb643b6c8a9036d8de.tar.bz2
mitmproxy-5f044d03b7c9d95be910f2eb643b6c8a9036d8de.zip
Use classes to test a command, move code to separate methods under
classes
Diffstat (limited to 'test/test_flow_export.py')
-rw-r--r--test/test_flow_export.py240
1 files changed, 126 insertions, 114 deletions
diff --git a/test/test_flow_export.py b/test/test_flow_export.py
index cee21311..e5e9c0a3 100644
--- a/test/test_flow_export.py
+++ b/test/test_flow_export.py
@@ -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
-
- flow = tutils.tflow(req=req_post)
- result = """curl -X POST 'http://address/path' --data-binary 'content'"""
- 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_python_code():
- flow = tutils.tflow(req=req_get)
- result = dedent("""
- import requests
-
- url = 'http://address/path'
-
- headers = {
- 'header': 'qvalue',
- 'content-length': '7',
- }
-
- response = requests.request(
- method='GET',
- url=url,
- headers=headers,
- )
-
- print(response.text)
- """).strip()
- assert flow_export.python_code(flow) == result
-
- flow = tutils.tflow(req=req_post)
- result = dedent("""
- import requests
-
- url = 'http://address/path'
-
- data = '''content'''
-
- response = requests.request(
- method='POST',
- url=url,
- data=data,
- )
-
- print(response.text)
- """).strip()
- assert flow_export.python_code(flow) == result
-
- flow = tutils.tflow(req=req_patch)
- result = dedent("""
- 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,
- )
-
- 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
-
- 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
-
- 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
+class TestExportCurlCommand():
+
+ 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
+
+ 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
+
+
+class TestExportPythonCode():
+
+ def test_get(self):
+ flow = tutils.tflow(req=req_get)
+ result = dedent("""
+ import requests
+
+ url = 'http://address/path'
+
+ headers = {
+ 'header': 'qvalue',
+ 'content-length': '7',
+ }
+
+ response = requests.request(
+ method='GET',
+ url=url,
+ headers=headers,
+ )
+
+ print(response.text)
+ """).strip()
+ assert flow_export.python_code(flow) == result
+
+ def test_post(self):
+ flow = tutils.tflow(req=req_post)
+ result = dedent("""
+ import requests
+
+ url = 'http://address/path'
+
+ data = '''content'''
+
+ response = requests.request(
+ method='POST',
+ url=url,
+ data=data,
+ )
+
+ print(response.text)
+ """).strip()
+ assert flow_export.python_code(flow) == result
+
+ def test_patch(self):
+ flow = tutils.tflow(req=req_patch)
+ result = dedent("""
+ 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,
+ )
+
+ print(response.text)
+ """).strip()
+ assert flow_export.python_code(flow) == result
+
+
+def TestRawRequest():
+
+ 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
+
+ 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