def test_parse_err(self): tutils.raises(rparse.ParseException, rparse.parse_response, {}, "400:msg,b:") try: rparse.parse_response({}, "400'msg':b:") except rparse.ParseException, v: assert v.marked() assert str(v)
def test_parse_response(self): a = rparse.parse_response({}, "400:ir,@100").actions[0] assert a[0] == "r" assert a[1] == "inject" a = rparse.parse_response({}, "400:ia,@100").actions[0] assert a[0] == "a" assert a[1] == "inject"
def test_length(self): def testlen(x): s = cStringIO.StringIO() x.serve(s, None) assert x.length() == len(s.getvalue()) testlen(rparse.parse_response({}, "400'msg'")) testlen(rparse.parse_response({}, "400'msg':h'foo'='bar'")) testlen(rparse.parse_response({}, "400'msg':h'foo'='bar':b@100b"))
def test_response(self): r = rparse.parse_response({}, "400'msg'") assert r.code == 400 assert r.msg == "msg" r = rparse.parse_response({}, "400'msg':b@100b") assert r.msg == "msg" assert r.body[:] assert str(r)
def test_write_values_after(self): s = cStringIO.StringIO() r = rparse.parse_response({}, "400:da") r.serve(s, None) s = cStringIO.StringIO() r = rparse.parse_response({}, "400:pa,0") r.serve(s, None) s = cStringIO.StringIO() r = rparse.parse_response({}, "400:ia,'xx'") r.serve(s, None) assert s.getvalue().endswith('xx')
def test_raw(self): s = cStringIO.StringIO() r = rparse.parse_response({}, "400:b'foo'") r.serve(s, None) v = s.getvalue() assert "Content-Length" in v assert "Date" in v s = cStringIO.StringIO() r = rparse.parse_response({}, "400:b'foo':r") r.serve(s, None) v = s.getvalue() assert not "Content-Length" in v assert not "Date" in v
def test_effective_length(self): def testlen(x, actions): s = cStringIO.StringIO() x.serve(s, None) assert x.effective_length(actions) == len(s.getvalue()) actions = [ ] r = rparse.parse_response({}, "400'msg':b@100") actions = [ (0, "disconnect"), ] r.actions = actions testlen(r, actions) actions = [ (0, "disconnect"), (0, "inject", "foo") ] r.actions = actions testlen(r, actions) actions = [ (0, "inject", "foo") ] r.actions = actions testlen(r, actions)
def test_checkfunc(self): s = cStringIO.StringIO() r = rparse.parse_response({}, "400:b@100k") def check(req, acts): return "errmsg" assert r.serve(s, check=check)["error"] == "errmsg"
def test_effective_length(self): def testlen(x, actions): s = cStringIO.StringIO() x.serve(s, None) assert x.effective_length(actions) == len(s.getvalue()) actions = [] r = rparse.parse_response({}, "400'msg':b@100") actions = [ (0, "disconnect"), ] r.actions = actions testlen(r, actions) actions = [(0, "disconnect"), (0, "inject", "foo")] r.actions = actions testlen(r, actions) actions = [(0, "inject", "foo")] r.actions = actions testlen(r, actions)
def test_parse_pause_before(self): r = rparse.parse_response({}, "400:p0,10") assert (0, "pause", 10) in r.actions
def test_parse_pause_after(self): r = rparse.parse_response({}, "400:pa,10") assert ("a", "pause", 10) in r.actions
def test_render(self): s = cStringIO.StringIO() r = rparse.parse_response({}, "400'msg'") assert r.serve(s, None)
def test_parse_header(self): r = rparse.parse_response({}, '400:h"foo"="bar"') assert utils.get_header("foo", r.headers)
def test_file(self): p = tutils.test_data.path("data") d = dict(staticdir=p) r = rparse.parse_response(d, "+response") assert r.code == 202
def test_parse_response(self): assert rparse.parse_response( {}, "400:c'foo'").headers[0][0][:] == "Content-Type" assert rparse.parse_response( {}, "400:l'foo'").headers[0][0][:] == "Location"
def test_parse_pause_random(self): r = rparse.parse_response({}, "400:pr,10") assert ("r", "pause", 10) in r.actions
def test_parse_stress(self): r = rparse.parse_response({}, "400:b@100g") assert r.length()
def dummy_response(self): return rparse.parse_response({}, "400'msg'")
def test_serve(self): s = cStringIO.StringIO() r = rparse.parse_response({}, "400:i0,'foo'") assert r.serve(s, None)
def test_parse_response(self): assert rparse.parse_response({}, "400:c'foo'").headers[0][0][:] == "Content-Type" assert rparse.parse_response({}, "400:l'foo'").headers[0][0][:] == "Location"
def test_request(self): r = rparse.parse_response({}, '400:p10,10') assert r.actions[0] == (10, "pause", 10)
def test_render(self): r = rparse.parse_response({}, "400:p0,100:dr") assert r.actions[0][1] == "pause" assert len(r.preview_safe()) == 1 assert not r.actions[0][1] == "pause"
def test_parse_response(self): assert (0, "disconnect") in rparse.parse_response({}, "400:d0").actions assert ("r", "disconnect") in rparse.parse_response({}, "400:dr").actions