aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_language_http2.py
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2015-06-08 15:28:24 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2015-06-15 15:50:44 +0200
commit0bc8fa1d0d4f2730311b9fc934a8fcdaae07ab66 (patch)
treed02b896553a04043c6b66f18412acf99d02ce1e6 /test/test_language_http2.py
parentb7c8021407965cd97bcc8051ddb0692145401cbf (diff)
downloadmitmproxy-0bc8fa1d0d4f2730311b9fc934a8fcdaae07ab66.tar.gz
mitmproxy-0bc8fa1d0d4f2730311b9fc934a8fcdaae07ab66.tar.bz2
mitmproxy-0bc8fa1d0d4f2730311b9fc934a8fcdaae07ab66.zip
http2: add pathoc and language tests
Diffstat (limited to 'test/test_language_http2.py')
-rw-r--r--test/test_language_http2.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/test_language_http2.py b/test/test_language_http2.py
new file mode 100644
index 00000000..de3e5cf9
--- /dev/null
+++ b/test/test_language_http2.py
@@ -0,0 +1,75 @@
+import cStringIO
+
+from libpathod import language
+from libpathod.language import http2, base
+import netlib
+import tutils
+
+
+def parse_request(s):
+ return language.parse_pathoc(s, True).next()
+
+
+class TestRequest:
+ def test_nonascii(self):
+ tutils.raises("ascii", parse_request, "get:\xf0")
+
+ def test_err(self):
+ tutils.raises(language.ParseException, parse_request, 'GET')
+
+ def test_simple(self):
+ r = parse_request('GET:"/foo"')
+ assert r.method.string() == "GET"
+ assert r.path.string() == "/foo"
+ r = parse_request('GET:/foo')
+ assert r.path.string() == "/foo"
+
+ def test_multiple(self):
+ r = list(language.parse_pathoc("GET:/ PUT:/"))
+ assert r[0].method.string() == "GET"
+ assert r[1].method.string() == "PUT"
+ assert len(r) == 2
+
+ l = """
+ GET
+ "/foo"
+
+ PUT
+
+ "/foo
+
+
+
+ bar"
+ """
+ r = list(language.parse_pathoc(l, True))
+ assert len(r) == 2
+ assert r[0].method.string() == "GET"
+ assert r[1].method.string() == "PUT"
+
+ l = """
+ get:"http://localhost:9999/p/200"
+ get:"http://localhost:9999/p/200"
+ """
+ r = list(language.parse_pathoc(l, True))
+ assert len(r) == 2
+ assert r[0].method.string() == "GET"
+ assert r[1].method.string() == "GET"
+
+ def test_render(self):
+ s = cStringIO.StringIO()
+ r = parse_request("GET:'/foo'")
+ assert language.serve(
+ r,
+ s,
+ language.Settings(
+ request_host = "foo.com",
+ protocol = netlib.http2.HTTP2Protocol(None)
+ )
+ )
+
+ def test_spec(self):
+ def rt(s):
+ s = parse_request(s).spec()
+ assert parse_request(s).spec() == s
+ rt("get:/foo")