diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2015-06-07 16:11:32 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2015-06-07 16:11:32 +1200 |
commit | df962f8e7bab9d8cd1dc9143f44977b0711c5bd9 (patch) | |
tree | 3e949abaad30590c0c822c0293ae0fd494ff1c2a /test/test_language_http.py | |
parent | 0da3e51e1c08eed2c8054d4a71bc591268b19af1 (diff) | |
download | mitmproxy-df962f8e7bab9d8cd1dc9143f44977b0711c5bd9.tar.gz mitmproxy-df962f8e7bab9d8cd1dc9143f44977b0711c5bd9.tar.bz2 mitmproxy-df962f8e7bab9d8cd1dc9143f44977b0711c5bd9.zip |
Convert parse_pathod to generator
Diffstat (limited to 'test/test_language_http.py')
-rw-r--r-- | test/test_language_http.py | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/test/test_language_http.py b/test/test_language_http.py index f9bbd273..02f0f998 100644 --- a/test/test_language_http.py +++ b/test/test_language_http.py @@ -143,42 +143,42 @@ class TestRequest: class TestResponse: def dummy_response(self): - return language.parse_pathod("400'msg'") + return language.parse_pathod("400'msg'").next() def test_response(self): - r = language.parse_pathod("400:m'msg'") + r = language.parse_pathod("400:m'msg'").next() assert r.code.string() == "400" assert r.reason.string() == "msg" - r = language.parse_pathod("400:m'msg':b@100b") + r = language.parse_pathod("400:m'msg':b@100b").next() assert r.reason.string() == "msg" assert r.body.values({}) assert str(r) - r = language.parse_pathod("200") + r = language.parse_pathod("200").next() assert r.code.string() == "200" assert not r.reason assert "OK" in [i[:] for i in r.preamble({})] def test_render(self): s = cStringIO.StringIO() - r = language.parse_pathod("400:m'msg'") + r = language.parse_pathod("400:m'msg'").next() assert language.serve(r, s, {}) - r = language.parse_pathod("400:p0,100:dr") + r = language.parse_pathod("400:p0,100:dr").next() assert "p0" in r.spec() s = r.preview_safe() assert "p0" not in s.spec() def test_raw(self): s = cStringIO.StringIO() - r = language.parse_pathod("400:b'foo'") + r = language.parse_pathod("400:b'foo'").next() language.serve(r, s, {}) v = s.getvalue() assert "Content-Length" in v s = cStringIO.StringIO() - r = language.parse_pathod("400:b'foo':r") + r = language.parse_pathod("400:b'foo':r").next() language.serve(r, s, {}) v = s.getvalue() assert "Content-Length" not in v @@ -186,6 +186,7 @@ class TestResponse: def test_length(self): def testlen(x): s = cStringIO.StringIO() + x = x.next() language.serve(x, s, language.Settings()) assert x.length(language.Settings()) == len(s.getvalue()) testlen(language.parse_pathod("400:m'msg':r")) @@ -194,6 +195,7 @@ class TestResponse: def test_maximum_length(self): def testlen(x): + x = x.next() s = cStringIO.StringIO() m = x.maximum_length({}) language.serve(x, s, {}) @@ -222,19 +224,19 @@ class TestResponse: tutils.raises("ascii", language.parse_pathod, "foo:b\xf0") def test_parse_header(self): - r = language.parse_pathod('400:h"foo"="bar"') + r = language.parse_pathod('400:h"foo"="bar"').next() assert http.get_header("foo", r.headers) def test_parse_pause_before(self): - r = language.parse_pathod("400:p0,10") + r = language.parse_pathod("400:p0,10").next() assert r.actions[0].spec() == "p0,10" def test_parse_pause_after(self): - r = language.parse_pathod("400:pa,10") + r = language.parse_pathod("400:pa,10").next() assert r.actions[0].spec() == "pa,10" def test_parse_pause_random(self): - r = language.parse_pathod("400:pr,10") + r = language.parse_pathod("400:pr,10").next() assert r.actions[0].spec() == "pr,10" def test_parse_stress(self): @@ -242,19 +244,19 @@ class TestResponse: # returns an int and a python 2.7 int on windows has 32bit precision. # Therefore, we should keep the body length < 2147483647 bytes in our # tests. - r = language.parse_pathod("400:b@1g") + r = language.parse_pathod("400:b@1g").next() assert r.length({}) def test_spec(self): def rt(s): - s = language.parse_pathod(s).spec() - assert language.parse_pathod(s).spec() == s + s = language.parse_pathod(s).next().spec() + assert language.parse_pathod(s).next().spec() == s rt("400:b@100g") rt("400") rt("400:da") def test_websockets(self): - r = language.parse_pathod("ws") + r = language.parse_pathod("ws").next() tutils.raises("no websocket key", r.resolve, language.Settings()) res = r.resolve(language.Settings(websocket_key="foo")) assert res.code.string() == "101" @@ -294,9 +296,9 @@ def test_location_shortcut(): def test_shortcuts(): assert language.parse_pathod( - "400:c'foo'").headers[0].key.val == "Content-Type" + "400:c'foo'").next().headers[0].key.val == "Content-Type" assert language.parse_pathod( - "400:l'foo'").headers[0].key.val == "Location" + "400:l'foo'").next().headers[0].key.val == "Location" assert "Android" in tutils.render(parse_request("get:/:ua")) assert "User-Agent" in tutils.render(parse_request("get:/:ua")) |