def test_exclude_mail(self, _send_mail): """Don't send mail if the to_addr is in the exclude_mail setting.""" mail.send_mail('*****@*****.**', '*****@*****.**', 'R013X', 'Want a c00l w@tch?') # The mail should not have been sent self.assertEqual(_send_mail.call_count, 0)
def test_no_from_addr(self, warn, _send_mail): """If there is no from_addr, a warning should be logged and the function should return.""" mail.send_mail(None, '*****@*****.**', 'R013X', 'Want a c00l w@tch?') warn.assert_called_once_with('Unable to send mail: bodhi_email not defined in the config') # The mail should not have been sent self.assertEqual(_send_mail.call_count, 0)
def test_send(self, SMTP): """Make sure an e-mail gets sent when conditions are right.""" smtp = SMTP.return_value mail.send_mail('*****@*****.**', '*****@*****.**', 'R013X', 'Want a c00l w@tch?') SMTP.assert_called_once_with('smtp.fp.o') smtp.sendmail.assert_called_once_with( b'*****@*****.**', [b'*****@*****.**'], (b'From: [email protected]\r\nTo: [email protected]\r\n' b'X-Bodhi: fedoraproject.org\r\nSubject: R013X\r\n\r\nWant a c00l w@tch?'))
def test_headers(self, SMTP): """Make sure headers are used correctly.""" smtp = SMTP.return_value mail.send_mail('*****@*****.**', '*****@*****.**', 'R013X', 'Want a c00l w@tch?', headers={'Bodhi-Is': 'Great'}) SMTP.assert_called_once_with('smtp.fp.o') smtp.sendmail.assert_called_once_with( b'*****@*****.**', [b'*****@*****.**'], (b'From: [email protected]\r\nTo: [email protected]\r\nBodhi-Is: Great\r\n' b'X-Bodhi: fedoraproject.org\r\nSubject: R013X\r\n\r\nWant a c00l w@tch?'))
def send_testing_digest(self): """Send digest mail to mailing lists""" self.log.info('Sending updates-testing digest') sechead = u'The following %s Security updates need testing:\n Age URL\n' crithead = u'The following %s Critical Path updates have yet to be approved:\n Age URL\n' testhead = u'The following builds have been pushed to %s updates-testing\n\n' for prefix, content in self.testing_digest.iteritems(): release = self.db.query(Release).filter_by(long_name=prefix).one() test_list_key = '%s_test_announce_list' % ( release.id_prefix.lower().replace('-', '_')) test_list = config.get(test_list_key) if not test_list: log.warn('%r undefined. Not sending updates-testing digest', test_list_key) continue log.debug("Sending digest for updates-testing %s" % prefix) maildata = u'' security_updates = self.get_security_updates(prefix) if security_updates: maildata += sechead % prefix for update in security_updates: maildata += u' %3i %s %s\n' % ( update.days_in_testing, update.abs_url(), update.title) maildata += '\n\n' critpath_updates = self.get_unapproved_critpath_updates(prefix) if critpath_updates: maildata += crithead % prefix for update in self.get_unapproved_critpath_updates(prefix): maildata += u' %3i %s %s\n' % ( update.days_in_testing, update.abs_url(), update.title) maildata += '\n\n' maildata += testhead % prefix updlist = content.keys() updlist.sort() for pkg in updlist: maildata += u' %s\n' % pkg maildata += u'\nDetails about builds:\n\n' for nvr in updlist: maildata += u"\n" + self.testing_digest[prefix][nvr] mail.send_mail(config.get('bodhi_email'), test_list, '%s updates-testing report' % prefix, maildata)