def test_web_agent_error(self): reactor = Mock() cfg = Mock() tor = Tor(reactor, cfg) with self.assertRaises(ValueError) as ctx: agent = tor.web_agent(pool=self.pool, _socks_endpoint=object()) yield agent.request('GET', b'meejah.ca') self.assertTrue("'_socks_endpoint' should be" in str(ctx.exception))
def test_web_agent_deferred(self): socks_d = defer.succeed("9151") reactor = Mock() cfg = Mock() tor = Tor(reactor, cfg) agent = tor.web_agent(pool=self.pool, _socks_endpoint=socks_d) resp = yield agent.request('GET', b'meejah.ca') self.assertEqual(self.expected_response, resp)
def test_web_agent_endpoint(self): socks = Mock() directlyProvides(socks, IStreamClientEndpoint) reactor = Mock() cfg = Mock() tor = Tor(reactor, cfg) agent = tor.web_agent(pool=self.pool, _socks_endpoint=socks) resp = yield agent.request('GET', b'meejah.ca') self.assertEqual(self.expected_response, resp)
def test_web_agent_defaults(self): reactor = Mock() cfg = Mock() cfg.create_socks_endpoint = Mock(return_value=defer.succeed("9050")) tor = Tor(reactor, cfg) try: agent = tor.web_agent(pool=self.pool) except ImportError as e: if 'IAgentEndpointFactory' in str(e): print("Skipping; appears we don't have web support") return resp = yield agent.request('GET', b'meejah.ca') self.assertEqual(self.expected_response, resp)