Example #1
0
 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)
Example #2
0
    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"
Example #3
0
    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"
Example #4
0
 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)
Example #5
0
 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"))
Example #6
0
    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"))
Example #7
0
    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)
Example #8
0
    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)
Example #9
0
    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')
Example #10
0
    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')
Example #11
0
    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
Example #12
0
    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
Example #13
0
    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)
Example #14
0
    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"
Example #15
0
    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)
Example #16
0
 def test_parse_pause_before(self):
     r = rparse.parse_response({}, "400:p0,10")
     assert (0, "pause", 10) in r.actions
Example #17
0
 def test_parse_pause_after(self):
     r = rparse.parse_response({}, "400:pa,10")
     assert ("a", "pause", 10) in r.actions
Example #18
0
 def test_render(self):
     s = cStringIO.StringIO()
     r = rparse.parse_response({}, "400'msg'")
     assert r.serve(s, None)
Example #19
0
 def test_parse_header(self):
     r = rparse.parse_response({}, '400:h"foo"="bar"')
     assert utils.get_header("foo", r.headers)
Example #20
0
 def test_file(self):
     p = tutils.test_data.path("data")
     d = dict(staticdir=p)
     r = rparse.parse_response(d, "+response")
     assert r.code == 202
Example #21
0
 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"
Example #22
0
 def test_parse_header(self):
     r = rparse.parse_response({}, '400:h"foo"="bar"')
     assert utils.get_header("foo", r.headers)
Example #23
0
 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"
Example #24
0
 def test_parse_pause_after(self):
     r = rparse.parse_response({}, "400:pa,10")
     assert ("a", "pause", 10) in r.actions
Example #25
0
 def test_parse_pause_before(self):
     r = rparse.parse_response({}, "400:p0,10")
     assert (0, "pause", 10) in r.actions
Example #26
0
 def test_parse_pause_random(self):
     r = rparse.parse_response({}, "400:pr,10")
     assert ("r", "pause", 10) in r.actions
Example #27
0
 def test_parse_stress(self):
     r = rparse.parse_response({}, "400:b@100g")
     assert r.length()
Example #28
0
 def dummy_response(self):
     return rparse.parse_response({}, "400'msg'")
Example #29
0
 def test_parse_pause_random(self):
     r = rparse.parse_response({}, "400:pr,10")
     assert ("r", "pause", 10) in r.actions
Example #30
0
 def test_serve(self):
     s = cStringIO.StringIO()
     r = rparse.parse_response({}, "400:i0,'foo'")
     assert r.serve(s, None)
Example #31
0
 def test_parse_stress(self):
     r = rparse.parse_response({}, "400:b@100g")
     assert r.length()
Example #32
0
 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"
Example #33
0
 def dummy_response(self):
     return rparse.parse_response({}, "400'msg'")
Example #34
0
 def test_request(self):
     r = rparse.parse_response({}, '400:p10,10')
     assert r.actions[0] == (10, "pause", 10)
Example #35
0
 def test_serve(self):
     s = cStringIO.StringIO()
     r = rparse.parse_response({}, "400:i0,'foo'")
     assert r.serve(s, None)
Example #36
0
 def test_request(self):
     r = rparse.parse_response({}, '400:p10,10')
     assert r.actions[0] == (10, "pause", 10)
Example #37
0
 def test_render(self):
     s = cStringIO.StringIO()
     r = rparse.parse_response({}, "400'msg'")
     assert r.serve(s, None)
Example #38
0
 def test_file(self):
     p = tutils.test_data.path("data")
     d = dict(staticdir=p)
     r = rparse.parse_response(d, "+response")
     assert r.code == 202
Example #39
0
 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"
Example #40
0
 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
Example #41
0
 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"
Example #42
0
 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