Exemple #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
Exemple #2
0
def treq(conn=None):
    if not conn:
        conn = flow.ClientConnect(("address", 22))
    headers = flow.ODictCaseless()
    headers["header"] = ["qvalue"]
    return flow.Request(conn, (1, 1), "host", 80, "http", "GET", "/path",
                        headers, "content")
Exemple #3
0
    def test_simple(self):
        h = flow.ODictCaseless()
        h["test"] = ["test"]
        c = flow.ClientConnect(("addr", 2222))
        r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h,
                         "content")
        u = r.get_url()
        assert r.set_url(u)
        assert not r.set_url("")
        assert r.get_url() == u
        assert r._assemble()
        assert r.size() == len(r._assemble())

        r2 = r.copy()
        assert r == r2

        r.content = None
        assert r._assemble()
        assert r.size() == len(r._assemble())

        r.close = True
        assert "connection: close" in r._assemble()

        assert r._assemble(True)

        r.content = flow.CONTENT_MISSING
        assert not r._assemble()
Exemple #4
0
 def req(self):
     conn = flow.ClientConnect(("one", 2222))
     headers = flow.ODictCaseless()
     headers["header"] = ["qvalue"]
     req = flow.Request(conn, (1, 1), "host", 80, "http", "GET", "/path",
                        headers, "content_request")
     return flow.Flow(req)
Exemple #5
0
 def test_get_header_size(self):
     h = flow.ODictCaseless()
     h["headername"] = ["headervalue"]
     c = flow.ClientConnect(("addr", 2222))
     r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content")
     result = r.get_header_size()
     assert result==43
Exemple #6
0
 def test_get_content_type(self):
     h = flow.ODictCaseless()
     h["Content-Type"] = ["text/plain"]
     c = flow.ClientConnect(("addr", 2222))
     r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h,
                      "content")
     assert r.get_content_type() == "text/plain"
Exemple #7
0
 def test_get_cookies_single(self):
     h = flow.ODictCaseless()
     h["Cookie"] = ["cookiename=cookievalue"]
     c = flow.ClientConnect(("addr", 2222))
     r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content")
     result = r.get_cookies()
     assert len(result)==1
     assert result['cookiename']==('cookievalue',{})
Exemple #8
0
 def test_anticache(self):
     h = flow.ODictCaseless()
     r = flow.Request(None, "host", 22, "https", "GET", "/", h, "content")
     h["if-modified-since"] = ["test"]
     h["if-none-match"] = ["test"]
     r.anticache()
     assert not "if-modified-since" in r.headers
     assert not "if-none-match" in r.headers
Exemple #9
0
    def test_simple(self):
        h = flow.Headers()
        h["test"] = ["test"]
        c = flow.ClientConnect(("addr", 2222))
        req = flow.Request(c, "host", 22, "https", "GET", "/", h, "content")
        resp = flow.Response(req, 200, "msg", h.copy(), "content")
        assert resp._assemble()

        resp2 = resp.copy()
        assert resp2 == resp
Exemple #10
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
Exemple #11
0
 def test_get_url(self):
     h = flow.ODictCaseless()
     h["test"] = ["test"]
     c = flow.ClientConnect(("addr", 2222))
     r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content")
     assert r.get_url() == "https://host:22/"
     assert r.get_url(hostheader=True) == "https://host:22/"
     r.headers["Host"] = ["foo.com"]
     assert r.get_url() == "https://host:22/"
     assert r.get_url(hostheader=True) == "https://foo.com:22/"
Exemple #12
0
    def test_getset_state(self):
        h = flow.ODictCaseless()
        h["test"] = ["test"]
        c = flow.ClientConnect(("addr", 2222))
        r = flow.Request(c, "host", 22, "https", "GET", "/", h, "content")
        state = r._get_state()
        assert flow.Request._from_state(state) == r

        r.client_conn = None
        state = r._get_state()
        assert flow.Request._from_state(state) == r

        r2 = flow.Request(c, "testing", 20, "http", "PUT", "/foo", h, "test")
        assert not r == r2
        r._load_state(r2._get_state())
        assert r == r2

        r2.client_conn = None
        r._load_state(r2._get_state())
        assert not r.client_conn
Exemple #13
0
    def test_simple(self):
        h = flow.Headers()
        h["test"] = ["test"]
        c = flow.ClientConnect(("addr", 2222))
        r = flow.Request(c, "host", 22, "https", "GET", "/", h, "content")
        u = r.get_url()
        assert r.set_url(u)
        assert not r.set_url("")
        assert r.get_url() == u
        assert r._assemble()

        r2 = r.copy()
        assert r == r2
Exemple #14
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()
Exemple #15
0
    def test_getset_state(self):
        h = flow.ODictCaseless()
        h["test"] = ["test"]
        c = flow.ClientConnect(("addr", 2222))
        req = flow.Request(c, "host", 22, "https", "GET", "/", h, "content")
        resp = flow.Response(req, 200, "msg", h.copy(), "content")

        state = resp._get_state()
        assert flow.Response._from_state(req, state) == resp

        resp2 = flow.Response(req, 220, "foo", h.copy(), "test")
        assert not resp == resp2
        resp._load_state(resp2._get_state())
        assert resp == resp2
Exemple #16
0
    def test_simple(self):
        h = flow.ODictCaseless()
        h["test"] = ["test"]
        c = flow.ClientConnect(("addr", 2222))
        req = flow.Request(c, "host", 22, "https", "GET", "/", h, "content")
        resp = flow.Response(req, 200, "msg", h.copy(), "content")
        assert resp._assemble()

        resp2 = resp.copy()
        assert resp2 == resp

        resp.content = None
        assert resp._assemble()

        resp.request.client_conn.close = True
        assert "connection: close" in resp._assemble()
Exemple #17
0
    def test_simple(self):
        h = flow.ODictCaseless()
        h["test"] = ["test"]
        c = flow.ClientConnect(("addr", 2222))
        req = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content")
        resp = flow.Response(req, (1, 1), 200, "msg", h.copy(), "content", None)
        assert resp._assemble()
        assert resp.size() == len(resp._assemble())


        resp2 = resp.copy()
        assert resp2 == resp

        resp.content = None
        assert resp._assemble()
        assert resp.size() == len(resp._assemble())

        resp.content = flow.CONTENT_MISSING
        assert not resp._assemble()
Exemple #18
0
 def req(self):
     conn = flow.ClientConnect(("one", 2222))
     headers = flow.Headers()
     headers["header"] = ["qvalue"]
     return flow.Request(conn, "host", 80, "http", "GET", "/path", headers,
                         "content_request")
Exemple #19
0
 def test_get_cookies_none(self):
     h = flow.ODictCaseless()
     c = flow.ClientConnect(("addr", 2222))
     r = flow.Request(c, (1, 1), "host", 22, "https", "GET", "/", h, "content")
     assert r.get_cookies() == None