コード例 #1
0
    def test_setup_exchange(self, mock_pika):
        """Function:  test_setup_exchange

        Description:  Test setup_exchange method.

        Arguments:

        """

        mock_pika.PlainCredentials.return_value = "PlainCredentials"
        mock_pika.ConnectionParameters.return_value = "ConnectionParameters"
        rmq = rabbitmq_class.RabbitMQPub(self.name, "xxxxx")
        rmq.channel = SetupExchange()

        self.assertFalse(rmq.setup_exchange())
コード例 #2
0
    def test_bind_queue(self, mock_pika):
        """Function:  test_bind_queue

        Description:  Test bind_queue method.

        Arguments:

        """

        mock_pika.PlainCredentials.return_value = "PlainCredentials"
        mock_pika.ConnectionParameters.return_value = "ConnectionParameters"
        rmq = rabbitmq_class.RabbitMQPub(self.name, "xxxxx")
        rmq.channel = BindQueue()

        self.assertFalse(rmq.bind_queue())
コード例 #3
0
    def test_close_channel(self, mock_pika):
        """Function:  test_close_channel

        Description:  Test close_channel method.

        Arguments:

        """

        mock_pika.PlainCredentials.return_value = "PlainCredentials"
        mock_pika.ConnectionParameters.return_value = "ConnectionParameters"
        rmq = rabbitmq_class.RabbitMQPub(self.name, "xxxxx")
        rmq.channel = CheckConfirm()

        self.assertFalse(rmq.check_confirm())
コード例 #4
0
    def test_open_channel(self, mock_pika):
        """Function:  test_open_channel

        Description:  Test open_channel method.

        Arguments:

        """

        mock_pika.PlainCredentials.return_value = "PlainCredentials"
        mock_pika.ConnectionParameters.return_value = "ConnectionParameters"
        rmq = rabbitmq_class.RabbitMQPub(self.name, "xxxxx")
        rmq.connection = OpenChannel()
        rmq.open_channel()

        self.assertEqual(rmq.channel, True)
コード例 #5
0
    def test_clear_queue(self, mock_pika):
        """Function:  test_clear_queue

        Description:  Test clear_queue method.

        Arguments:

        """

        mock_pika.PlainCredentials.return_value = "PlainCredentials"
        mock_pika.ConnectionParameters.return_value = "ConnectionParameters"
        mock_pika.BasicProperties.return_value = True
        rmq = rabbitmq_class.RabbitMQPub(self.name, "xxxxx")
        rmq.channel = ClearQueue()

        self.assertFalse(rmq.clear_queue())
コード例 #6
0
    def test_fail_connect(self, mock_pika, mock_connect):

        """Function:  test_fail_connect

        Description:  Test with failure to connect.

        Arguments:

        """

        mock_pika.PlainCredentials.return_value = "PlainCredentials"
        mock_pika.ConnectionParameters.return_value = "ConnectionParameters"
        mock_connect.return_value = (False, "Failed to connect")
        rmq = rabbitmq_class.RabbitMQPub(self.name, "xxxxx")

        self.assertEqual(rmq.create_connection(), (False, "Failed to connect"))
コード例 #7
0
    def test_publish_msg(self, mock_pika):
        """Function:  test_publish_msg

        Description:  Test publish_msg method.

        Arguments:

        """

        mock_pika.PlainCredentials.return_value = "PlainCredentials"
        mock_pika.ConnectionParameters.return_value = "ConnectionParameters"
        mock_pika.BasicProperties.return_value = True
        rmq = rabbitmq_class.RabbitMQPub(self.name, "xxxxx")
        rmq.channel = PublishMsg()

        self.assertTrue(rmq.publish_msg(self.body))
コード例 #8
0
    def test_drop_connection(self, mock_pika, mock_close, mock_channel):

        """Function:  test_drop_connection

        Description:  Test drop_connection method.

        Arguments:

        """

        mock_pika.PlainCredentials.return_value = "PlainCredentials"
        mock_pika.ConnectionParameters.return_value = "ConnectionParameters"
        mock_close.return_value = True
        mock_channel.return_value = True
        rmq = rabbitmq_class.RabbitMQPub(self.name, "xxxxx")

        self.assertFalse(rmq.drop_connection())
コード例 #9
0
    def test_default(self, mock_pika):

        """Function:  test_default

        Description:  Test __init__ method with default arguments.

        Arguments:

        """

        mock_pika.PlainCredentials.return_value = "PlainCredentials"
        mock_pika.ConnectionParameters.return_value = "ConnectionParameters"
        rmq = rabbitmq_class.RabbitMQPub(self.name, "xxxxx")

        self.assertEqual((rmq.name, rmq.host, rmq.port, rmq.exchange,
                          rmq.exchange_type, rmq.queue_name, rmq.routing_key,
                          rmq.x_durable, rmq.q_durable, rmq.auto_delete),
                         (self.name, "localhost", 5672, "", "direct", "", "",
                          True, True, False))
コード例 #10
0
    def test_setup_queue(self, mock_pika, mock_setup, mock_create, mock_bind,
                         mock_check):
        """Function:  test_setup_queue

        Description:  Test setup_queue method.

        Arguments:

        """

        mock_pika.PlainCredentials.return_value = "PlainCredentials"
        mock_pika.ConnectionParameters.return_value = "ConnectionParameters"
        mock_setup.return_value = True
        mock_create.return_value = True
        mock_bind.return_value = True
        mock_check.return_value = True
        rmq = rabbitmq_class.RabbitMQPub(self.name, "xxxxx")

        self.assertFalse(rmq.setup_queue())
コード例 #11
0
    def test_channel_is_closed(self, mock_pika, mock_connect, mock_channel):

        """Function:  test_channel_is_closed

        Description:  Test with channel is closed.

        Arguments:

        """

        mock_pika.PlainCredentials.return_value = "PlainCredentials"
        mock_pika.ConnectionParameters.return_value = "ConnectionParameters"
        mock_connect.return_value = (True, None)
        mock_channel.return_value = True
        rmq = rabbitmq_class.RabbitMQPub(self.name, "xxxxx")
        rmq.channel = CreateConnection()
        rmq.channel.is_open = False

        self.assertEqual(rmq.create_connection(),
                         (False, "Error:  Unable to open channel."))
コード例 #12
0
    def test_channel_is_open(self, mock_pika, mock_connect, mock_channel,
                             mock_setup):

        """Function:  test_channel_is_open

        Description:  Test with channel is open.

        Arguments:

        """

        mock_pika.PlainCredentials.return_value = "PlainCredentials"
        mock_pika.ConnectionParameters.return_value = "ConnectionParameters"
        mock_connect.return_value = (True, None)
        mock_channel.return_value = True
        mock_setup.return_value = True
        rmq = rabbitmq_class.RabbitMQPub(self.name, "xxxxx")
        rmq.channel = CreateConnection()

        self.assertEqual(rmq.create_connection(), (True, None))
コード例 #13
0
    def test_with_data(self, mock_pika):

        """Function:  test_with_data

        Description:  Test __init__ method with all arguments.

        Arguments:

        """

        mock_pika.PlainCredentials.return_value = "PlainCredentials"
        mock_pika.ConnectionParameters.return_value = "ConnectionParameters"
        rmq = rabbitmq_class.RabbitMQPub(
            self.name, "xxxxx", self.host, self.port,
            exchange_name=self.exchange_name, queue_name=self.queue_name,
            routing_key=self.routing_key, auto_delete=self.auto_delete)

        self.assertEqual((rmq.name, rmq.host, rmq.port, rmq.exchange,
                          rmq.exchange_type, rmq.queue_name, rmq.routing_key,
                          rmq.x_durable, rmq.q_durable, rmq.auto_delete),
                         (self.name, self.host, 5555, self.exchange_name,
                          "direct", self.queue_name, self.routing_key,
                          True, True, self.auto_delete))