From 7bde38dc4a8041e60daeddfea4c581fb90f0e192 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sun, 19 Jun 2016 12:00:37 +0200 Subject: py3++ --- test/mitmproxy/mastertest.py | 5 +++-- test/mitmproxy/test_contentview.py | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/mastertest.py b/test/mitmproxy/mastertest.py index 4d04f337..9e726a32 100644 --- a/test/mitmproxy/mastertest.py +++ b/test/mitmproxy/mastertest.py @@ -1,7 +1,8 @@ -import tutils -import netlib.tutils import mock +from . import tutils +import netlib.tutils + from mitmproxy import flow, proxy, models diff --git a/test/mitmproxy/test_contentview.py b/test/mitmproxy/test_contentview.py index 667a36fe..48825bc2 100644 --- a/test/mitmproxy/test_contentview.py +++ b/test/mitmproxy/test_contentview.py @@ -138,16 +138,16 @@ class TestContentView: def test_view_image(self): v = cv.ViewImage() p = tutils.test_data.path("data/image.png") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) p = tutils.test_data.path("data/image.gif") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) p = tutils.test_data.path("data/image-err1.jpg") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) p = tutils.test_data.path("data/image.ico") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) assert not v("flibble") @@ -252,22 +252,22 @@ if pyamf: v = cv.ViewAMF() p = tutils.test_data.path("data/amf01") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) p = tutils.test_data.path("data/amf02") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) def test_view_amf_response(): v = cv.ViewAMF() p = tutils.test_data.path("data/amf03") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) if cv.ViewProtobuf.is_available(): def test_view_protobuf_request(): v = cv.ViewProtobuf() p = tutils.test_data.path("data/protobuf01") - content_type, output = v(file(p, "rb").read()) + content_type, output = v(open(p, "rb").read()) assert content_type == "Protobuf" assert output.next()[0][1] == '1: "3bbc333c-e61c-433b-819a-0b9a8cc103b8"' -- cgit v1.2.3 From ba13fda10d3065a0c8dfd95d55680675b3bf08c2 Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Mon, 20 Jun 2016 00:50:41 +0530 Subject: Add tests for PathEdit --- test/mitmproxy/console/test_pathedit.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/mitmproxy/console/test_pathedit.py b/test/mitmproxy/console/test_pathedit.py index 107a48ac..ff6ef846 100644 --- a/test/mitmproxy/console/test_pathedit.py +++ b/test/mitmproxy/console/test_pathedit.py @@ -2,6 +2,8 @@ import os from os.path import normpath from mitmproxy.console import pathedit +from mock import patch + from .. import tutils @@ -47,3 +49,25 @@ class TestPathCompleter: s = "thisisatotallynonexistantpathforsure" assert c.complete(s) == s assert c.final == s + + +class TestPathEdit(): + + def test_keypress(self): + + pe = pathedit.PathEdit() + + with patch('urwid.widget.Edit.get_edit_text') as get_text, \ + patch('urwid.widget.Edit.set_edit_text') as set_text: + + cd = tutils.test_data.path("completion") + get_text.return_value = os.path.join(cd, "a") + + # Pressing tab should set completed path + pe.keypress((1,), "tab") + set_text_called_with = set_text.call_args[0][0] + assert set_text_called_with.endswith(normpath("/completion/aaa")) + + # Pressing any other key should reset + pe.keypress((1,), "a") + assert pe.lookup is None -- cgit v1.2.3 From 6aeba9777a105da85cf5d8c69defc521aff67212 Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Mon, 20 Jun 2016 01:24:27 +0530 Subject: Add dummy directory to completion --- test/mitmproxy/completion/bbb/Readme.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test/mitmproxy/completion/bbb/Readme.md (limited to 'test') diff --git a/test/mitmproxy/completion/bbb/Readme.md b/test/mitmproxy/completion/bbb/Readme.md new file mode 100644 index 00000000..ac534722 --- /dev/null +++ b/test/mitmproxy/completion/bbb/Readme.md @@ -0,0 +1,2 @@ + +This empty directory has been added so that we can hit [this line](https://codecov.io/gh/mitmproxy/mitmproxy/src/ba13fda10d3065a0c8dfd95d55680675b3bf08c2/mitmproxy/console/pathedit.py#L43) while testing pathedit completion. -- cgit v1.2.3 From efeade134ae0f750e146920409d998c09e855093 Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Tue, 21 Jun 2016 00:22:00 +0530 Subject: py3++ --- test/mitmproxy/test_contentview.py | 54 +++++++++++++++---------------- test/mitmproxy/test_custom_contentview.py | 2 +- 2 files changed, 28 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/test_contentview.py b/test/mitmproxy/test_contentview.py index 48825bc2..52fceeac 100644 --- a/test/mitmproxy/test_contentview.py +++ b/test/mitmproxy/test_contentview.py @@ -23,37 +23,37 @@ class TestContentView: def test_view_auto(self): v = cv.ViewAuto() f = v( - "foo", + b"foo", headers=Headers() ) assert f[0] == "Raw" f = v( - "", + b"", headers=Headers(content_type="text/html") ) assert f[0] == "HTML" f = v( - "foo", + b"foo", headers=Headers(content_type="text/flibble") ) assert f[0] == "Raw" f = v( - "", + b"", headers=Headers(content_type="text/flibble") ) assert f[0].startswith("XML") f = v( - "", + b"", headers=Headers() ) assert f[0] == "No content" f = v( - "", + b"", headers=Headers(), query=multidict.MultiDict([("foo", "bar")]), ) @@ -69,29 +69,29 @@ class TestContentView: def test_view_html(self): v = cv.ViewHTML() - s = "


one

" + s = b"


one

" assert v(s) - s = "gobbledygook" + s = b"gobbledygook" assert not v(s) def test_view_html_outline(self): v = cv.ViewHTMLOutline() - s = "


one

" + s = b"


one

" assert v(s) def test_view_json(self): cv.VIEW_CUTOFF = 100 v = cv.ViewJSON() - assert v("{}") - assert not v("{") - assert v("[1, 2, 3, 4, 5]") + assert v(b"{}") + assert not v(b"{") + assert v(b"[1, 2, 3, 4, 5]") def test_view_xml(self): v = cv.ViewXML() - assert v("") - assert not v("") - s = """ + assert v(b"") + assert not v(b"") + s = b""" Date: Tue, 21 Jun 2016 01:08:14 +0530 Subject: py3++ --- test/mitmproxy/test_cmdline.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/test_cmdline.py b/test/mitmproxy/test_cmdline.py index e75b7baf..4fe2cf94 100644 --- a/test/mitmproxy/test_cmdline.py +++ b/test/mitmproxy/test_cmdline.py @@ -39,11 +39,11 @@ def test_parse_replace_hook(): def test_parse_server_spec(): tutils.raises("Invalid server specification", cmdline.parse_server_spec, "") assert cmdline.parse_server_spec( - "http://foo.com:88") == ("http", ("foo.com", 88)) + "http://foo.com:88") == (b"http", (b"foo.com", 88)) assert cmdline.parse_server_spec( - "http://foo.com") == ("http", ("foo.com", 80)) + "http://foo.com") == (b"http", (b"foo.com", 80)) assert cmdline.parse_server_spec( - "https://foo.com") == ("https", ("foo.com", 443)) + "https://foo.com") == (b"https", (b"foo.com", 443)) tutils.raises( "Invalid server specification", cmdline.parse_server_spec, @@ -59,9 +59,9 @@ def test_parse_upstream_auth(): tutils.raises("Invalid upstream auth specification", cmdline.parse_upstream_auth, ":") tutils.raises("Invalid upstream auth specification", cmdline.parse_upstream_auth, ":test") assert cmdline.parse_upstream_auth( - "test:test") == "Basic" + " " + base64.b64encode("test:test") + "test:test") == b"Basic" + b" " + base64.b64encode(b"test:test") assert cmdline.parse_upstream_auth( - "test:") == "Basic" + " " + base64.b64encode("test:") + "test:") == b"Basic" + b" " + base64.b64encode(b"test:") def test_parse_setheaders(): @@ -124,7 +124,7 @@ def test_common(): opts.replace_file = [("/foo/bar/%s" % p)] v = cmdline.get_common_options(opts)["replacements"] assert len(v) == 1 - assert v[0][2].strip() == "replacecontents" + assert v[0][2].strip() == b"replacecontents" def test_mitmproxy(): -- cgit v1.2.3