Exemplo n.º 1
0
    def test_getset_query(self):
        h = flow.ODictCaseless()

        r = flow.Request(None, "host", 22, "https", "GET", "/foo?x=y&a=b", h,
                         "content")
        q = r.get_query()
        assert q.lst == [("x", "y"), ("a", "b")]

        r = flow.Request(None, "host", 22, "https", "GET", "/", h, "content")
        q = r.get_query()
        assert not q

        r = flow.Request(None, "host", 22, "https", "GET", "/?adsfa", h,
                         "content")
        q = r.get_query()
        assert not q

        r = flow.Request(None, "host", 22, "https", "GET", "/foo?x=y&a=b", h,
                         "content")
        assert r.get_query()
        r.set_query(flow.ODict([]))
        assert not r.get_query()
        qv = flow.ODict([("a", "b"), ("c", "d")])
        r.set_query(qv)
        assert r.get_query() == qv
Exemplo n.º 2
0
    def test_getset_form_urlencoded(self):
        d = flow.ODict([("one", "two"), ("three", "four")])
        r = tutils.treq(content=utils.urlencode(d.lst))
        r.headers["content-type"] = [protocol.http.HDR_FORM_URLENCODED]
        assert r.get_form_urlencoded() == d

        d = flow.ODict([("x", "y")])
        r.set_form_urlencoded(d)
        assert r.get_form_urlencoded() == d

        r.headers["content-type"] = ["foo"]
        assert not r.get_form_urlencoded()
Exemplo n.º 3
0
    def test_getset_form_urlencoded(self):
        h = flow.ODictCaseless()
        h["content-type"] = [flow.HDR_FORM_URLENCODED]
        d = flow.ODict([("one", "two"), ("three", "four")])
        r = flow.Request(None, (1, 1), "host", 22, "https", "GET", "/", h, utils.urlencode(d.lst))
        assert r.get_form_urlencoded() == d

        d = flow.ODict([("x", "y")])
        r.set_form_urlencoded(d)
        assert r.get_form_urlencoded() == d

        r.headers["content-type"] = ["foo"]
        assert not r.get_form_urlencoded()
Exemplo n.º 4
0
 def test_match_re(self):
     h = flow.ODict()
     h.add("one", "uno")
     h.add("two", "due")
     h.add("two", "tre")
     assert h.match_re("uno")
     assert h.match_re("two: due")
     assert not h.match_re("nonono")
Exemplo n.º 5
0
    def test_getset_query(self):
        h = flow.ODictCaseless()

        r = tutils.treq()
        r.path = "/foo?x=y&a=b"
        q = r.get_query()
        assert q.lst == [("x", "y"), ("a", "b")]

        r.path = "/"
        q = r.get_query()
        assert not q

        r.path = "/?adsfa"
        q = r.get_query()
        assert q.lst == [("adsfa", "")]

        r.path = "/foo?x=y&a=b"
        assert r.get_query()
        r.set_query(flow.ODict([]))
        assert not r.get_query()
        qv = flow.ODict([("a", "b"), ("c", "d")])
        r.set_query(qv)
        assert r.get_query() == qv
Exemplo n.º 6
0
    def test_all(self):

        d = Dummy()
        h = flow.ODict()
        s = cStringIO.StringIO("testing")
        assert proxy.read_http_body(s, d, h, False, None) == ""

        h["content-length"] = ["foo"]
        s = cStringIO.StringIO("testing")
        libpry.raises(proxy.ProxyError, proxy.read_http_body, s, d, h, False,
                      None)

        h["content-length"] = [5]
        s = cStringIO.StringIO("testing")
        assert len(proxy.read_http_body(s, d, h, False, None)) == 5
        s = cStringIO.StringIO("testing")
        libpry.raises(proxy.ProxyError, proxy.read_http_body, s, d, h, False,
                      4)

        h = flow.ODict()
        s = cStringIO.StringIO("testing")
        assert len(proxy.read_http_body(s, d, h, True, 4)) == 4
        s = cStringIO.StringIO("testing")
        assert len(proxy.read_http_body(s, d, h, True, 100)) == 7
Exemplo n.º 7
0
def test_multipartdecode():
    boundary = 'somefancyboundary'
    headers = flow.ODict([('content-type',
                           ('multipart/form-data; boundary=%s' % boundary))])
    content = "--{0}\n" \
              "Content-Disposition: form-data; name=\"field1\"\n\n" \
              "value1\n" \
              "--{0}\n" \
              "Content-Disposition: form-data; name=\"field2\"\n\n" \
              "value2\n" \
              "--{0}--".format(boundary)

    form = utils.multipartdecode(headers, content)

    assert len(form) == 2
    assert form[0] == ('field1', 'value1')
    assert form[1] == ('field2', 'value2')
Exemplo n.º 8
0
    def test_path_components(self):
        r = tutils.treq()
        r.path = "/"
        assert r.get_path_components() == []
        r.path = "/foo/bar"
        assert r.get_path_components() == ["foo", "bar"]
        q = flow.ODict()
        q["test"] = ["123"]
        r.set_query(q)
        assert r.get_path_components() == ["foo", "bar"]

        r.set_path_components([])
        assert r.get_path_components() == []
        r.set_path_components(["foo"])
        assert r.get_path_components() == ["foo"]
        r.set_path_components(["/oo"])
        assert r.get_path_components() == ["/oo"]
        assert "%2F" in r.path
Exemplo n.º 9
0
    def test_path_components(self):
        h = flow.ODictCaseless()
        c = flow.ClientConnect(("addr", 2222))
        r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content")
        assert r.get_path_components() == []
        r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/foo/bar", h, "content")
        assert r.get_path_components() == ["foo", "bar"]
        q = flow.ODict()
        q["test"] = ["123"]
        r.set_query(q)
        assert r.get_path_components() == ["foo", "bar"]

        r.set_path_components([])
        assert r.get_path_components() == []
        r.set_path_components(["foo"])
        assert r.get_path_components() == ["foo"]
        r.set_path_components(["/oo"])
        assert r.get_path_components() == ["/oo"]
        assert "%2F" in r.path
Exemplo n.º 10
0
 def test_str_err(self):
     h = flow.ODict()
     libpry.raises(ValueError, h.__setitem__, "key", "foo")
Exemplo n.º 11
0
 def setUp(self):
     self.od = flow.ODict()