def test_callRemotely_badHost(self) : p = ServiceProxy("http://badhost:80") try : p.callRemotely("service") self.fail("Exception expected") except urllib2.URLError as e : self.assertEqual(e.message, "")
def test_callRemotely_withArg(self) : p = ServiceProxy("http://myhost:80") p.callRemotely("service", a="boo") self.assertEqual(self.query.path,'/service') self.assertEqual(self.query.method,'POST') self.assertEqual(self.params,dict(a='boo'))
def test_callRemotely_noArgs(self) : p = ServiceProxy("http://myhost:80") p.callRemotely("service") self.assertEqual(self.query.path,'/service') self.assertEqual(self.query.method,'POST') self.assertEqual(self.query.params,{})
def test_callRemotely_internalError(self) : p = ServiceProxy("http://myhost:80") try : p.callRemotely("service", error="Message") self.fail("Exception expected") except RemoteError as e : self.assertEqual(e.message, "Message")
async def master_socket_handler(loop, master_socket): while True: sock, _ = await loop.sock_accept(master_socket) try: ServiceProxy(sock, service_type, target, loop) except ConnectionRefusedError as e: logger.warning("%s: %s", e, target) sock.close()
def test_callRemotely_internalError(self) : p = ServiceProxy("http://myhost:80") try : p.callRemotely("service", error="Message") self.fail("Exception expected") except urllib2.HTTPError as e : self.assertEqual(e.reason, "Internal Server Error") self.assertEqual(e.read(), "Message") self.assertEqual(e.getcode(), 500)
def test_callRemotely_notFoundError(self) : p = ServiceProxy("http://myhost") try : p.callRemotely("service", notfound="Message") self.fail("Exception expected") except urllib2.HTTPError as e : self.assertEqual(e.reason, "Not found") self.assertEqual(e.read(), "Message") self.assertEqual(e.getcode(), 404)
def test_callRemotely_withIntArgs(self) : p = ServiceProxy("http://myhost:80") p.callRemotely("service", a=1) self.assertEqual(self.query.path,'/service') self.assertEqual(self.params,dict(a=1))
def test_callRemotely_returnsText(self) : p = ServiceProxy("http://myhost:80") result = p.callRemotely("service") self.assertEqual(result, "Hola")
def test_callRemotely_anouncesAsUserAgent(self) : p = ServiceProxy("http://myhost:80") p.callRemotely("service") self.assertEqual(self.query.user_agent, "python-service-proxy/1.0")