|
1 | 1 | from datetime import datetime |
2 | 2 |
|
3 | 3 | from django.core import mail |
| 4 | +from django.core.mail import EmailMultiAlternatives |
4 | 5 | from django.core.management import call_command |
5 | 6 | from django.test import TestCase, SimpleTestCase |
6 | 7 | from django.test.utils import override_settings |
@@ -343,6 +344,36 @@ def test_sends_all_scheduled_emails(self, render_mock, address_mock): |
343 | 344 | EntityEmailerInterface.send_unsent_scheduled_emails() |
344 | 345 | self.assertEqual(len(mail.outbox), 2) |
345 | 346 |
|
| 347 | + @patch('entity_emailer.interface.pre_send') |
| 348 | + @patch('entity_emailer.interface.get_subscribed_email_addresses') |
| 349 | + @patch.object(Event, 'render', spec_set=True) |
| 350 | + def test_send_signals(self, render_mock, address_mock, mock_pre_send): |
| 351 | + """ |
| 352 | + Test that we properly fire signals during the send process |
| 353 | + """ |
| 354 | + |
| 355 | + # Setup the email |
| 356 | + render_mock.return_value = ['<p>This is a test html email.</p>', 'This is a test text email.'] |
| 357 | + address_mock. return_value = [ '[email protected]', '[email protected]'] |
| 358 | + email = g_email(context={ |
| 359 | + 'test': 'test' |
| 360 | + }, scheduled=datetime.min) |
| 361 | + EntityEmailerInterface.send_unsent_scheduled_emails() |
| 362 | + |
| 363 | + # Assert that we sent the email |
| 364 | + self.assertEqual(len(mail.outbox), 1) |
| 365 | + |
| 366 | + # Assert that we called the pre send signal with the proper values |
| 367 | + name, args, kwargs = mock_pre_send.send.mock_calls[0] |
| 368 | + self.assertEqual(kwargs['sender'], email.event.source.name) |
| 369 | + self.assertEqual(kwargs['email'], email) |
| 370 | + self.assertEqual(kwargs['event'], email.event) |
| 371 | + self.assertEqual(kwargs['context'], { |
| 372 | + 'test': 'test', |
| 373 | + 'entity_emailer_id': str(email.view_uid) |
| 374 | + }) |
| 375 | + self.assertIsInstance(kwargs['message'], EmailMultiAlternatives) |
| 376 | + |
346 | 377 | @patch('entity_emailer.interface.get_subscribed_email_addresses') |
347 | 378 | @patch.object(Event, 'render', spec_set=True) |
348 | 379 | def test_sends_email_with_specified_from_address(self, render_mock, address_mock): |
|
0 commit comments