aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-12-10 11:36:32 +0100
committerMaximilian Hils <git@maximilianhils.com>2016-12-10 11:40:07 +0100
commit123ef043dc7214c9818985aeea565a82c2680c0e (patch)
tree28fe91eeeab3ba7e0a636618cf61511aeedbf527 /test
parent293b79af9120c3fc056db60492f88e21a5610ab6 (diff)
downloadmitmproxy-123ef043dc7214c9818985aeea565a82c2680c0e.tar.gz
mitmproxy-123ef043dc7214c9818985aeea565a82c2680c0e.tar.bz2
mitmproxy-123ef043dc7214c9818985aeea565a82c2680c0e.zip
add new xml/html pretty-printer :tada:
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/contentviews/test_html_outline.py2
-rw-r--r--test/mitmproxy/contentviews/test_xml_html.py29
-rw-r--r--test/mitmproxy/contentviews/test_xml_html_data/cdata-formatted.xml10
-rw-r--r--test/mitmproxy/contentviews/test_xml_html_data/cdata.xml10
-rw-r--r--test/mitmproxy/contentviews/test_xml_html_data/comment-formatted.xml10
-rw-r--r--test/mitmproxy/contentviews/test_xml_html_data/comment.xml10
-rw-r--r--test/mitmproxy/contentviews/test_xml_html_data/inline-formatted.html14
-rw-r--r--test/mitmproxy/contentviews/test_xml_html_data/inline.html7
-rw-r--r--test/mitmproxy/contentviews/test_xml_html_data/simple-formatted.html10
-rw-r--r--test/mitmproxy/contentviews/test_xml_html_data/simple.html1
10 files changed, 102 insertions, 1 deletions
diff --git a/test/mitmproxy/contentviews/test_html_outline.py b/test/mitmproxy/contentviews/test_html_outline.py
index d9ccc406..9e664e52 100644
--- a/test/mitmproxy/contentviews/test_html_outline.py
+++ b/test/mitmproxy/contentviews/test_html_outline.py
@@ -6,4 +6,4 @@ def test_view_html_outline():
v = full_eval(html_outline.ViewHTMLOutline())
s = b"<html><br><br></br><p>one</p></html>"
assert v(s)
- assert v(b'\xfe') \ No newline at end of file
+ assert v(b'\xfe')
diff --git a/test/mitmproxy/contentviews/test_xml_html.py b/test/mitmproxy/contentviews/test_xml_html.py
new file mode 100644
index 00000000..899ecfde
--- /dev/null
+++ b/test/mitmproxy/contentviews/test_xml_html.py
@@ -0,0 +1,29 @@
+import pytest
+
+from mitmproxy.contentviews import xml_html
+from mitmproxy.test import tutils
+from . import full_eval
+
+data = tutils.test_data.push("mitmproxy/contentviews/test_xml_html_data/")
+
+
+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>')]])
+
+
+@pytest.mark.parametrize("filename", [
+ "simple.html",
+ "cdata.xml",
+ "comment.xml",
+ "inline.html",
+])
+def test_format_xml(filename):
+ path = data.path(filename)
+ with open(path) as f:
+ input = f.read()
+ with open(path.replace(".", "-formatted.")) as f:
+ expected = f.read()
+ tokens = xml_html.tokenize(input)
+ assert xml_html.format_xml(tokens) == expected
diff --git a/test/mitmproxy/contentviews/test_xml_html_data/cdata-formatted.xml b/test/mitmproxy/contentviews/test_xml_html_data/cdata-formatted.xml
new file mode 100644
index 00000000..44a81a83
--- /dev/null
+++ b/test/mitmproxy/contentviews/test_xml_html_data/cdata-formatted.xml
@@ -0,0 +1,10 @@
+<exampleOfACDATA>
+ <![CDATA[
+ Since this is a CDATA section
+ I can use all sorts of reserved characters
+ like > < " and &
+ or write things like
+ <foo></bar>
+ but my document is still well formed!
+ ]]>
+</exampleOfACDATA>
diff --git a/test/mitmproxy/contentviews/test_xml_html_data/cdata.xml b/test/mitmproxy/contentviews/test_xml_html_data/cdata.xml
new file mode 100644
index 00000000..b4c5dfca
--- /dev/null
+++ b/test/mitmproxy/contentviews/test_xml_html_data/cdata.xml
@@ -0,0 +1,10 @@
+<exampleOfACDATA>
+<![CDATA[
+ Since this is a CDATA section
+ I can use all sorts of reserved characters
+ like > < " and &
+or write things like
+ <foo></bar>
+ but my document is still well formed!
+]]>
+</exampleOfACDATA> \ No newline at end of file
diff --git a/test/mitmproxy/contentviews/test_xml_html_data/comment-formatted.xml b/test/mitmproxy/contentviews/test_xml_html_data/comment-formatted.xml
new file mode 100644
index 00000000..d0da6665
--- /dev/null
+++ b/test/mitmproxy/contentviews/test_xml_html_data/comment-formatted.xml
@@ -0,0 +1,10 @@
+<exampleOfAComment>
+ <!--
+ Since this is a comment
+ I can use all sorts of reserved characters
+ like > < " and &
+ or write things like
+ <foo></bar>
+ but my document is still well formed!
+ -->
+</exampleOfAComment>
diff --git a/test/mitmproxy/contentviews/test_xml_html_data/comment.xml b/test/mitmproxy/contentviews/test_xml_html_data/comment.xml
new file mode 100644
index 00000000..3f54ddba
--- /dev/null
+++ b/test/mitmproxy/contentviews/test_xml_html_data/comment.xml
@@ -0,0 +1,10 @@
+<exampleOfAComment>
+<!--
+ Since this is a comment
+ I can use all sorts of reserved characters
+ like > < " and &
+ or write things like
+ <foo></bar>
+ but my document is still well formed!
+-->
+</exampleOfAComment> \ No newline at end of file
diff --git a/test/mitmproxy/contentviews/test_xml_html_data/inline-formatted.html b/test/mitmproxy/contentviews/test_xml_html_data/inline-formatted.html
new file mode 100644
index 00000000..5253bf4f
--- /dev/null
+++ b/test/mitmproxy/contentviews/test_xml_html_data/inline-formatted.html
@@ -0,0 +1,14 @@
+<html>
+<head>
+ <title>Test Page</title>
+</head>
+<body>
+ <p>
+ <i class="fa fa-alert"></i>
+ Some things should be
+ <b>inline</b>
+ , some things shouldn't!
+ </p>
+ <i class="fa fa-warning"/>
+</body>
+</html>
diff --git a/test/mitmproxy/contentviews/test_xml_html_data/inline.html b/test/mitmproxy/contentviews/test_xml_html_data/inline.html
new file mode 100644
index 00000000..3e4b16b9
--- /dev/null
+++ b/test/mitmproxy/contentviews/test_xml_html_data/inline.html
@@ -0,0 +1,7 @@
+<html>
+<head><title>Test Page</title></head>
+<body>
+ <p><i class="fa fa-alert"></i>Some things should be <b>inline</b>, some things shouldn't!</p>
+ <i class="fa fa-warning"/>
+</body>
+</html> \ No newline at end of file
diff --git a/test/mitmproxy/contentviews/test_xml_html_data/simple-formatted.html b/test/mitmproxy/contentviews/test_xml_html_data/simple-formatted.html
new file mode 100644
index 00000000..23438428
--- /dev/null
+++ b/test/mitmproxy/contentviews/test_xml_html_data/simple-formatted.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>title</title>
+</head>
+<body>
+ <h1>Hello World</h1>
+ <!-- page content -->
+</body>
+</html>
diff --git a/test/mitmproxy/contentviews/test_xml_html_data/simple.html b/test/mitmproxy/contentviews/test_xml_html_data/simple.html
new file mode 100644
index 00000000..73e81a5e
--- /dev/null
+++ b/test/mitmproxy/contentviews/test_xml_html_data/simple.html
@@ -0,0 +1 @@
+<!DOCTYPE html><html lang="en"><head><title>title</title></head><body><h1>Hello World</h1><!-- page content --></body></html>