diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_flow.py | 102 | ||||
-rw-r--r-- | test/test_protocol_http.py | 12 | ||||
-rw-r--r-- | test/test_proxy.py | 4 | ||||
-rw-r--r-- | test/test_server.py | 11 |
4 files changed, 62 insertions, 67 deletions
diff --git a/test/test_flow.py b/test/test_flow.py index 6e9464e7..4bc2391e 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -753,10 +753,10 @@ class TestRequest: def test_simple(self): f = tutils.tflow() r = f.request - u = r.get_url(False, f) - assert r.set_url(u, f) - assert not r.set_url("", f) - assert r.get_url(False, f) == u + u = r.url + r.url = u + tutils.raises(ValueError, setattr, r, "url", "") + assert r.url == u assert r._assemble() assert r.size() == len(r._assemble()) @@ -771,83 +771,81 @@ class TestRequest: tutils.raises("Cannot assemble flow with CONTENT_MISSING", r._assemble) def test_get_url(self): - f = tutils.tflow() - r = f.request + r = tutils.treq() - assert r.get_url(False, f) == "http://address:22/path" + assert r.url == "http://address:22/path" r.scheme = "https" - assert r.get_url(False, f) == "https://address:22/path" + assert r.url == "https://address:22/path" r.host = "host" r.port = 42 - assert r.get_url(False, f) == "https://host:42/path" + assert r.url == "https://host:42/path" r.host = "address" r.port = 22 - assert r.get_url(False, f) == "https://address:22/path" + assert r.url== "https://address:22/path" - assert r.get_url(True, f) == "https://address:22/path" + assert r.pretty_url(True) == "https://address:22/path" r.headers["Host"] = ["foo.com"] - assert r.get_url(False, f) == "https://address:22/path" - assert r.get_url(True, f) == "https://foo.com:22/path" + assert r.pretty_url(False) == "https://address:22/path" + assert r.pretty_url(True) == "https://foo.com:22/path" def test_path_components(self): - f = tutils.tflow() - r = f.request + r = tutils.treq() r.path = "/" - assert r.get_path_components(f) == [] + assert r.path_components == [] r.path = "/foo/bar" - assert r.get_path_components(f) == ["foo", "bar"] + assert r.path_components == ["foo", "bar"] q = flow.ODict() q["test"] = ["123"] - r.set_query(q, f) - assert r.get_path_components(f) == ["foo", "bar"] - - r.set_path_components([], f) - assert r.get_path_components(f) == [] - r.set_path_components(["foo"], f) - assert r.get_path_components(f) == ["foo"] - r.set_path_components(["/oo"], f) - assert r.get_path_components(f) == ["/oo"] + r.query = q + assert r.path_components == ["foo", "bar"] + + r.path_components = [] + assert r.path_components == [] + r.path_components = ["foo"] + assert r.path_components == ["foo"] + r.path_components = ["/oo"] + assert r.path_components == ["/oo"] assert "%2F" in r.path 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 + assert r.form_urlencoded == d d = flow.ODict([("x", "y")]) - r.set_form_urlencoded(d) - assert r.get_form_urlencoded() == d + r.form_urlencoded = d + assert r.form_urlencoded == d r.headers["content-type"] = ["foo"] - assert not r.get_form_urlencoded() + assert not r.form_urlencoded def test_getset_query(self): h = flow.ODictCaseless() - f = tutils.tflow() - f.request.path = "/foo?x=y&a=b" - q = f.request.get_query(f) + r = tutils.treq() + r.path = "/foo?x=y&a=b" + q = r.query assert q.lst == [("x", "y"), ("a", "b")] - f.request.path = "/" - q = f.request.get_query(f) + r.path = "/" + q = r.query assert not q - f.request.path = "/?adsfa" - q = f.request.get_query(f) + r.path = "/?adsfa" + q = r.query assert q.lst == [("adsfa", "")] - f.request.path = "/foo?x=y&a=b" - assert f.request.get_query(f) - f.request.set_query(flow.ODict([]), f) - assert not f.request.get_query(f) + r.path = "/foo?x=y&a=b" + assert r.query + r.query = flow.ODict([]) + assert not r.query qv = flow.ODict([("a", "b"), ("c", "d")]) - f.request.set_query(qv, f) - assert f.request.get_query(f) == qv + r.query = qv + assert r.query == qv def test_anticache(self): h = flow.ODictCaseless() @@ -918,14 +916,14 @@ class TestRequest: h = flow.ODictCaseless() r = tutils.treq() r.headers = h - assert r.get_cookies() is None + assert r.cookies is None def test_get_cookies_single(self): h = flow.ODictCaseless() h["Cookie"] = ["cookiename=cookievalue"] r = tutils.treq() r.headers = h - result = r.get_cookies() + result = r.cookies assert len(result)==1 assert result['cookiename']==('cookievalue',{}) @@ -934,7 +932,7 @@ class TestRequest: h["Cookie"] = ["cookiename=cookievalue;othercookiename=othercookievalue"] r = tutils.treq() r.headers = h - result = r.get_cookies() + result = r.cookies assert len(result)==2 assert result['cookiename']==('cookievalue',{}) assert result['othercookiename']==('othercookievalue',{}) @@ -944,7 +942,7 @@ class TestRequest: h["Cookie"] = ["cookiename=coo=kievalue;othercookiename=othercookievalue"] r = tutils.treq() r.headers = h - result = r.get_cookies() + result = r.cookies assert len(result)==2 assert result['cookiename']==('coo=kievalue',{}) assert result['othercookiename']==('othercookievalue',{}) @@ -1054,14 +1052,14 @@ class TestResponse: h = flow.ODictCaseless() resp = tutils.tresp() resp.headers = h - assert not resp.get_cookies() + assert not resp.cookies def test_get_cookies_simple(self): h = flow.ODictCaseless() h["Set-Cookie"] = ["cookiename=cookievalue"] resp = tutils.tresp() resp.headers = h - result = resp.get_cookies() + result = resp.cookies assert len(result)==1 assert "cookiename" in result assert result["cookiename"] == ("cookievalue", {}) @@ -1071,7 +1069,7 @@ class TestResponse: h["Set-Cookie"] = ["cookiename=cookievalue;domain=example.com;expires=Wed Oct 21 16:29:41 2015;path=/; HttpOnly"] resp = tutils.tresp() resp.headers = h - result = resp.get_cookies() + result = resp.cookies assert len(result)==1 assert "cookiename" in result assert result["cookiename"][0] == "cookievalue" @@ -1086,7 +1084,7 @@ class TestResponse: h["Set-Cookie"] = ["cookiename=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/"] resp = tutils.tresp() resp.headers = h - result = resp.get_cookies() + result = resp.cookies assert len(result)==1 assert "cookiename" in result assert result["cookiename"][0] == "" @@ -1097,7 +1095,7 @@ class TestResponse: h["Set-Cookie"] = ["cookiename=cookievalue","othercookie=othervalue"] resp = tutils.tresp() resp.headers = h - result = resp.get_cookies() + result = resp.cookies assert len(result)==2 assert "cookiename" in result assert result["cookiename"] == ("cookievalue", {}) diff --git a/test/test_protocol_http.py b/test/test_protocol_http.py index c2ff7b44..c76fa192 100644 --- a/test/test_protocol_http.py +++ b/test/test_protocol_http.py @@ -58,12 +58,12 @@ class TestHTTPRequest: tutils.raises("Invalid request form", r._assemble, "antiauthority") def test_set_url(self): - f = tutils.tflow(req=tutils.treq_absolute()) - f.request.set_url("https://otheraddress:42/ORLY", f) - assert f.request.scheme == "https" - assert f.request.host == "otheraddress" - assert f.request.port == 42 - assert f.request.path == "/ORLY" + r = tutils.treq_absolute() + r.url = "https://otheraddress:42/ORLY" + assert r.scheme == "https" + assert r.host == "otheraddress" + assert r.port == 42 + assert r.path == "/ORLY" class TestHTTPResponse: diff --git a/test/test_proxy.py b/test/test_proxy.py index 91e4954f..ad2bb2d7 100644 --- a/test/test_proxy.py +++ b/test/test_proxy.py @@ -23,7 +23,7 @@ class TestServerConnection: self.d.shutdown() def test_simple(self): - sc = ServerConnection((self.d.IFACE, self.d.port), None) + sc = ServerConnection((self.d.IFACE, self.d.port)) sc.connect() f = tutils.tflow() f.server_conn = sc @@ -35,7 +35,7 @@ class TestServerConnection: sc.finish() def test_terminate_error(self): - sc = ServerConnection((self.d.IFACE, self.d.port), None) + sc = ServerConnection((self.d.IFACE, self.d.port)) sc.connect() sc.connection = mock.Mock() sc.connection.recv = mock.Mock(return_value=False) diff --git a/test/test_server.py b/test/test_server.py index 6c0829f4..21d01f5a 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -330,17 +330,14 @@ class MasterRedirectRequest(tservers.TestMaster): def handle_request(self, f): request = f.request if request.path == "/p/201": - url = request.get_url(False, f) + url = request.url new = "http://127.0.0.1:%s/p/201" % self.redirect_port - request.set_url(new, f) - request.set_url(new, f) + request.url = new f.live.change_server(("127.0.0.1", self.redirect_port), False) - request.set_url(url, f) + request.url = url tutils.raises("SSL handshake error", f.live.change_server, ("127.0.0.1", self.redirect_port), True) - request.set_url(new, f) - request.set_url(url, f) - request.set_url(new, f) + request.url = new tservers.TestMaster.handle_request(self, f) def handle_response(self, f): |