diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_server.py | 16 | ||||
-rw-r--r-- | test/tutils.py | 77 |
2 files changed, 56 insertions, 37 deletions
diff --git a/test/test_server.py b/test/test_server.py index 296333d8..e54d3559 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -11,28 +11,32 @@ import tutils for a 200 response. """ -class Sanity(tutils.ProxTest): +class SanityMixin: def test_http(self): assert self.pathod("304").status_code == 304 assert self.log() def test_large(self): - assert len(self.pathod("200:b@500k").content) == 1024*500 + assert len(self.pathod("200:b@50k").content) == 1024*50 -class TestHTTP(Sanity): +class TestHTTP(tutils.HTTPProxTest, SanityMixin): pass -class TestHTTPS(Sanity): +class TestHTTPS(tutils.HTTPProxTest, SanityMixin): ssl = True -class TestReverse(Sanity): +class TestReverse(tutils.ReverseProxTest, SanityMixin): reverse = True -class TestProxy(tutils.ProxTest): +class _TestTransparent(): + transparent = True + + +class TestProxy(tutils.HTTPProxTest): def test_http(self): f = self.pathod("304") assert f.status_code == 304 diff --git a/test/tutils.py b/test/tutils.py index 2fdf51a8..2556a57b 100644 --- a/test/tutils.py +++ b/test/tutils.py @@ -83,24 +83,15 @@ class ServerThread(threading.Thread): self.server.shutdown() -class ProxTest: - ssl = None - reverse = False +class ProxTestBase: @classmethod def setupAll(cls): cls.tqueue = Queue.Queue() cls.server = libpathod.test.Daemon(ssl=cls.ssl) - if cls.reverse: - reverse_proxy = ( - "https" if cls.ssl else "http", - "127.0.0.1", - cls.server.port - ) - else: - reverse_proxy = None + pconf = cls.get_proxy_config() config = proxy.ProxyConfig( certfile=test_data.path("data/testkey.pem"), - reverse_proxy = reverse_proxy + **pconf ) cls.proxy = ProxyThread(cls.tqueue, config) cls.proxy.start() @@ -113,25 +104,6 @@ class ProxTest: def setUp(self): self.proxy.tmaster.clear() - def pathod(self, spec): - """ - Constructs a pathod request, with the appropriate base and proxy. - """ - if self.reverse: - r = hurl.get( - "http://127.0.0.1:%s"%self.proxy.port + "/p/" + spec, - validate_cert=False, - #debug=hurl.utils.stdout_debug - ) - return r - else: - return hurl.get( - self.urlbase + "/p/" + spec, - proxy=self.proxies, - validate_cert=False, - #debug=hurl.utils.stdout_debug - ) - @property def scheme(self): return "https" if self.ssl else "http" @@ -157,6 +129,49 @@ class ProxTest: return pthread.tmaster.log +class HTTPProxTest(ProxTestBase): + ssl = None + @classmethod + def get_proxy_config(cls): + return dict() + + def pathod(self, spec): + """ + Constructs a pathod request, with the appropriate base and proxy. + """ + return hurl.get( + self.urlbase + "/p/" + spec, + proxy=self.proxies, + validate_cert=False, + #debug=hurl.utils.stdout_debug + ) + + +class ReverseProxTest(ProxTestBase): + ssl = None + @classmethod + def get_proxy_config(cls): + return dict( + reverse_proxy = ( + "https" if cls.ssl else "http", + "127.0.0.1", + cls.server.port + ) + ) + + def pathod(self, spec): + """ + Constructs a pathod request, with the appropriate base and proxy. + """ + r = hurl.get( + "http://127.0.0.1:%s"%self.proxy.port + "/p/" + spec, + validate_cert=False, + #debug=hurl.utils.stdout_debug + ) + return r + + + @contextmanager def tmpdir(*args, **kwargs): orig_workdir = os.getcwd() |