aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_proxy.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2013-02-24 22:24:21 +1300
committerAldo Cortesi <aldo@nullcube.com>2013-02-24 22:24:21 +1300
commit02578151410fff4b3c018303290e2f843e244a89 (patch)
tree3f76702fd3fa36f5cbda7679e95617e077926d37 /test/test_proxy.py
parent705559d65e5dc5883395efb85bacbf1459eb243c (diff)
downloadmitmproxy-02578151410fff4b3c018303290e2f843e244a89.tar.gz
mitmproxy-02578151410fff4b3c018303290e2f843e244a89.tar.bz2
mitmproxy-02578151410fff4b3c018303290e2f843e244a89.zip
Significantly simplify server connection handling, and test.
Diffstat (limited to 'test/test_proxy.py')
-rw-r--r--test/test_proxy.py35
1 files changed, 4 insertions, 31 deletions
diff --git a/test/test_proxy.py b/test/test_proxy.py
index b575a1d0..3995b393 100644
--- a/test/test_proxy.py
+++ b/test/test_proxy.py
@@ -39,8 +39,8 @@ class TestServerConnection:
self.d.shutdown()
def test_simple(self):
- sc = proxy.ServerConnection(proxy.ProxyConfig(), self.d.IFACE, self.d.port)
- sc.connect("http", "host.com")
+ sc = proxy.ServerConnection(proxy.ProxyConfig(), "http", self.d.IFACE, self.d.port, "host.com")
+ sc.connect()
r = tutils.treq()
r.path = "/p/200:da"
sc.send(r)
@@ -53,36 +53,9 @@ class TestServerConnection:
sc.terminate()
def test_terminate_error(self):
- sc = proxy.ServerConnection(proxy.ProxyConfig(), self.d.IFACE, self.d.port)
- sc.connect("http", "host.com")
+ sc = proxy.ServerConnection(proxy.ProxyConfig(), "http", self.d.IFACE, self.d.port, "host.com")
+ sc.connect()
sc.connection = mock.Mock()
sc.connection.close = mock.Mock(side_effect=IOError)
sc.terminate()
-
-
-def _dummysc(config, host, port):
- return mock.MagicMock(config=config, host=host, port=port)
-
-
-def _errsc(config, host, port):
- m = mock.MagicMock(config=config, host=host, port=port)
- m.connect = mock.MagicMock(side_effect=tcp.NetLibError())
- return m
-
-
-class TestServerConnectionPool:
- @mock.patch("libmproxy.proxy.ServerConnection", _dummysc)
- def test_pooling(self):
- p = proxy.ServerConnectionPool(proxy.ProxyConfig())
- c = p.get_connection("http", "localhost", 80, "localhost")
- c2 = p.get_connection("http", "localhost", 80, "localhost")
- assert c is c2
- c3 = p.get_connection("http", "foo", 80, "localhost")
- assert not c is c3
-
- @mock.patch("libmproxy.proxy.ServerConnection", _errsc)
- def test_connection_error(self):
- p = proxy.ServerConnectionPool(proxy.ProxyConfig())
- tutils.raises("502", p.get_connection, "http", "localhost", 80, "localhost")
-