示例#1
0
 def test_parse_err(self):
     tutils.raises(language.ParseException, language.parse_pathod, "400:msg,b:")
     try:
         language.parse_pathod("400'msg':b:")
     except language.ParseException as v:
         assert v.marked()
         assert str(v)
def test_shortcuts():
    assert language.parse_pathod(
        "400:c'foo'").next().headers[0].key.val == "Content-Type"
    assert language.parse_pathod(
        "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"))
    def test_parse_pathod(self):
        a = language.parse_pathod("400:ir,@100").next().actions[0]
        assert a.offset == "r"
        assert a.value.datatype == "bytes"
        assert a.value.usize == 100

        a = language.parse_pathod("400:ia,@100").next().actions[0]
        assert a.offset == "a"
示例#4
0
def test_shortcuts():
    assert language.parse_pathod(
        "400:c'foo'").next().headers[0].key.val == "Content-Type"
    assert language.parse_pathod(
        "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"))
示例#5
0
    def test_parse_pathod(self):
        a = language.parse_pathod("400:ir,@100").next().actions[0]
        assert a.offset == "r"
        assert a.value.datatype == "bytes"
        assert a.value.usize == 100

        a = language.parse_pathod("400:ia,@100").next().actions[0]
        assert a.offset == "a"
 def test_parse_err(self):
     tutils.raises(language.ParseException, language.parse_pathod,
                   "400:msg,b:")
     try:
         language.parse_pathod("400'msg':b:")
     except language.ParseException as v:
         assert v.marked()
         assert str(v)
    def test_render(self):
        s = cStringIO.StringIO()
        r = language.parse_pathod("400:m'msg'").next()
        assert language.serve(r, s, {})

        r = language.parse_pathod("400:p0,100:dr").next()
        assert "p0" in r.spec()
        s = r.preview_safe()
        assert "p0" not in s.spec()
示例#8
0
    def test_render(self):
        s = cStringIO.StringIO()
        r = language.parse_pathod("400:m'msg'").next()
        assert language.serve(r, s, {})

        r = language.parse_pathod("400:p0,100:dr").next()
        assert "p0" in r.spec()
        s = r.preview_safe()
        assert "p0" not in s.spec()
示例#9
0
 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"))
     testlen(language.parse_pathod("400:m'msg':h'foo'='bar':r"))
     testlen(language.parse_pathod("400:m'msg':h'foo'='bar':b@100b:r"))
示例#10
0
    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"))
        testlen(language.parse_pathod("400:m'msg':h'foo'='bar':r"))
        testlen(language.parse_pathod("400:m'msg':h'foo'='bar':b@100b:r"))
示例#11
0
    def test_raw(self):
        s = cStringIO.StringIO()
        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").next()
        language.serve(r, s, {})
        v = s.getvalue()
        assert "Content-Length" not in v
示例#12
0
    def test_raw(self):
        s = cStringIO.StringIO()
        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").next()
        language.serve(r, s, {})
        v = s.getvalue()
        assert "Content-Length" not in v
def test_write_values_after():
    s = cStringIO.StringIO()
    r = language.parse_pathod("400:da").next()
    language.serve(r, s, {})

    s = cStringIO.StringIO()
    r = language.parse_pathod("400:pa,0").next()
    language.serve(r, s, {})

    s = cStringIO.StringIO()
    r = language.parse_pathod("400:ia,'xx'").next()
    language.serve(r, s, {})
    assert s.getvalue().endswith('xx')
示例#14
0
def test_write_values_after():
    s = cStringIO.StringIO()
    r = language.parse_pathod("400:da").next()
    language.serve(r, s, {})

    s = cStringIO.StringIO()
    r = language.parse_pathod("400:pa,0").next()
    language.serve(r, s, {})

    s = cStringIO.StringIO()
    r = language.parse_pathod("400:ia,'xx'").next()
    language.serve(r, s, {})
    assert s.getvalue().endswith('xx')
示例#15
0
    def test_response(self):
        r = language.parse_pathod("400:m'msg'").next()
        assert r.status_code.string() == "400"
        assert r.reason.string() == "msg"

        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").next()
        assert r.status_code.string() == "200"
        assert not r.reason
        assert "OK" in [i[:] for i in r.preamble({})]
示例#16
0
    def test_response(self):
        r = language.parse_pathod("400:m'msg'").next()
        assert r.status_code.string() == "400"
        assert r.reason.string() == "msg"

        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").next()
        assert r.status_code.string() == "200"
        assert not r.reason
        assert "OK" in [i[:] for i in r.preamble({})]
示例#17
0
 def test_parse_stress(self):
     # While larger values are known to work on linux, len() technically
     # 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").next()
     assert r.length({})
示例#18
0
 def test_parse_stress(self):
     # While larger values are known to work on linux, len() technically
     # 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").next()
     assert r.length({})
示例#19
0
    def test_maximum_length(self):
        def testlen(x):
            x = x.next()
            s = cStringIO.StringIO()
            m = x.maximum_length({})
            language.serve(x, s, {})
            assert m >= len(s.getvalue())

        r = language.parse_pathod("400:m'msg':b@100:d0")
        testlen(r)

        r = language.parse_pathod("400:m'msg':b@100:d0:i0,'foo'")
        testlen(r)

        r = language.parse_pathod("400:m'msg':b@100:d0:i0,'foo'")
        testlen(r)
示例#20
0
    def test_maximum_length(self):
        def testlen(x):
            x = x.next()
            s = cStringIO.StringIO()
            m = x.maximum_length({})
            language.serve(x, s, {})
            assert m >= len(s.getvalue())

        r = language.parse_pathod("400:m'msg':b@100:d0")
        testlen(r)

        r = language.parse_pathod("400:m'msg':b@100:d0:i0,'foo'")
        testlen(r)

        r = language.parse_pathod("400:m'msg':b@100:d0:i0,'foo'")
        testlen(r)
示例#21
0
 def test_parse_header(self):
     r = language.parse_pathod('400:h"foo"="bar"').next()
     assert http.get_header("foo", r.headers)
示例#22
0
 def test_request(self):
     r = language.parse_pathod('400:p10,10').next()
     assert r.actions[0].spec() == "p10,10"
示例#23
0
def parse_response(s):
    return language.parse_pathod(s, True).next()
示例#24
0
 def dummy_response(self):
     return language.parse_pathod("400'msg'").next()
示例#25
0
 def test_websockets(self):
     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.status_code.string() == "101"
示例#26
0
 def test_parse_pause_random(self):
     r = language.parse_pathod("400:pr,10").next()
     assert r.actions[0].spec() == "pr,10"
示例#27
0
 def test_serve(self):
     s = cStringIO.StringIO()
     r = language.parse_pathod("400:i0,'foo'").next()
     assert language.serve(r, s, {})
示例#28
0
 def rt(s):
     s = language.parse_pathod(s).next().spec()
     assert language.parse_pathod(s).next().spec() == s
示例#29
0
 def test_parse_pause_random(self):
     r = language.parse_pathod("400:pr,10").next()
     assert r.actions[0].spec() == "pr,10"
 def test_parse_pathod(self):
     a = language.parse_pathod("400:d0").next().actions[0]
     assert a.spec() == "d0"
     a = language.parse_pathod("400:dr").next().actions[0]
     assert a.spec() == "dr"
示例#31
0
def parse_response(s):
    return language.parse_pathod(s, True).next()
示例#32
0
 def test_parse_pathod(self):
     a = language.parse_pathod("400:d0").next().actions[0]
     assert a.spec() == "d0"
     a = language.parse_pathod("400:dr").next().actions[0]
     assert a.spec() == "dr"
示例#33
0
 def test_parse_pause_before(self):
     r = language.parse_pathod("400:p0,10").next()
     assert r.actions[0].spec() == "p0,10"
示例#34
0
 def test_parse_pause_before(self):
     r = language.parse_pathod("400:p0,10").next()
     assert r.actions[0].spec() == "p0,10"
示例#35
0
 def test_parse_pause_after(self):
     r = language.parse_pathod("400:pa,10").next()
     assert r.actions[0].spec() == "pa,10"
示例#36
0
 def test_parse_pause_after(self):
     r = language.parse_pathod("400:pa,10").next()
     assert r.actions[0].spec() == "pa,10"
 def test_serve(self):
     s = cStringIO.StringIO()
     r = language.parse_pathod("400:i0,'foo'").next()
     assert language.serve(r, s, {})
示例#38
0
 def rt(s):
     s = language.parse_pathod(s).next().spec()
     assert language.parse_pathod(s).next().spec() == s
示例#39
0
 def test_websockets(self):
     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.status_code.string() == "101"
 def test_request(self):
     r = language.parse_pathod('400:p10,10').next()
     assert r.actions[0].spec() == "p10,10"
示例#41
0
 def dummy_response(self):
     return language.parse_pathod("400'msg'").next()
示例#42
0
 def test_parse_header(self):
     r = language.parse_pathod('400:h"foo"="bar"').next()
     assert http.get_header("foo", r.headers)