Exemplo n.º 1
0
    def test_send_notification_does_not_send_email_with_ssl_when_email_ssl_not_set(
            self):
        logger = mock.MagicMock()
        client = mock.MagicMock()

        arguments = self.construct_arguments()
        arguments["email_ssl"] = False

        notifier_object = notifier.Notifier(logger, arguments)

        notifier.smtplib = mock.MagicMock()
        notifier.urllib2 = mock.MagicMock()
        notifier_object.send_notification("")

        notifier.smtplib.SMTP_SSL().sendmail.assert_not_called()
Exemplo n.º 2
0
    def test_send_notification_logs_info_when_sending_to_telegram(self):
        logger = mock.MagicMock()
        client = mock.MagicMock()

        arguments = self.construct_arguments()
        arguments["email_to"] = None
        arguments["slack_url"] = None

        notifier_object = notifier.Notifier(logger, arguments)

        notifier.smtplib = mock.MagicMock()
        notifier.urllib2 = mock.MagicMock()
        notifier_object.send_notification("")

        logger.info.assert_called_once()
Exemplo n.º 3
0
    def test_send_notification_does_not_use_host_alias_when_not_set(self):
        logger = mock.MagicMock()
        client = mock.MagicMock()

        arguments = self.construct_arguments()
        arguments["server_host_alias"] = None

        notifier_object = notifier.Notifier(logger, arguments)

        notifier.smtplib = mock.MagicMock()
        notifier.urllib2 = mock.MagicMock()
        notifier_object.send_notification("")

        notifier.smtplib.SMTP().sendmail.assert_called_once_with(
            "*****@*****.**", ["*****@*****.**"],
            "Subject: foo foo-host foo\n\nfoo-host - ")
Exemplo n.º 4
0
    def test_send_notification_does_not_send_to_telegram_when_any_argument_not_set(
            self):
        logger = mock.MagicMock()
        client = mock.MagicMock()

        arguments = self.construct_arguments()
        arguments["telegram_bot_id"] = None

        notifier_object = notifier.Notifier(logger, arguments)

        notifier.smtplib = mock.MagicMock()
        notifier.urllib2 = mock.MagicMock()
        notifier_object.send_notification("")

        # only slack is called
        notifier.urllib2.urlopen.assert_called_once()