Added tests

This commit is contained in:
Krzysztof Bielicki 2015-03-16 10:23:50 +01:00
parent 244ef243d7
commit 953f9aa641
No known key found for this signature in database
GPG Key ID: DBD93BED87876271
2 changed files with 39 additions and 1 deletions

View File

@ -1,3 +1,4 @@
from mock import MagicMock
from libmproxy.protocol.http import *
from cStringIO import StringIO
import tutils, tservers
@ -112,6 +113,26 @@ class TestHTTPRequest:
r = tutils.treq()
assert repr(r)
def test_get_form_for_urlencoded(self):
r = tutils.treq()
r.headers.add("content-type", "application/x-www-form-urlencoded")
r.get_form_urlencoded = MagicMock()
r.get_form()
assert r.get_form_urlencoded.called
def test_get_form_for_multipart(self):
r = tutils.treq()
r.headers.add("content-type", "multipart/form-data")
r.get_form_multipart = MagicMock()
r.get_form()
assert r.get_form_multipart.called
class TestHTTPResponse:
def test_read_from_stringio(self):

View File

@ -1,5 +1,5 @@
import json
from libmproxy import utils
from libmproxy import utils, flow
import tutils
utils.CERT_SLEEP_TIME = 0
@ -52,6 +52,23 @@ def test_urldecode():
s = "one=two&three=four"
assert len(utils.urldecode(s)) == 2
def test_multipartdecode():
boundary = 'somefancyboundary'
headers = flow.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_pretty_duration():
assert utils.pretty_duration(0.00001) == "0ms"
assert utils.pretty_duration(0.0001) == "0ms"