aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Kriechbaumer <Kriechi@users.noreply.github.com>2017-05-17 15:12:36 +0800
committerGitHub <noreply@github.com>2017-05-17 15:12:36 +0800
commitfeff5bd138a9cb4e72760f6aea8bccf0ad4b81d2 (patch)
tree3a821ba03f3e8bb173944bae6316695f8088ef97
parentca46b1e340750859881347ead92a64ed05105d25 (diff)
parent208931021e28de8b57e3f28d0fbcb018b5fb3879 (diff)
downloadmitmproxy-feff5bd138a9cb4e72760f6aea8bccf0ad4b81d2.tar.gz
mitmproxy-feff5bd138a9cb4e72760f6aea8bccf0ad4b81d2.tar.bz2
mitmproxy-feff5bd138a9cb4e72760f6aea8bccf0ad4b81d2.zip
Merge pull request #2338 from ujjwal96/test-cov
Increased test coverage
-rw-r--r--setup.cfg4
-rw-r--r--test/mitmproxy/contentviews/test_api.py15
-rw-r--r--test/mitmproxy/contentviews/test_xml_html.py8
-rw-r--r--test/mitmproxy/contentviews/test_xml_html_data/test-formatted.html44
-rw-r--r--test/mitmproxy/contentviews/test_xml_html_data/test.html14
-rw-r--r--test/mitmproxy/test_controller.py2
6 files changed, 79 insertions, 8 deletions
diff --git a/setup.cfg b/setup.cfg
index ebe76efd..f1382a6e 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -21,9 +21,7 @@ exclude_lines =
[tool:full_coverage]
exclude =
- mitmproxy/contentviews/__init__.py
mitmproxy/contentviews/wbxml.py
- mitmproxy/contentviews/xml_html.py
mitmproxy/net/tcp.py
mitmproxy/net/http/encoding.py
mitmproxy/proxy/protocol/
@@ -31,7 +29,6 @@ exclude =
mitmproxy/proxy/root_context.py
mitmproxy/proxy/server.py
mitmproxy/tools/
- mitmproxy/controller.py
mitmproxy/flow.py
mitmproxy/master.py
pathod/pathoc.py
@@ -45,7 +42,6 @@ exclude =
mitmproxy/addons/termlog.py
mitmproxy/contentviews/base.py
mitmproxy/contentviews/wbxml.py
- mitmproxy/contentviews/xml_html.py
mitmproxy/controller.py
mitmproxy/ctx.py
mitmproxy/exceptions.py
diff --git a/test/mitmproxy/contentviews/test_api.py b/test/mitmproxy/contentviews/test_api.py
index 95d83af9..c072c86f 100644
--- a/test/mitmproxy/contentviews/test_api.py
+++ b/test/mitmproxy/contentviews/test_api.py
@@ -9,23 +9,28 @@ from mitmproxy.test import tutils
class TestContentView(contentviews.View):
name = "test"
- prompt = ("t", "test")
+ prompt = ("test", "t")
content_types = ["test/123"]
def test_add_remove():
tcv = TestContentView()
contentviews.add(tcv)
+ assert tcv in contentviews.views
# repeated addition causes exception
- with pytest.raises(ContentViewException):
+ with pytest.raises(ContentViewException, match="Duplicate view"):
contentviews.add(tcv)
+ tcv2 = TestContentView()
+ tcv2.name = "test2"
+ tcv2.prompt = ("test2", "t")
# Same shortcut doesn't work either.
- with pytest.raises(ContentViewException):
- contentviews.add(TestContentView())
+ with pytest.raises(ContentViewException, match="Duplicate view shortcut"):
+ contentviews.add(tcv2)
contentviews.remove(tcv)
+ assert tcv not in contentviews.views
def test_get_content_view():
@@ -43,6 +48,7 @@ def test_get_content_view():
headers=Headers(content_type="application/json")
)
assert desc == "JSON"
+ assert list(lines)
desc, lines, err = contentviews.get_content_view(
contentviews.get("JSON"),
@@ -84,3 +90,4 @@ def test_get_message_content_view():
def test_get_by_shortcut():
assert contentviews.get_by_shortcut("s")
+ assert not contentviews.get_by_shortcut("b")
diff --git a/test/mitmproxy/contentviews/test_xml_html.py b/test/mitmproxy/contentviews/test_xml_html.py
index 2b0aee4d..8148fd4c 100644
--- a/test/mitmproxy/contentviews/test_xml_html.py
+++ b/test/mitmproxy/contentviews/test_xml_html.py
@@ -11,6 +11,13 @@ def test_simple():
v = full_eval(xml_html.ViewXmlHtml())
assert v(b"foo") == ('XML', [[('text', 'foo')]])
assert v(b"<html></html>") == ('HTML', [[('text', '<html></html>')]])
+ assert v(b"<>") == ('XML', [[('text', '<>')]])
+ assert v(b"<p") == ('XML', [[('text', '<p')]])
+
+ with open(data.path("simple.html")) as f:
+ input = f.read()
+ tokens = xml_html.tokenize(input)
+ assert str(next(tokens)) == "Tag(<!DOCTYPE html>)"
@pytest.mark.parametrize("filename", [
@@ -18,6 +25,7 @@ def test_simple():
"cdata.xml",
"comment.xml",
"inline.html",
+ "test.html"
])
def test_format_xml(filename):
path = data.path(filename)
diff --git a/test/mitmproxy/contentviews/test_xml_html_data/test-formatted.html b/test/mitmproxy/contentviews/test_xml_html_data/test-formatted.html
new file mode 100644
index 00000000..0eb60004
--- /dev/null
+++ b/test/mitmproxy/contentviews/test_xml_html_data/test-formatted.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Title</title>
+</head>
+<body>
+ <p>
+ Lorem ipsum dolor
+ <p>
+ sit amet, consectetur
+ <p>
+ adipiscing elit, sed
+ <p>
+ do eiusmod tempor
+ <p>
+ incididunt ut
+ <p>
+ labore et dolore
+ <p>
+ magna aliqua.
+ <p>
+ Ut enim ad minim
+ <p>
+ veniam, quis nostrud
+ <p>
+ exercitation
+ <p>
+ ullamco laboris
+ <p>
+ nisi ut aliquip ex ea
+ <p>
+ commodo consequat.
+ <p>
+ Duis aute irure
+ <p>
+ dolor in reprehenderit
+ <p>
+ in voluptate velit
+ <p>
+ esse cillum dolore
+ <p>eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
+</body>
+</html>
diff --git a/test/mitmproxy/contentviews/test_xml_html_data/test.html b/test/mitmproxy/contentviews/test_xml_html_data/test.html
new file mode 100644
index 00000000..e74ac314
--- /dev/null
+++ b/test/mitmproxy/contentviews/test_xml_html_data/test.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Title</title>
+</head>
+<body>
+<p>Lorem ipsum dolor<p>sit amet, consectetur <p>adipiscing elit, sed<p>do eiusmod tempor<p> incididunt ut<p> labore et dolore<p> magna aliqua.
+ <p>Ut enim ad minim <p>veniam, quis nostrud <p>exercitation <p>ullamco laboris <p>
+ nisi ut aliquip ex ea <p>commodo consequat.<p>Duis aute irure <p>dolor in reprehenderit <p>in voluptate velit<p> esse cillum dolore <p>eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
+
+
+</body>
+</html> \ No newline at end of file
diff --git a/test/mitmproxy/test_controller.py b/test/mitmproxy/test_controller.py
index ccc8bf35..2e13d298 100644
--- a/test/mitmproxy/test_controller.py
+++ b/test/mitmproxy/test_controller.py
@@ -176,6 +176,8 @@ class TestDummyReply:
reply = controller.DummyReply()
reply.ack()
reply.take()
+ with pytest.raises(ControlException):
+ reply.mark_reset()
reply.commit()
reply.mark_reset()
assert reply.state == "committed"