def setup(self, transporter_args): send_queue_suffix = transporter_args.get("amqp_send_queue_suffix", "-S") recv_queue_suffix = transporter_args.get("amqp_recv_queue_suffix", "-T") suffix_map = {transporter.DIR_SEND: send_queue_suffix, transporter.DIR_RECV: recv_queue_suffix} suffix = suffix_map.get(transporter_args["direction"], "") if "amqp_hapi_queue" not in transporter_args: transporter_args["amqp_hapi_queue"] = transporter_args["amqp_queue"] transporter_args["amqp_queue"] = \ transporter_args["amqp_hapi_queue"] + suffix RabbitMQConnector.setup(self, transporter_args)
def test__publish_with_exception(self): conn = RabbitMQConnector() testutils.set_priv_attr(conn, "__publish_raw", None) target_func = testutils.get_priv_attr(conn, "__publish") with self.assertRaises(hap.Signal) as cm: target_func("msg") self.assertTrue(cm.exception.critical)
def test_run_receive_loop(self): class Receiver(): def __call__(self, channel, msg): self.msg = msg channel.stop_consuming() TEST_BODY = "FOO" self.__delete_test_queue() conn = RabbitMQConnector() conn.setup(self.__get_default_transporter_args()) receiver = Receiver() conn.set_receiver(receiver) self.__publish(TEST_BODY) conn.run_receive_loop() self.assertEquals(receiver.msg, TEST_BODY)
def test__setup_ssl(self): conn = RabbitMQConnector() target_func = testutils.returnPrivObj(conn, "__setup_ssl", "RabbitMQConnector") conn_args = {} transporter_args = self.__get_default_transporter_args() target_func(conn_args, transporter_args) self.assertNotIn("ssl", conn_args) self.assertNotIn("ssl_options", conn_args) transporter_args["amqp_ssl_key"] = "/foo/key" transporter_args["amqp_ssl_cert"] = "/foo/cert" transporter_args["amqp_ssl_ca"] = "/kamo/ca" conn_args = {} target_func(conn_args, transporter_args) self.assertTrue(conn_args["ssl"]) ssl_options = conn_args["ssl_options"] self.assertEquals(ssl_options["keyfile"], "/foo/key") self.assertEquals(ssl_options["certfile"], "/foo/cert") self.assertEquals(ssl_options["ca_certs"], "/kamo/ca")
def __connect(self): conn = RabbitMQConnector() conn.setup(self.__get_default_transporter_args()) return conn
def test_run_receive_loop_without_connect(self): conn = RabbitMQConnector() self.assertRaises(AssertionError, conn.run_receive_loop)
def test_setup(self): conn = RabbitMQConnector() conn.setup(self.__get_default_transporter_args())