def test_send_notification_recipients_str(mock_mail, file_html): mock_mail.send.return_value = Email() recipients = "*****@*****.**" with patch.object(Notification, 'save'): utils.send_notification(recipients, content_filename=file_html) # we called send with all the proper args mock_mail.send.assert_called() call_kwargs = mock_mail.send.call_args[1] assert [recipients] == call_kwargs["recipients"]
def test_send_notification(mock_mail, file_html): mock_mail.send.return_value = Email() recipients = ["*****@*****.**"] with patch.object(Notification, 'save'): utils.send_notification(recipients, content_filename=file_html) # we called send with all the proper args mock_mail.send.assert_called() call_kwargs = mock_mail.send.call_args[1] assert settings.DEFAULT_FROM_EMAIL == call_kwargs['sender'] assert recipients == call_kwargs["recipients"]
def send_notification_email(self, subject, recipient, template_name): # TODO this could be async to avoid too long api calls in case of mail server issue serializer = TravelMailSerializer(self, context={}) send_notification( recipients=[recipient], from_address=settings.DEFAULT_FROM_EMAIL, # TODO what should sender be? subject=subject, html_content_filename=template_name, context={'travel': serializer.data, 'url': self.get_object_url()} )
def test_send_notification_from_address(mock_mail, file_html): mock_mail.send.return_value = Email() recipients = ["*****@*****.**"] from_address = "*****@*****.**" with patch.object(Notification, 'save'): utils.send_notification(recipients, from_address=from_address, content_filename=file_html) # we called send with all the proper args mock_mail.send.assert_called() call_kwargs = mock_mail.send.call_args[1] assert from_address == call_kwargs['sender'] assert recipients == call_kwargs["recipients"]
def send_mail_for_error(self, workspace, invoice): url = reverse('t2f:invoices:details', kwargs={'invoice_pk': invoice.id}) recipients = User.objects.filter(profile__country=workspace, groups__name='Finance Focal Point').values_list('email', flat=True) # TODO what should sender be? send_notification( recipients=[u.email for u in recipients], from_address=settings.DEFAULT_FROM_EMAIL, # TODO what should sender be? subject='[Travel2Field VISION Error] {}'.format(invoice.reference_number), html_content_filename='emails/failed_invoice_sync.html', context={'invoice': invoice, 'url': url} )