aboutsummaryrefslogtreecommitdiffstats
path: root/test/netlib
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-05-31 19:07:55 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-05-31 19:07:55 +1200
commitec34cae6181d6af0150ac730d70b96104a07e9d5 (patch)
tree875987f36e83f92ce9a38cd6e22326a948f29609 /test/netlib
parent15b2374ef9d6a8cbafdff7c79694921387836ff3 (diff)
downloadmitmproxy-ec34cae6181d6af0150ac730d70b96104a07e9d5.tar.gz
mitmproxy-ec34cae6181d6af0150ac730d70b96104a07e9d5.tar.bz2
mitmproxy-ec34cae6181d6af0150ac730d70b96104a07e9d5.zip
utils.multipartdecode -> http.multipart.decode
also utils.parse_content_type -> http.headers.parse_content_type
Diffstat (limited to 'test/netlib')
-rw-r--r--test/netlib/http/test_headers.py10
-rw-r--r--test/netlib/http/test_multipart.py23
-rw-r--r--test/netlib/test_utils.py32
3 files changed, 33 insertions, 32 deletions
diff --git a/test/netlib/http/test_headers.py b/test/netlib/http/test_headers.py
index cd2ca9d1..e12bceaf 100644
--- a/test/netlib/http/test_headers.py
+++ b/test/netlib/http/test_headers.py
@@ -1,4 +1,5 @@
from netlib.http import Headers
+from netlib.http.headers import parse_content_type
from netlib.tutils import raises
@@ -72,3 +73,12 @@ class TestHeaders(object):
replacements = headers.replace(r"Host: ", "X-Host ")
assert replacements == 0
assert headers["Host"] == "example.com"
+
+
+def test_parse_content_type():
+ p = parse_content_type
+ assert p("text/html") == ("text", "html", {})
+ assert p("text") is None
+
+ v = p("text/html; charset=UTF-8")
+ assert v == ('text', 'html', {'charset': 'UTF-8'})
diff --git a/test/netlib/http/test_multipart.py b/test/netlib/http/test_multipart.py
new file mode 100644
index 00000000..45ae996b
--- /dev/null
+++ b/test/netlib/http/test_multipart.py
@@ -0,0 +1,23 @@
+from netlib.http import Headers
+from netlib.http import multipart
+
+def test_decode():
+ boundary = 'somefancyboundary'
+ headers = Headers(
+ content_type='multipart/form-data; boundary=' + boundary
+ )
+ content = (
+ "--{0}\n"
+ "Content-Disposition: form-data; name=\"field1\"\n\n"
+ "value1\n"
+ "--{0}\n"
+ "Content-Disposition: form-data; name=\"field2\"\n\n"
+ "value2\n"
+ "--{0}--".format(boundary).encode()
+ )
+
+ form = multipart.decode(headers, content)
+
+ assert len(form) == 2
+ assert form[0] == (b"field1", b"value1")
+ assert form[1] == (b"field2", b"value2")
diff --git a/test/netlib/test_utils.py b/test/netlib/test_utils.py
index c4ee3c10..b3cc9a0b 100644
--- a/test/netlib/test_utils.py
+++ b/test/netlib/test_utils.py
@@ -1,7 +1,6 @@
# coding=utf-8
from netlib import utils, tutils
-from netlib.http import Headers
def test_bidi():
@@ -38,37 +37,6 @@ def test_pretty_size():
assert utils.pretty_size(1024 * 1024) == "1MB"
-def test_multipartdecode():
- boundary = 'somefancyboundary'
- headers = Headers(
- content_type='multipart/form-data; boundary=' + boundary
- )
- content = (
- "--{0}\n"
- "Content-Disposition: form-data; name=\"field1\"\n\n"
- "value1\n"
- "--{0}\n"
- "Content-Disposition: form-data; name=\"field2\"\n\n"
- "value2\n"
- "--{0}--".format(boundary).encode()
- )
-
- form = utils.multipartdecode(headers, content)
-
- assert len(form) == 2
- assert form[0] == (b"field1", b"value1")
- assert form[1] == (b"field2", b"value2")
-
-
-def test_parse_content_type():
- p = utils.parse_content_type
- assert p("text/html") == ("text", "html", {})
- assert p("text") is None
-
- v = p("text/html; charset=UTF-8")
- assert v == ('text', 'html', {'charset': 'UTF-8'})
-
-
def test_safe_subn():
assert utils.safe_subn("foo", u"bar", "\xc2foo")