def test_send_email_success(self): """ Tests that sending out an email returns an integer value rv <= 0 failure to send or error rv >=1 success in send, rv corresponds to number of recipients """ EmailProducer.send = mock.Mock(return_value=1) self.assertEqual(EmailProducer.send('title', 'body', '*****@*****.**', list('*****@*****.**')), 1) self.assertEqual(EmailProducer.send.call_count, 1)
def test_inner_send_mail_function(self): as_obj = AlertSearch() as_obj.save() new_alert = Alert(owner='core', created='2015-09-01T13:20:30+03:00', msg_title='Alert : openstack syslog errors', msg_body='There are 23 incidents of syslog errors', query_id=as_obj.pk) new_alert.save() with mock.patch("django.core.mail.send_mail") \ as sm_mock: sm_mock.return_value = 1 producer_inst = EmailProducer(query=as_obj, sender='*****@*****.**', receiver='*****@*****.**') producer_inst.save() rv = producer_inst.send(new_alert) self.assertEqual(rv, sm_mock.return_value) as_obj.delete() new_alert.delete()