def test_endpoint_for_unix(self): from twisted.internet import reactor factory = ClientEndpointFactory(reactor) url_bytes = b'unix://.%2Ftests%2Fnode%2Fhttp.sock/engine.io/?EIO=3&transport=polling' url = BaseUrl.fromBytes(url_bytes) endpoint = factory.endpointForURI(url) self.assertIsInstance(endpoint, t_endpoints.UNIXClientEndpoint) self.assertEqual(endpoint._path.encode('utf_8'), b'./tests/node/http.sock') # pylint: disable=protected-access
def test_endpoint_for_ws(self): from twisted.internet import reactor factory = ClientEndpointFactory(reactor) url_bytes = b'ws://tweets.socket.io/engine.io/?EIO=3&transport=polling' url = BaseUrl.fromBytes(url_bytes) endpoint = factory.endpointForURI(url) self.assertIsInstance(endpoint, t_endpoints.HostnameEndpoint) self.assertEqual(endpoint._host, b'tweets.socket.io') # pylint: disable=protected-access self.assertEqual(endpoint._port, 80) # pylint: disable=protected-access url_bytes = b'ws://tweets.socket.io:12345/engine.io/?EIO=3&transport=polling' url = BaseUrl.fromBytes(url_bytes) endpoint = factory.endpointForURI(url) self.assertIsInstance(endpoint, t_endpoints.HostnameEndpoint) self.assertEqual(endpoint._host, b'tweets.socket.io') # pylint: disable=protected-access self.assertEqual(endpoint._port, 12345) # pylint: disable=protected-access