Ejemplo n.º 1
0
    def test_send_notification_sends_to_slack_and_telegram_when_options_are_set(self):
        rmqa = rabbitmqalert.RabbitMQAlert()
        options = self.construct_options()
        optionsresolver.OptionsResover.setup_options = mock.MagicMock(return_value=options)

        rabbitmqalert.smtplib = mock.MagicMock()
        rabbitmqalert.urllib2 = mock.MagicMock()
        rmqa.send_notification(options, "")

        rabbitmqalert.urllib2.urlopen.assert_called()
Ejemplo n.º 2
0
    def test_send_notification_not_call_login_when_email_password_not_set(self):
        rmqa = rabbitmqalert.RabbitMQAlert()
        options = self.construct_options()
        optionsresolver.OptionsResover.setup_options = mock.MagicMock(return_value=options)

        rabbitmqalert.smtplib = mock.MagicMock()
        rabbitmqalert.urllib2 = mock.MagicMock()
        rmqa.send_notification(options, "")

        rabbitmqalert.smtplib.SMTP().login.assert_not_called()
Ejemplo n.º 3
0
    def test_send_notification_sends_email_when_email_to_is_set(self):
        rmqa = rabbitmqalert.RabbitMQAlert()
        options = self.construct_options()
        optionsresolver.OptionsResover.setup_options = mock.MagicMock(return_value=options)

        rabbitmqalert.smtplib = mock.MagicMock()
        rabbitmqalert.urllib2 = mock.MagicMock()
        rmqa.send_notification(options, "")

        rabbitmqalert.smtplib.SMTP().sendmail.assert_called_once()
Ejemplo n.º 4
0
    def test_check_connection_conditions_open_connections_not_send_notification_when_exceeding_option(self):
        rmqa = rabbitmqalert.RabbitMQAlert()
        response = self.construct_response_connection()
        rmqa.send_request = mock.MagicMock(return_value=response)

        options = self.construct_options()
        optionsresolver.OptionsResover.setup_options = mock.MagicMock(return_value=options)

        rmqa.send_notification = mock.MagicMock()
        rmqa.check_connection_conditions(options)

        rmqa.send_notification.assert_not_called()
Ejemplo n.º 5
0
    def test_send_notification_not_send_to_telegram_when_any_option_not_set(self):
        rmqa = rabbitmqalert.RabbitMQAlert()
        options = self.construct_options()
        options["telegram_bot_id"] = None
        optionsresolver.OptionsResover.setup_options = mock.MagicMock(return_value=options)

        rabbitmqalert.smtplib = mock.MagicMock()
        rabbitmqalert.urllib2 = mock.MagicMock()
        rmqa.send_notification(options, "")

        # Assure only slack is called
        rabbitmqalert.urllib2.urlopen.assert_called_once()
Ejemplo n.º 6
0
    def test_check_queue_conditions_messages_unacknowledged_send_notification_when_exceeding_option(self):
        rmqa = rabbitmqalert.RabbitMQAlert()
        response = self.construct_response_queue()
        response["messages_unacknowledged"] = 2
        rmqa.send_request = mock.MagicMock(return_value=response)

        options = self.construct_options()
        optionsresolver.OptionsResover.setup_options = mock.MagicMock(return_value=options)

        rmqa.send_notification = mock.MagicMock()
        rmqa.check_queue_conditions(options)

        rmqa.send_notification.assert_called_once()
Ejemplo n.º 7
0
    def test_check_node_conditions_send_notification_when_node_memory_exceeding_option(self):
        rmqa = rabbitmqalert.RabbitMQAlert()
        response = self.construct_response_node()
        response[0]["mem_used"] = 2000000
        rmqa.send_request = mock.MagicMock(return_value=response)

        options = self.construct_options()
        optionsresolver.OptionsResover.setup_options = mock.MagicMock(return_value=options)

        rmqa.send_notification = mock.MagicMock()
        rmqa.check_node_conditions(options)

        rmqa.send_notification.assert_called_once()
Ejemplo n.º 8
0
    def test_check_connection_conditions_open_connections_send_notification_when_beneath_option(self):
        rmqa = rabbitmqalert.RabbitMQAlert()
        response = self.construct_response_connection()
        response.pop("connection_foo")
        response.pop("connection_bar")
        rmqa.send_request = mock.MagicMock(return_value=response)

        options = self.construct_options()
        optionsresolver.OptionsResover.setup_options = mock.MagicMock(return_value=options)

        rmqa.send_notification = mock.MagicMock()
        rmqa.check_connection_conditions(options)

        rmqa.send_notification.assert_called_once()