diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_pathoc.py | 37 | ||||
-rw-r--r-- | test/test_pathod.py | 25 | ||||
-rw-r--r-- | test/tutils.py | 8 |
3 files changed, 32 insertions, 38 deletions
diff --git a/test/test_pathoc.py b/test/test_pathoc.py index 5172d85f..88479b6c 100644 --- a/test/test_pathoc.py +++ b/test/test_pathoc.py @@ -1,6 +1,8 @@ import json import cStringIO -from libpathod import pathoc, test, version, pathod +import re + +from libpathod import pathoc, test, version, pathod, language import tutils @@ -18,7 +20,9 @@ class _TestDaemon: ssl=self.ssl, ssloptions=self.ssloptions, staticdir=tutils.test_data.path("data"), - anchors=[("/anchor/.*", "202")] + anchors=[ + (re.compile("/anchor/.*"), language.parse_response("202")) + ] ) @classmethod @@ -37,9 +41,18 @@ class _TestDaemon: r = c.request("get:/api/info") assert tuple(json.loads(r.content)["version"]) == version.IVERSION - def tval(self, requests, showreq=False, showresp=False, explain=False, - showssl=False, hexdump=False, timeout=None, ignorecodes=None, - ignoretimeout=None): + def tval( + self, + requests, + showreq=False, + showresp=False, + explain=False, + showssl=False, + hexdump=False, + timeout=None, + ignorecodes=None, + ignoretimeout=None + ): c = pathoc.Pathoc(("127.0.0.1", self.d.port), ssl=self.ssl) c.connect() if timeout: @@ -47,7 +60,7 @@ class _TestDaemon: s = cStringIO.StringIO() for i in requests: c.print_request( - i, + language.parse_request(i), showreq = showreq, showresp = showresp, explain = explain, @@ -125,17 +138,14 @@ class TestDaemon(_TestDaemon): assert "HTTP/" in v def test_explain(self): - reqs = [ "get:/p/200:b@100" ] - assert not "b@100" in self.tval(reqs, explain=True) + reqs = ["get:/p/200:b@100"] + assert "b@100" not in self.tval(reqs, explain=True) def test_showreq(self): - reqs = [ "get:/api/info:p0,0", "get:/api/info:p0,0" ] + reqs = ["get:/api/info:p0,0", "get:/api/info:p0,0"] assert self.tval(reqs, showreq=True).count("unprintables escaped") == 2 assert self.tval(reqs, showreq=True, hexdump=True).count("hex dump") == 2 - def test_parse_err(self): - assert "Error parsing" in self.tval(["foo"]) - def test_conn_err(self): assert "Invalid server response" in self.tval(["get:'/p/200:d2'"]) @@ -152,6 +162,3 @@ class TestDaemon(_TestDaemon): "HTTP/1.1 200 OK\r\n" ) c.http_connect(to) - - - diff --git a/test/test_pathod.py b/test/test_pathod.py index 0172678c..158f3bda 100644 --- a/test/test_pathod.py +++ b/test/test_pathod.py @@ -1,28 +1,9 @@ from libpathod import pathod, version -from netlib import tcp, http, certutils +from netlib import tcp, http import tutils class TestPathod: - def test_instantiation(self): - p = pathod.Pathod( - ("127.0.0.1", 0), - anchors = [(".*", "200:da")] - ) - assert p.anchors - tutils.raises( - "invalid regex", - pathod.Pathod, - ("127.0.0.1", 0), - anchors=[("*", "200:da")] - ) - tutils.raises( - "invalid page spec", - pathod.Pathod, - ("127.0.0.1", 0), - anchors=[("foo", "bar")] - ) - def test_logging(self): p = pathod.Pathod(("127.0.0.1", 0)) assert len(p.get_log()) == 0 @@ -39,6 +20,7 @@ class TestPathod: class TestNoWeb(tutils.DaemonTests): noweb = True + def test_noweb(self): assert self.get("200:da").status_code == 200 assert self.getpath("/").status_code == 800 @@ -46,6 +28,7 @@ class TestNoWeb(tutils.DaemonTests): class TestTimeout(tutils.DaemonTests): timeout = 0.01 + def test_noweb(self): # FIXME: Add float values to spec language, reduce test timeout to # increase test performance @@ -55,6 +38,7 @@ class TestTimeout(tutils.DaemonTests): class TestNoApi(tutils.DaemonTests): noapi = True + def test_noapi(self): assert self.getpath("/log").status_code == 404 r = self.getpath("/") @@ -238,4 +222,3 @@ class TestDaemonSSL(CommonTests): r = self.pathoc(r"get:/p/202") assert r.status_code == 202 assert self.d.last_log()["cipher"][1] > 0 - diff --git a/test/tutils.py b/test/tutils.py index 94c1ff9d..5876e5e6 100644 --- a/test/tutils.py +++ b/test/tutils.py @@ -1,10 +1,12 @@ import tempfile import os +import re import shutil from contextlib import contextmanager -from libpathod import utils, test, pathoc, pathod +from libpathod import utils, test, pathoc, pathod, language import requests + class DaemonTests: noweb = False noapi = False @@ -22,7 +24,9 @@ class DaemonTests: so = pathod.SSLOptions(**opts) self.d = test.Daemon( staticdir=test_data.path("data"), - anchors=[("/anchor/.*", "202:da")], + anchors=[ + (re.compile("/anchor/.*"), language.parse_response("202:da")) + ], ssl = self.ssl, ssloptions = so, sizelimit=1*1024*1024, |