Esempio n. 1
0
 def test_send_not_email(self):
     """
     This just tests that if we currently send a non Email notification,
     sent_recipients doesn't get updated.
     """
     notification = NotificationFactory(type='SMS')
     notification.send_notification()
     self.assertEqual(notification.sent_recipients, [])
Esempio n. 2
0
    def test_send_notification(self):
        old_email_count = Email.objects.count()
        valid_notification = NotificationFactory()
        valid_notification.send_notification()

        six.assertCountEqual(self, valid_notification.recipients,
                             valid_notification.sent_recipients)
        self.assertEqual(Email.objects.count(), old_email_count + 1)
Esempio n. 3
0
 def test_sender_is_not_a_user(self, mock_mail):
     "If sender is not a User, send DEFAULT_FROM_EMAIL"
     notification = NotificationFactory()
     notification.send_mail()
     # we called send ...
     mock_mail.send.assert_called()
     call_kwargs = mock_mail.send.call_args[1]
     # ... with the proper email
     self.assertEqual(settings.DEFAULT_FROM_EMAIL, call_kwargs['sender'])
Esempio n. 4
0
 def test_ignore_mail_sending_error(self, mock_mail):
     "If sending throws an error, we log and continue."
     mock_mail.send.side_effect = Exception()
     notification = NotificationFactory()
     with patch('notification.models.logger') as mock_logger:
         notification.send_mail()
     mock_logger.exception.assert_called_with('Failed to send mail.')
     # recipients weren't marked as successful
     self.assertEqual(notification.sent_recipients, [])
Esempio n. 5
0
 def test_sender_is_user(self, mock_mail):
     "If sender is a User, send from their email address"
     sender = UserFactory()
     notification = NotificationFactory(sender=sender)
     notification.send_mail()
     # we called send ...
     mock_mail.send.assert_called()
     call_kwargs = mock_mail.send.call_args[1]
     # ... with the proper email
     self.assertEqual(sender.email, call_kwargs['sender'])
Esempio n. 6
0
 def test_template_data_is_str(self, mock_mail):
     "We accept string data for the template context."
     template_data = '{"foo": "bar"}'
     notification = NotificationFactory(template_data=template_data)
     notification.send_mail()
     # we called send ...
     mock_mail.send.assert_called()
     call_kwargs = mock_mail.send.call_args[1]
     # ... with the proper context
     self.assertEqual({'foo': 'bar'}, call_kwargs['context'])
Esempio n. 7
0
    def test_notification(self):
        agreement = AgreementFactory(partner=PartnerFactory(name=b'xyz'))
        notification = NotificationFactory(sender=agreement)

        self.assertIn(u'Email Notification from', six.text_type(notification))
        self.assertIn(u'for xyz', six.text_type(notification))

        agreement = AgreementFactory(partner=PartnerFactory(
            name=u'R\xe4dda Barnen'))
        notification = NotificationFactory(sender=agreement)
        self.assertIn(u'Email Notification from', six.text_type(notification))
        self.assertIn(u'for R\xe4dda Barnen', six.text_type(notification))
Esempio n. 8
0
 def test_success(self, mock_mail):
     "On successful notification, sent_recipients should be populated."
     notification = NotificationFactory(template_data={'foo': 'bar'})
     notification.send_mail()
     # we called send with all the proper args
     mock_mail.send.assert_called_with(
         recipients=notification.recipients,
         sender=settings.DEFAULT_FROM_EMAIL,
         template=notification.template_name,
         context=notification.template_data,
     )
     # we marked the recipients as sent
     self.assertEqual(notification.recipients, notification.sent_recipients)