def testProxyFromArgs(self): self.assertEqual( get_proxy_info("echo.websocket.org", False, proxy_host="localhost"), ("localhost", 0, None)) self.assertEqual( get_proxy_info("echo.websocket.org", False, proxy_host="localhost", proxy_port=3128), ("localhost", 3128, None)) self.assertEqual( get_proxy_info("echo.websocket.org", True, proxy_host="localhost"), ("localhost", 0, None)) self.assertEqual( get_proxy_info("echo.websocket.org", True, proxy_host="localhost", proxy_port=3128), ("localhost", 3128, None)) self.assertEqual( get_proxy_info("echo.websocket.org", False, proxy_host="localhost", proxy_auth=("a", "b")), ("localhost", 0, ("a", "b"))) self.assertEqual( get_proxy_info("echo.websocket.org", False, proxy_host="localhost", proxy_port=3128, proxy_auth=("a", "b")), ("localhost", 3128, ("a", "b"))) self.assertEqual( get_proxy_info("echo.websocket.org", True, proxy_host="localhost", proxy_auth=("a", "b")), ("localhost", 0, ("a", "b"))) self.assertEqual( get_proxy_info("echo.websocket.org", True, proxy_host="localhost", proxy_port=3128, proxy_auth=("a", "b")), ("localhost", 3128, ("a", "b"))) self.assertEqual( get_proxy_info("echo.websocket.org", True, proxy_host="localhost", proxy_port=3128, no_proxy=["example.com"], proxy_auth=("a", "b")), ("localhost", 3128, ("a", "b"))) self.assertEqual( get_proxy_info("echo.websocket.org", True, proxy_host="localhost", proxy_port=3128, no_proxy=["echo.websocket.org"], proxy_auth=("a", "b")), (None, 0, None))
def testProxyFromArgs(self): self.assertEqual(get_proxy_info("echo.websocket.org", False, proxy_host="localhost"), ("localhost", 0, None)) self.assertEqual(get_proxy_info("echo.websocket.org", False, proxy_host="localhost", proxy_port=3128), ("localhost", 3128, None)) self.assertEqual(get_proxy_info("echo.websocket.org", True, proxy_host="localhost"), ("localhost", 0, None)) self.assertEqual(get_proxy_info("echo.websocket.org", True, proxy_host="localhost", proxy_port=3128), ("localhost", 3128, None)) self.assertEqual(get_proxy_info("echo.websocket.org", False, proxy_host="localhost", proxy_auth=("a", "b")), ("localhost", 0, ("a", "b"))) self.assertEqual(get_proxy_info("echo.websocket.org", False, proxy_host="localhost", proxy_port=3128, proxy_auth=("a", "b")), ("localhost", 3128, ("a", "b"))) self.assertEqual(get_proxy_info("echo.websocket.org", True, proxy_host="localhost", proxy_auth=("a", "b")), ("localhost", 0, ("a", "b"))) self.assertEqual(get_proxy_info("echo.websocket.org", True, proxy_host="localhost", proxy_port=3128, proxy_auth=("a", "b")), ("localhost", 3128, ("a", "b"))) self.assertEqual(get_proxy_info("echo.websocket.org", True, proxy_host="localhost", proxy_port=3128, no_proxy=["example.com"], proxy_auth=("a", "b")), ("localhost", 3128, ("a", "b"))) self.assertEqual(get_proxy_info("echo.websocket.org", True, proxy_host="localhost", proxy_port=3128, no_proxy=["echo.websocket.org"], proxy_auth=("a", "b")), (None, 0, None))
def testProxyFromEnv(self): os.environ["http_proxy"] = "http://localhost/" self.assertEqual(get_proxy_info("echo.websocket.org", False), ("localhost", None, None)) os.environ["http_proxy"] = "http://*****:*****@localhost/" self.assertEqual(get_proxy_info("echo.websocket.org", False), ("localhost", None, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost:3128/" self.assertEqual(get_proxy_info("echo.websocket.org", False), ("localhost", 3128, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost/" os.environ["https_proxy"] = "http://*****:*****@localhost2/" self.assertEqual(get_proxy_info("echo.websocket.org", False), ("localhost", None, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost:3128/" os.environ["https_proxy"] = "http://*****:*****@localhost2:3128/" self.assertEqual(get_proxy_info("echo.websocket.org", False), ("localhost", 3128, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost/" os.environ["https_proxy"] = "http://*****:*****@localhost2/" self.assertEqual(get_proxy_info("echo.websocket.org", True), ("localhost2", None, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost:3128/" os.environ["https_proxy"] = "http://*****:*****@localhost2:3128/" self.assertEqual(get_proxy_info("echo.websocket.org", True), ("localhost2", 3128, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost/" os.environ["https_proxy"] = "http://*****:*****@localhost2/" os.environ["no_proxy"] = "example1.com,example2.com" self.assertEqual(get_proxy_info("example.1.com", True), ("localhost2", None, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost:3128/" os.environ["https_proxy"] = "http://*****:*****@localhost2:3128/" os.environ["no_proxy"] = "example1.com,example2.com, echo.websocket.org" self.assertEqual(get_proxy_info("echo.websocket.org", True), (None, 0, None)) os.environ["http_proxy"] = "http://*****:*****@localhost:3128/" os.environ["https_proxy"] = "http://*****:*****@localhost2:3128/" os.environ["no_proxy"] = "127.0.0.0/8, 192.168.0.0/16" self.assertEqual(get_proxy_info("127.0.0.1", False), (None, 0, None)) self.assertEqual(get_proxy_info("192.168.1.1", False), (None, 0, None))
def testProxyFromEnv(self): os.environ["http_proxy"] = "http://localhost/" self.assertEqual(get_proxy_info("echo.websocket.org", False), ("localhost", None, None)) os.environ["http_proxy"] = "http://*****:*****@localhost/" self.assertEqual(get_proxy_info("echo.websocket.org", False), ("localhost", None, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost:3128/" self.assertEqual(get_proxy_info("echo.websocket.org", False), ("localhost", 3128, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost/" os.environ["https_proxy"] = "http://*****:*****@localhost2/" self.assertEqual(get_proxy_info("echo.websocket.org", False), ("localhost", None, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost:3128/" os.environ["https_proxy"] = "http://*****:*****@localhost2:3128/" self.assertEqual(get_proxy_info("echo.websocket.org", False), ("localhost", 3128, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost/" os.environ["https_proxy"] = "http://*****:*****@localhost2/" self.assertEqual(get_proxy_info("echo.websocket.org", True), ("localhost2", None, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost:3128/" os.environ["https_proxy"] = "http://*****:*****@localhost2:3128/" self.assertEqual(get_proxy_info("echo.websocket.org", True), ("localhost2", 3128, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost/" os.environ["https_proxy"] = "http://*****:*****@localhost2/" os.environ["no_proxy"] = "example1.com,example2.com" self.assertEqual(get_proxy_info("example.1.com", True), ("localhost2", None, ("a", "b"))) os.environ["http_proxy"] = "http://*****:*****@localhost:3128/" os.environ["https_proxy"] = "http://*****:*****@localhost2:3128/" os.environ[ "no_proxy"] = "example1.com,example2.com, echo.websocket.org" self.assertEqual(get_proxy_info("echo.websocket.org", True), (None, 0, None)) os.environ["http_proxy"] = "http://*****:*****@localhost:3128/" os.environ["https_proxy"] = "http://*****:*****@localhost2:3128/" os.environ["no_proxy"] = "127.0.0.0/8, 192.168.0.0/16" self.assertEqual(get_proxy_info("127.0.0.1", False), (None, 0, None)) self.assertEqual(get_proxy_info("192.168.1.1", False), (None, 0, None))