diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-06-02 19:32:50 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-06-02 19:36:02 +1200 |
commit | d8c52964c75afae9a7e5cbc4470159dc09f08810 (patch) | |
tree | e730090178f1b915ea590ae9b81dc8ca98a62ceb | |
parent | a7522d9308a9592b0c79709f3d04cdd816ee1a57 (diff) | |
download | mitmproxy-d8c52964c75afae9a7e5cbc4470159dc09f08810.tar.gz mitmproxy-d8c52964c75afae9a7e5cbc4470159dc09f08810.tar.bz2 mitmproxy-d8c52964c75afae9a7e5cbc4470159dc09f08810.zip |
Reimplement test retrievals on pathoc and ditch requests
Requests uses urllib3, which has a connection pool that's not easy to disable
(https://github.com/shazow/urllib3/issues/383).
-rw-r--r-- | test/pathod/test_app.py | 4 | ||||
-rw-r--r-- | test/pathod/test_pathod.py | 9 | ||||
-rw-r--r-- | test/pathod/tutils.py | 25 |
3 files changed, 27 insertions, 11 deletions
diff --git a/test/pathod/test_app.py b/test/pathod/test_app.py index 7f691485..fbaa773c 100644 --- a/test/pathod/test_app.py +++ b/test/pathod/test_app.py @@ -11,11 +11,11 @@ class TestApp(tutils.DaemonTests): def test_about(self): r = self.getpath("/about") - assert r.ok + assert r.status_code == 200 def test_download(self): r = self.getpath("/download") - assert r.ok + assert r.status_code == 200 def test_docs(self): assert self.getpath("/docs/pathod").status_code == 200 diff --git a/test/pathod/test_pathod.py b/test/pathod/test_pathod.py index 0646d011..ec9c169f 100644 --- a/test/pathod/test_pathod.py +++ b/test/pathod/test_pathod.py @@ -6,10 +6,6 @@ from netlib.exceptions import HttpException, TlsException import tutils -import requests.packages.urllib3 -requests.packages.urllib3.disable_warnings() - - class TestPathod(object): def test_logging(self): @@ -150,8 +146,7 @@ class CommonTests(tutils.DaemonTests): assert len(self.d.log()) == 0 def test_disconnect(self): - rsp = self.get("202:b@100k:d200") - assert len(rsp.content) < 200 + tutils.raises("unexpected eof", self.get, "202:b@100k:d200") def test_parserr(self): rsp = self.get("400:msg,b:") @@ -163,7 +158,7 @@ class CommonTests(tutils.DaemonTests): assert rsp.content.strip() == "testfile" def test_anchor(self): - rsp = self.getpath("anchor/foo") + rsp = self.getpath("/anchor/foo") assert rsp.status_code == 202 def test_invalid_first_line(self): diff --git a/test/pathod/tutils.py b/test/pathod/tutils.py index f7bb22e5..a99a2fd3 100644 --- a/test/pathod/tutils.py +++ b/test/pathod/tutils.py @@ -3,6 +3,7 @@ import re import shutil import requests from six.moves import cStringIO as StringIO +import urllib from netlib import tcp from netlib import utils @@ -66,7 +67,7 @@ class DaemonTests(object): if not (self.noweb or self.noapi): self.d.clear_log() - def getpath(self, path, params=None): + def _getpath(self, path, params=None): scheme = "https" if self.ssl else "http" resp = requests.get( "%s://localhost:%s/%s" % ( @@ -79,8 +80,28 @@ class DaemonTests(object): ) return resp + def getpath(self, path, params=None): + logfp = StringIO() + c = pathoc.Pathoc( + ("localhost", self.d.port), + ssl=self.ssl, + fp=logfp, + ) + c.connect() + if params: + path = path + "?" + urllib.urlencode(params) + resp = c.request("get:%s" % path) + return resp + def get(self, spec): - resp = requests.get(self.d.p(spec), verify=False) + logfp = StringIO() + c = pathoc.Pathoc( + ("localhost", self.d.port), + ssl=self.ssl, + fp=logfp, + ) + c.connect() + resp = c.request("get:/p/%s" % urllib.quote(spec).encode("string_escape")) return resp def pathoc( |