diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-08-18 17:08:17 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-08-18 17:08:17 +1200 |
commit | 11c63dcb9f2e88f17704898efc16fb289d877196 (patch) | |
tree | b2f75d0714671a58676dcc6906537f03ff6f4658 /test | |
parent | 5c80450ce7036c9bb010ec8240493b041de79642 (diff) | |
download | mitmproxy-11c63dcb9f2e88f17704898efc16fb289d877196.tar.gz mitmproxy-11c63dcb9f2e88f17704898efc16fb289d877196.tar.bz2 mitmproxy-11c63dcb9f2e88f17704898efc16fb289d877196.zip |
Huge cleanup of content viewers.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_console_contentview.py | 102 |
1 files changed, 58 insertions, 44 deletions
diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py index 6f3958df..04f72a17 100644 --- a/test/test_console_contentview.py +++ b/test/test_console_contentview.py @@ -13,82 +13,91 @@ class TestContentView: def test_get_view_func(self): f = cv.get_view_func( - cv.VIEW_HEX, + cv.get("Hex"), flow.ODictCaseless(), "foo" ) - assert f is cv.view_hex + assert f.name == "Hex" f = cv.get_view_func( - cv.VIEW_AUTO, + cv.get("Auto"), flow.ODictCaseless(), "foo" ) - assert f is cv.view_raw + assert f.name == "Raw" f = cv.get_view_func( - cv.VIEW_AUTO, + cv.get("Auto"), flow.ODictCaseless( [["content-type", "text/html"]], ), "foo" ) - assert f is cv.view_html + assert f.name == "HTML" f = cv.get_view_func( - cv.VIEW_AUTO, + cv.get("Auto"), flow.ODictCaseless( [["content-type", "text/flibble"]], ), "foo" ) - assert f is cv.view_raw + assert f.name == "Raw" f = cv.get_view_func( - cv.VIEW_AUTO, + cv.get("Auto"), flow.ODictCaseless( [["content-type", "text/flibble"]], ), "<xml></xml>" ) - assert f is cv.view_xml + assert f.name == "XML" try: import pyamf f = cv.get_view_func( - cv.VIEW_AUTO, + cv.get("Auto"), flow.ODictCaseless( [["content-type", "application/x-amf"]], ), "" ) - assert f is cv.view_amf + assert f.name == "AMF" except ImportError: pass def test_view_urlencoded(self): d = utils.urlencode([("one", "two"), ("three", "four")]) - assert cv.view_urlencoded([], d, 100) - assert not cv.view_urlencoded([], "foo", 100) + v = cv.ViewURLEncoded() + assert v([], d, 100) + assert not v([], "foo", 100) def test_view_html(self): + v = cv.ViewHTML() s = "<html><br><br></br><p>one</p></html>" - assert cv.view_html([], s, 1000) + assert v([], s, 1000) s = "gobbledygook" - assert not cv.view_html([], s, 1000) + assert not v([], s, 1000) + + def test_view_html_outline(self): + v = cv.ViewHTMLOutline() + s = "<html><br><br></br><p>one</p></html>" + assert v([], s, 1000) def test_view_json(self): cv.VIEW_CUTOFF = 100 - assert cv.view_json([], "{}", 1000) - assert not cv.view_json([], "{", 1000) - assert cv.view_json([], "[" + ",".join(["0"]*cv.VIEW_CUTOFF) + "]", 1000) - assert cv.view_json([], "[1, 2, 3, 4, 5]", 5) + v = cv.ViewJSON() + assert v([], "{}", 1000) + assert not v([], "{", 1000) + assert v([], "[" + ",".join(["0"]*cv.VIEW_CUTOFF) + "]", 1000) + assert v([], "[1, 2, 3, 4, 5]", 5) def test_view_xml(self): - assert cv.view_xml([], "<foo></foo>", 1000) - assert not cv.view_xml([], "<foo>", 1000) + v = cv.ViewXML() + assert v([], "<foo></foo>", 1000) + assert not v([], "<foo>", 1000) s = """<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet title="XSL_formatting"?> <rss @@ -97,44 +106,49 @@ class TestContentView: version="2.0"> </rss> """ - assert cv.view_xml([], s, 1000) + assert v([], s, 1000) def test_view_raw(self): - assert cv.view_raw([], "foo", 1000) + v = cv.ViewRaw() + assert v([], "foo", 1000) def test_view_javascript(self): - assert cv.view_javascript([], "[1, 2, 3]", 100) - assert cv.view_javascript([], "[1, 2, 3", 100) - assert cv.view_javascript([], "function(a){[1, 2, 3]}", 100) + v = cv.ViewJavaScript() + assert v([], "[1, 2, 3]", 100) + assert v([], "[1, 2, 3", 100) + assert v([], "function(a){[1, 2, 3]}", 100) def test_view_hex(self): - assert cv.view_hex([], "foo", 1000) + v = cv.ViewHex() + assert v([], "foo", 1000) def test_view_image(self): + v = cv.ViewImage() p = tutils.test_data.path("data/image.png") - assert cv.view_image([], file(p).read(), sys.maxint) + assert v([], file(p).read(), sys.maxint) p = tutils.test_data.path("data/image.gif") - assert cv.view_image([], file(p).read(), sys.maxint) + assert v([], file(p).read(), sys.maxint) p = tutils.test_data.path("data/image-err1.jpg") - assert cv.view_image([], file(p).read(), sys.maxint) + assert v([], file(p).read(), sys.maxint) p = tutils.test_data.path("data/image.ico") - assert cv.view_image([], file(p).read(), sys.maxint) + assert v([], file(p).read(), sys.maxint) - assert not cv.view_image([], "flibble", sys.maxint) + assert not v([], "flibble", sys.maxint) def test_view_amf(self): try: import pyamf - + v = cv.ViewAMF() p = tutils.test_data.path("data/test.amf") - assert cv.view_amf([], file(p).read(), sys.maxint) + assert v([], file(p).read(), sys.maxint) except ImportError: pass def test_view_multipart(self): + view = cv.ViewMultipart() v = """ --AaB03x Content-Disposition: form-data; name="submit-name" @@ -145,24 +159,24 @@ Larry h = flow.ODictCaseless( [("Content-Type", "multipart/form-data; boundary=AaB03x")] ) - assert cv.view_multipart(h, v, 1000) + assert view(h, v, 1000) h = flow.ODictCaseless() - assert not cv.view_multipart(h, v, 1000) + assert not view(h, v, 1000) h = flow.ODictCaseless( [("Content-Type", "multipart/form-data")] ) - assert not cv.view_multipart(h, v, 1000) + assert not view(h, v, 1000) h = flow.ODictCaseless( [("Content-Type", "unparseable")] ) - assert not cv.view_multipart(h, v, 1000) + assert not view(h, v, 1000) def test_get_content_view(self): r = cv.get_content_view( - cv.VIEW_RAW, + cv.get("Raw"), [["content-type", "application/json"]], "[1, 2, 3]", 1000 @@ -170,7 +184,7 @@ Larry assert "Raw" in r[0] r = cv.get_content_view( - cv.VIEW_AUTO, + cv.get("Auto"), [["content-type", "application/json"]], "[1, 2, 3]", 1000 @@ -178,7 +192,7 @@ Larry assert r[0] == "JSON" r = cv.get_content_view( - cv.VIEW_AUTO, + cv.get("Auto"), [["content-type", "application/json"]], "[1, 2", 1000 @@ -186,7 +200,7 @@ Larry assert "Raw" in r[0] r = cv.get_content_view( - cv.VIEW_AUTO, + cv.get("Auto"), [ ["content-type", "application/json"], ["content-encoding", "gzip"] @@ -198,7 +212,7 @@ Larry assert "JSON" in r[0] r = cv.get_content_view( - cv.VIEW_XML, + cv.get("XML"), [ ["content-type", "application/json"], ["content-encoding", "gzip"] |