diff options
| author | Maximilian Hils <git@maximilianhils.com> | 2015-08-11 10:57:32 +0200 |
|---|---|---|
| committer | Maximilian Hils <git@maximilianhils.com> | 2015-08-11 10:57:32 +0200 |
| commit | f3a611339148a5a3de141ff1234ec9018ab20896 (patch) | |
| tree | 5c53dc5d5eb8a06d1caaed84b04fd137cdbee6a1 /test/test_utils.py | |
| parent | c2832ef72bd4eed485a1c8d4bcb732da69896444 (diff) | |
| parent | 6a30ad2ad236fa20d086e271ff962ebc907da027 (diff) | |
| download | mitmproxy-f3a611339148a5a3de141ff1234ec9018ab20896.tar.gz mitmproxy-f3a611339148a5a3de141ff1234ec9018ab20896.tar.bz2 mitmproxy-f3a611339148a5a3de141ff1234ec9018ab20896.zip | |
Merge pull request #85 from Kriechi/http2-wip
add move tests and code from mitmproxy
Diffstat (limited to 'test/test_utils.py')
| -rw-r--r-- | test/test_utils.py | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/test/test_utils.py b/test/test_utils.py index 5e681eb6..fc7174d6 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1,5 +1,3 @@ -import urlparse - from netlib import utils, odict, tutils @@ -30,8 +28,6 @@ def test_pretty_size(): assert utils.pretty_size(1024 * 1024) == "1MB" - - def test_parse_url(): assert not utils.parse_url("") @@ -86,7 +82,6 @@ def test_urlencode(): assert utils.urlencode([('foo', 'bar')]) - def test_urldecode(): s = "one=two&three=four" assert len(utils.urldecode(s)) == 2 @@ -101,3 +96,31 @@ def test_get_header_tokens(): assert utils.get_header_tokens(h, "foo") == ["bar", "voing"] h["foo"] = ["bar, voing", "oink"] assert utils.get_header_tokens(h, "foo") == ["bar", "voing", "oink"] + + +def test_multipartdecode(): + boundary = 'somefancyboundary' + headers = odict.ODict( + [('content-type', ('multipart/form-data; boundary=%s' % 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) + + form = utils.multipartdecode(headers, content) + + assert len(form) == 2 + assert form[0] == ('field1', 'value1') + assert form[1] == ('field2', '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'}) |
