Пример #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)
Пример #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"
Пример #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"
Пример #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)
Пример #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"))
Пример #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"))
Пример #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)
Пример #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)
Пример #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')
Пример #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')
Пример #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
Пример #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
Пример #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)
Пример #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"
Пример #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)
Пример #16
0
 def test_parse_pause_before(self):
     r = rparse.parse_response({}, "400:p0,10")
     assert (0, "pause", 10) in r.actions
Пример #17
0
 def test_parse_pause_after(self):
     r = rparse.parse_response({}, "400:pa,10")
     assert ("a", "pause", 10) in r.actions
Пример #18
0
 def test_render(self):
     s = cStringIO.StringIO()
     r = rparse.parse_response({}, "400'msg'")
     assert r.serve(s, None)
Пример #19
0
 def test_parse_header(self):
     r = rparse.parse_response({}, '400:h"foo"="bar"')
     assert utils.get_header("foo", r.headers)
Пример #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
Пример #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"
Пример #22
0
 def test_parse_header(self):
     r = rparse.parse_response({}, '400:h"foo"="bar"')
     assert utils.get_header("foo", r.headers)
Пример #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"
Пример #24
0
 def test_parse_pause_after(self):
     r = rparse.parse_response({}, "400:pa,10")
     assert ("a", "pause", 10) in r.actions
Пример #25
0
 def test_parse_pause_before(self):
     r = rparse.parse_response({}, "400:p0,10")
     assert (0, "pause", 10) in r.actions
Пример #26
0
 def test_parse_pause_random(self):
     r = rparse.parse_response({}, "400:pr,10")
     assert ("r", "pause", 10) in r.actions
Пример #27
0
 def test_parse_stress(self):
     r = rparse.parse_response({}, "400:b@100g")
     assert r.length()
Пример #28
0
 def dummy_response(self):
     return rparse.parse_response({}, "400'msg'")
Пример #29
0
 def test_parse_pause_random(self):
     r = rparse.parse_response({}, "400:pr,10")
     assert ("r", "pause", 10) in r.actions
Пример #30
0
 def test_serve(self):
     s = cStringIO.StringIO()
     r = rparse.parse_response({}, "400:i0,'foo'")
     assert r.serve(s, None)
Пример #31
0
 def test_parse_stress(self):
     r = rparse.parse_response({}, "400:b@100g")
     assert r.length()
Пример #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"
Пример #33
0
 def dummy_response(self):
     return rparse.parse_response({}, "400'msg'")
Пример #34
0
 def test_request(self):
     r = rparse.parse_response({}, '400:p10,10')
     assert r.actions[0] == (10, "pause", 10)
Пример #35
0
 def test_serve(self):
     s = cStringIO.StringIO()
     r = rparse.parse_response({}, "400:i0,'foo'")
     assert r.serve(s, None)
Пример #36
0
 def test_request(self):
     r = rparse.parse_response({}, '400:p10,10')
     assert r.actions[0] == (10, "pause", 10)
Пример #37
0
 def test_render(self):
     s = cStringIO.StringIO()
     r = rparse.parse_response({}, "400'msg'")
     assert r.serve(s, None)
Пример #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
Пример #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"
Пример #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
Пример #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"
Пример #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