def test_http_hook(self): @http.register(re.compile("^/thumbsup$")) def httptest(wsgi_env, regex_match, irc_client_instance): irc_client_instance.chanmsg("#test", "Eeey!") return "text/plain", "Success" ircserver = TestIRCServer("Eeey!", ("127.0.0.1", 0)) ircserver.start() ircclient = irc_client.IRC(max_reconnects=1, max_messages=3) import anton anton.config.BACKEND = ("127.0.0.1", ircserver.server_port) ircclient.start() anton.config.HTTP_LISTEN = "127.0.0.1", 0 http_server = http.server(ircclient) http_server.start() result = requests.get("http://127.0.0.1:%s/thumbsup" % http_server.server_port) self.assertTrue(ircserver.message_received) self.assertEqual(ircserver.received[-1], "PRIVMSG #test :Eeey!\r\n") self.assertEqual(result.text, "Success") self.assertEqual(result.headers["Content-type"], "text/plain") ircserver.close() ircclient.stop() http_server.close()
def main(): irc_instance = irc.irc_instance() http_instance = http.server(irc_instance) gevent.spawn(irc.client, irc_instance) # Abuse WSGIServer's serve_forever() implementation as a "daemonization # kit" that handles signals correctly. _log.info("anton listening on %s:%s" % (config.HTTP_LISTEN[0], config.HTTP_LISTEN[1],)) http_instance.serve_forever()
def main(): irc_instance = irc.irc_instance() http_instance = http.server(irc_instance) gevent.spawn(irc.client, irc_instance) # Abuse WSGIServer's serve_forever() implementation as a "daemonization # kit" that handles signals correctly. _log.info("anton listening on %s:%s" % ( config.HTTP_LISTEN[0], config.HTTP_LISTEN[1], )) http_instance.serve_forever()
def main(): irc_instance = IRC( max_reconnects=int(config.IRC_MAX_CONNECTATTEMPTS), max_messages=int(config.IRC_MAX_MESSAGESPERCONNECTION) ) http_instance = http.server(irc_instance) scheduler.setup(irc_instance) irc_instance.start() _log.info("anton listening on %s:%s" % (config.HTTP_LISTEN[0], config.HTTP_LISTEN[1],)) # Run WSGIServer's serve_forever() implementation as a cooperative # event loop consumer. # FIXME: handle signals correctly http_instance.serve_forever()
def test_http_404(self): @http.register(re.compile("^/thumbsdown$")) def httptest(wsgi_env, regex_match, irc_client_instance): return "text/plain", "wat?!" import anton anton.config.HTTP_LISTEN = "127.0.0.1", 0 ircclient = mock.Mock() http_server = http.server(ircclient) http_server.start() result = requests.get("http://127.0.0.1:%s/thumbsup" % http_server.server_port) self.assertEqual(result.status_code, 404) http_server.stop()
def test_http_autocontenttype(self): @http.register(re.compile("^/thumbsup$")) def httptest(wsgi_env, regex_match, irc_client_instance): return "Eeey!" import anton anton.config.HTTP_LISTEN = "127.0.0.1", 0 ircclient = mock.Mock() http_server = http.server(ircclient) http_server.start() result = requests.get("http://127.0.0.1:%s/thumbsup" % http_server.server_port) self.assertEqual(result.text, "Eeey!") self.assertEqual(result.headers["Content-type"], "text/plain") http_server.close()