aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_app.py24
-rw-r--r--test/test_language_http2.py8
-rw-r--r--test/test_pathoc.py15
-rw-r--r--test/test_pathod.py13
-rw-r--r--test/tutils.py8
5 files changed, 37 insertions, 31 deletions
diff --git a/test/test_app.py b/test/test_app.py
index 4536db8e..4571617f 100644
--- a/test/test_app.py
+++ b/test/test_app.py
@@ -7,7 +7,7 @@ class TestApp(tutils.DaemonTests):
def test_index(self):
r = self.getpath("/")
assert r.status_code == 200
- assert r.content
+ assert r.body
def test_about(self):
r = self.getpath("/about")
@@ -38,48 +38,48 @@ class TestApp(tutils.DaemonTests):
def test_response_preview(self):
r = self.getpath("/response_preview", params=dict(spec="200"))
assert r.status_code == 200
- assert 'Response' in r.content
+ assert 'Response' in r.body
r = self.getpath("/response_preview", params=dict(spec="foo"))
assert r.status_code == 200
- assert 'Error' in r.content
+ assert 'Error' in r.body
r = self.getpath("/response_preview", params=dict(spec="200:b@100m"))
assert r.status_code == 200
- assert "too large" in r.content
+ assert "too large" in r.body
r = self.getpath("/response_preview", params=dict(spec="200:b@5k"))
assert r.status_code == 200
- assert 'Response' in r.content
+ assert 'Response' in r.body
r = self.getpath(
"/response_preview",
params=dict(
spec="200:b<nonexistent"))
assert r.status_code == 200
- assert 'File access denied' in r.content
+ assert 'File access denied' in r.body
r = self.getpath("/response_preview", params=dict(spec="200:b<file"))
assert r.status_code == 200
- assert 'testfile' in r.content
+ assert 'testfile' in r.body
def test_request_preview(self):
r = self.getpath("/request_preview", params=dict(spec="get:/"))
assert r.status_code == 200
- assert 'Request' in r.content
+ assert 'Request' in r.body
r = self.getpath("/request_preview", params=dict(spec="foo"))
assert r.status_code == 200
- assert 'Error' in r.content
+ assert 'Error' in r.body
r = self.getpath("/request_preview", params=dict(spec="get:/:b@100m"))
assert r.status_code == 200
- assert "too large" in r.content
+ assert "too large" in r.body
r = self.getpath("/request_preview", params=dict(spec="get:/:b@5k"))
assert r.status_code == 200
- assert 'Request' in r.content
+ assert 'Request' in r.body
r = self.getpath("/request_preview", params=dict(spec=""))
assert r.status_code == 200
- assert 'empty spec' in r.content
+ assert 'empty spec' in r.body
diff --git a/test/test_language_http2.py b/test/test_language_http2.py
index 3b36c01b..2e941f9a 100644
--- a/test/test_language_http2.py
+++ b/test/test_language_http2.py
@@ -1,9 +1,11 @@
import cStringIO
+import netlib
from netlib import tcp
+from netlib.http import user_agents
+
from libpathod import language
from libpathod.language import http2, base
-import netlib
import tutils
@@ -18,7 +20,7 @@ def parse_response(s):
def default_settings():
return language.Settings(
request_host="foo.com",
- protocol=netlib.http2.HTTP2Protocol(tcp.TCPClient(('localhost', 1234)))
+ protocol=netlib.http.http2.HTTP2Protocol(tcp.TCPClient(('localhost', 1234)))
)
@@ -121,7 +123,7 @@ class TestRequest:
def test_user_agent(self):
r = parse_request('GET:/:r:ua')
assert len(r.headers) == 1
- assert r.headers[0].values(default_settings()) == ("user-agent", netlib.http_uastrings.get_by_shortcut('a')[2])
+ assert r.headers[0].values(default_settings()) == ("user-agent", user_agents.get_by_shortcut('a')[2])
def test_render_with_headers(self):
s = cStringIO.StringIO()
diff --git a/test/test_pathoc.py b/test/test_pathoc.py
index fb8d348a..215f691b 100644
--- a/test/test_pathoc.py
+++ b/test/test_pathoc.py
@@ -4,13 +4,15 @@ import re
import OpenSSL
from mock import Mock
-from netlib import tcp, http, http2, socks
+from netlib import tcp, http, socks
+from netlib.http import http1, http2
+
from libpathod import pathoc, test, version, pathod, language
import tutils
def test_response():
- r = pathoc.Response("1.1", 200, "Message", {}, None, None)
+ r = http.Response("1.1", 200, "Message", {}, None, None)
assert repr(r)
@@ -43,7 +45,7 @@ class _TestDaemon:
)
c.connect()
resp = c.request("get:/api/info")
- assert tuple(json.loads(resp.content)["version"]) == version.IVERSION
+ assert tuple(json.loads(resp.body)["version"]) == version.IVERSION
def tval(
self,
@@ -103,7 +105,7 @@ class TestDaemonSSL(_TestDaemon):
c.connect()
c.request("get:/p/200")
r = c.request("get:/api/log")
- d = json.loads(r.content)
+ d = json.loads(r.body)
assert d["log"][0]["request"]["sni"] == "foobar.com"
def test_showssl(self):
@@ -119,7 +121,7 @@ class TestDaemonSSL(_TestDaemon):
c.connect()
c.request("get:/p/200")
r = c.request("get:/api/log")
- d = json.loads(r.content)
+ d = json.loads(r.body)
assert d["log"][0]["request"]["clientcert"]["keyinfo"]
def test_http2_without_ssl(self):
@@ -270,8 +272,7 @@ class TestDaemonHTTP2(_TestDaemon):
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
)
- # TODO: change if other protocols get implemented
- assert c.protocol is None
+ assert isinstance(c.protocol, http1.HTTP1Protocol)
def test_http2_alpn(self):
c = pathoc.Pathoc(
diff --git a/test/test_pathod.py b/test/test_pathod.py
index 12f7bac0..1f127586 100644
--- a/test/test_pathod.py
+++ b/test/test_pathod.py
@@ -3,7 +3,7 @@ import cStringIO
import OpenSSL
from libpathod import pathod, version
-from netlib import tcp, http, http2
+from netlib import tcp, http
import tutils
@@ -51,7 +51,7 @@ class TestNoApi(tutils.DaemonTests):
assert self.getpath("/log").status_code == 404
r = self.getpath("/")
assert r.status_code == 200
- assert not "Log" in r.content
+ assert not "Log" in r.body
class TestNotAfterConnect(tutils.DaemonTests):
@@ -119,7 +119,7 @@ class TestNocraft(tutils.DaemonTests):
def test_nocraft(self):
r = self.get(r"200:b'\xf0'")
assert r.status_code == 800
- assert "Crafting disabled" in r.content
+ assert "Crafting disabled" in r.body
class CommonTests(tutils.DaemonTests):
@@ -152,7 +152,7 @@ class CommonTests(tutils.DaemonTests):
def test_disconnect(self):
rsp = self.get("202:b@100k:d200")
- assert len(rsp.content) < 200
+ assert len(rsp.body) < 200
def test_parserr(self):
rsp = self.get("400:msg,b:")
@@ -161,7 +161,7 @@ class CommonTests(tutils.DaemonTests):
def test_static(self):
rsp = self.get("200:b<file")
assert rsp.status_code == 200
- assert rsp.content.strip() == "testfile"
+ assert rsp.body.strip() == "testfile"
def test_anchor(self):
rsp = self.getpath("anchor/foo")
@@ -201,7 +201,7 @@ class CommonTests(tutils.DaemonTests):
def test_source_access_denied(self):
rsp = self.get("200:b</foo")
assert rsp.status_code == 800
- assert "File access denied" in rsp.content
+ assert "File access denied" in rsp.body
def test_proxy(self):
r, _ = self.pathoc([r"get:'http://foo.com/p/202':da"])
@@ -284,5 +284,4 @@ class TestHTTP2(tutils.DaemonTests):
def test_http2(self):
r, _ = self.pathoc(["GET:/"], ssl=True, use_http2=True)
- print(r)
assert r[0].status_code == "800"
diff --git a/test/tutils.py b/test/tutils.py
index f7fcc312..a728e852 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -62,7 +62,7 @@ class DaemonTests(object):
def getpath(self, path, params=None):
scheme = "https" if self.ssl else "http"
- return requests.get(
+ resp = requests.get(
"%s://localhost:%s/%s" % (
scheme,
self.d.port,
@@ -71,9 +71,13 @@ class DaemonTests(object):
verify=False,
params=params
)
+ resp.body = resp.content
+ return resp
def get(self, spec):
- return requests.get(self.d.p(spec), verify=False)
+ resp = requests.get(self.d.p(spec), verify=False)
+ resp.body = resp.content
+ return resp
def pathoc(
self,