示例#1
0
    def test_exception_in__send_mail(self, exception_log, SMTP):
        """Assert that we log an exception if _send_mail catches one"""
        update = models.Update.query.all()[0]

        mail.send('*****@*****.**', 'comment', update, agent='bowlofeggs')

        exception_log.assert_called_once_with('Unable to send mail')
        sendmail = SMTP.return_value.sendmail
        self.assertEqual(sendmail.call_count, 0)
示例#2
0
    def test_nvr_in_subject(self, SMTP):
        """Assert that the sent e-mail has the full NVR in the subject."""
        update = models.Update.query.all()[0]

        mail.send('*****@*****.**', 'comment', update, agent='bowlofeggs')

        SMTP.assert_called_once_with('smtp.example.com')
        sendmail = SMTP.return_value.sendmail
        self.assertEqual(sendmail.call_count, 1)
        self.assertEqual(sendmail.mock_calls[0][1][0], b'*****@*****.**')
        self.assertEqual(sendmail.mock_calls[0][1][1], [b'*****@*****.**'])
        self.assertTrue(b'X-Bodhi-Update-Title: bodhi-2.0-1.fc17' in sendmail.mock_calls[0][1][2])
        self.assertTrue(
            b'Subject: [Fedora Update] [comment] bodhi-2.0-1.fc17' in sendmail.mock_calls[0][1][2])
示例#3
0
    def test_nvr_in_subject(self, SMTP):
        """Assert that the sent e-mail has the full NVR in the subject."""
        update = models.Update.query.all()[0]

        mail.send(['*****@*****.**'], 'comment', update, agent='bowlofeggs')

        SMTP.assert_called_once_with('smtp.example.com')
        sm = SMTP.return_value.sendmail
        assert sm.call_count == 1
        assert sm.mock_calls[0][1][0] == '*****@*****.**'
        assert sm.mock_calls[0][1][1] == ['*****@*****.**']
        assert b'X-Bodhi-Update-Title: bodhi-2.0-1.fc17' in sm.mock_calls[0][
            1][2]
        assert b'Subject: [Fedora Update] [comment] bodhi-2.0-1.fc17' in sm.mock_calls[
            0][1][2]
示例#4
0
    def test_msg_type_new(self, SMTP):
        """Assert that the correct header is used for the "new" msg_type."""
        sendmail = SMTP.return_value.sendmail
        update = models.Update.query.all()[0]

        mail.send('*****@*****.**', 'new', update, agent='bodhi')

        SMTP.assert_called_once_with('smtp.fp.o')
        self.assertEqual(sendmail.call_count, 1)
        sendmail = sendmail.mock_calls[0]
        self.assertEqual(len(sendmail[1]), 3)
        self.assertEqual(sendmail[1][0], b'*****@*****.**')
        self.assertEqual(sendmail[1][1], [b'*****@*****.**'])
        self.assertTrue('Message-ID: <bodhi-update-{}-{}-{}@{}>'.format(
            update.id, update.user.name, update.release.name,
            config.config.get('message_id_email_domain')) in str(sendmail[1][2]))
示例#5
0
    def test_msg_type_new(self, SMTP):
        """Assert that the correct header is used for the "new" msg_type."""
        sendmail = SMTP.return_value.sendmail
        update = models.Update.query.all()[0]

        mail.send(['*****@*****.**'], 'new', update, agent='bodhi')

        SMTP.assert_called_once_with('smtp.fp.o')
        assert sendmail.call_count == 1
        sendmail = sendmail.mock_calls[0]
        assert len(sendmail[1]) == 3
        assert sendmail[1][0] == '*****@*****.**'
        assert sendmail[1][1] == ['*****@*****.**']
        expected_body = 'Message-ID: <bodhi-update-{}-{}-{}@{}>'.format(
            update.id, update.user.name, update.release.name,
            config.config.get('message_id_email_domain'))
        assert expected_body.encode('utf-8') in sendmail[1][2]