def test_h2l_heroku_push_to_amqp_success(self): """ Message is forwarded to amqp without errors :return: """ consumer = AMQPConnection() yield consumer.connect(self.io_loop) self.futureMsg = Future() yield consumer.subscribe("heroku.v1.integration.toto", "heroku_queue", self.on_message) payload = b"123 <40>1 2017-06-21T17:02:55+00:00 host ponzi web.1 - " \ b"Lorem ipsum dolor sit amet, consecteteur adipiscing elit b'quis' b'ad'.\n" response = self.http_client.fetch(self.get_url('/heroku/v1/integration/toto'), method='POST', body=payload) res = yield self.futureMsg json_res = json.loads(res.decode('utf-8')) self.assertEqual(json_res['app'], 'toto') self.assertEqual(json_res['env'], 'integration') self.assertEqual(json_res['type'], 'heroku') self.assertEqual(json_res['http_content_length'], 122) self.assertEqual(json_res['parser_ver'], 'v1') self.assertEqual(json_res['message'], '<40>1 2017-06-21T17:02:55+00:00 host ponzi web.1' ' - Lorem ipsum dolor sit amet, consecteteur' ' adipiscing elit b\'quis\' b\'ad\'.') value = yield response self.assertEqual(value.code, 200) self.assertEqual(len(value.body), 0) yield consumer.disconnect()
def test_cloudtrail_push_to_amqp_success_gzip(self): consumer = AMQPConnection() yield consumer.connect(self.io_loop) self.futureMsg = Future() yield consumer.subscribe("cloudtrail.v1.integration.toto", "cloudtrail_integration_queue", self.on_message) payload = gzip.compress( json.dumps({ 'Records': [{ 'message': 'this is a log message' }] }).encode()) request = tornado.httpclient.HTTPRequest( self.get_url('/cloudtrail/v1/integration/toto'), method='POST', body=payload, use_gzip=True) response = self.http_client.fetch(request) res = yield self.futureMsg self.assertEqual(res, b'{"message": "this is a log message"}') value = yield response self.assertEqual(value.code, 200) self.assertEqual(len(value.body), 0) yield consumer.disconnect()
def test_delivery_confirmation_ack(self): con = AMQPConnection() frame = Mock() frame.method = Mock() frame.method.NAME = 'toto.ack' con.statsdClient = Mock() con.statsdClient.incr = Mock() con._on_delivery_confirmation(frame) con.statsdClient.incr.assert_called_with('amqp.output_delivered', count=1)
def connect_to_amqp(): amqp_con = AMQPConnection() res = yield amqp_con.connect(IOLoop.current()) if not res: sys.exit(1) yield amqp_con.declare_queue("mobile_integration_queue") yield amqp_con.declare_queue("mobile_production_queue") yield amqp_con.declare_queue("heroku_integration_queue") yield amqp_con.declare_queue("heroku_production_queue") yield amqp_con.declare_queue("cloudtrail_integration_queue") yield amqp_con.declare_queue("cloudtrail_production_queue") return amqp_con
def test_pubsub(self): routing_key = 'toto' AmqpConfig.port = 5672 sub = AMQPConnection(AmqpConfig) yield sub.connect(self.io_loop) self.futureMsg = Future() yield sub.subscribe(routing_key, "pubsub", self.handle_msg) pub = AMQPConnection() yield pub.connect(self.io_loop) msg_sent = {'toto': 'tutu'} yield pub.publish(routing_key, json.dumps(msg_sent)) msg_rcv = yield self.futureMsg self.assertEqual(msg_rcv, msg_sent) yield sub.disconnect() yield pub.disconnect()
def test_cloudtrail_push_to_amqp_success(self): consumer = AMQPConnection() yield consumer.connect(self.io_loop) self.futureMsg = Future() yield consumer.subscribe("cloudtrail.v1.integration.toto", "cloudtrail_integration_queue", self.on_message) payload = b'{"Records": [{"test": "plop"}]}' response = self.http_client.fetch( self.get_url('/cloudtrail/v1/integration/toto'), method='POST', body=payload, use_gzip=False) res = yield self.futureMsg self.assertEqual(res, b'{"test": "plop"}') value = yield response self.assertEqual(value.code, 200) self.assertEqual(len(value.body), 0) yield consumer.disconnect()
def test_mobile_push_to_amqp_success(self): consumer = AMQPConnection() yield consumer.connect(self.io_loop) self.futureMsg = Future() yield consumer.subscribe("mobile.v1.integration.toto", "mobile_queue", self.on_message) payload = b"123 <40>1 2017-06-21T17:02:55+00:00 host ponzi web.1 - " \ b"Lorem ipsum dolor sit amet, consecteteur adipiscing elit b'quis' b'ad'.\n" response = self.http_client.fetch( self.get_url('/mobile/v1/integration/toto'), method='POST', body=payload, use_gzip=False ) res = yield self.futureMsg self.assertEqual(res, b"123 <40>1 2017-06-21T17:02:55+00:00 host ponzi web.1 - " b"Lorem ipsum dolor sit amet, consecteteur adipiscing elit b'quis' b'ad'.\n") value = yield response self.assertEqual(value.code, 200) self.assertEqual(len(value.body), 0) yield consumer.disconnect()
def connect_to_amqp(): amqp_con = AMQPConnection() yield amqp_con.connect(IOLoop.current()) return amqp_con
def test_connect_failure(self): AmqpConfig.port = 1432 sub = AMQPConnection(AmqpConfig) res = yield sub.connect(self.io_loop) self.assertFalse(res) yield sub.disconnect()
def test_connect(self): sub = AMQPConnection() res = yield sub.connect(self.io_loop) self.assertTrue(res) yield sub.disconnect()