def test_email_recipients(mailoutbox, send_kwargs, future_event, organizer_peter, organizer_julia): """ All emails should go to event.email and all team members, but only once. """ send_kwargs['events'] = [future_event] future_event.email = organizer_peter.email future_event.save() future_event.team.add(organizer_julia) handle_emails.send_event_emails(**send_kwargs) assert len(mailoutbox) == 1 assert set(mailoutbox[0].to) == set([organizer_peter.email, organizer_julia.email])
def test_email_recipients(mailoutbox, send_kwargs, future_event, organizer_peter, organizer_julia): """ All emails should go to event.email and all team members, but only once. """ send_kwargs['events'] = [future_event] future_event.email = organizer_peter.email future_event.save() future_event.team.add(organizer_julia) handle_emails.send_event_emails(**send_kwargs) assert len(mailoutbox) == 1 assert set(mailoutbox[0].to) == set( [organizer_peter.email, organizer_julia.email])
def test_email_template_rendering(mailoutbox, send_kwargs): """ Test basic email rendering for templates and content. """ city_name = "definitely not a city that will actually show up in a template" event = Event.objects.create(city=city_name, email='*****@*****.**') send_kwargs['events'] = [event] handle_emails.send_event_emails(**send_kwargs) assert len(mailoutbox) == 1 mail = mailoutbox[0] html_content, _ = mail.alternatives[0] assert "<p>" in html_content assert "<p>" not in mail.body assert event.city in html_content
def test_email_template_rendering(mailoutbox, send_kwargs): """ Test basic email rendering for templates and content. """ city_name = "definitely not a city that will actually show up in a template" event = Event.objects.create(city=city_name, email='*****@*****.**') send_kwargs['events'] = [event] handle_emails.send_event_emails(**send_kwargs) assert len(mailoutbox) == 1 mail = mailoutbox[0] html_content, _ = mail.alternatives[0] assert "<p>" in html_content assert "<p>" not in mail.body assert event.city in html_content
def test_email_template_rendering(self): """ Test basic email rendering for templates and content. """ city_name = "definitely not a city that will actually show up in a template" event = Event.objects.create(city=city_name, email='*****@*****.**') self.sending_args['events'] = [event] with mock.patch('core.management.commands.handle_emails.send_mail' ) as mock_send_mail: handle_emails.send_event_emails(**self.sending_args) _, send_kwargs = mock_send_mail.call_args self.assertEqual(mock_send_mail.call_count, 1) self.assertIn("<p>", send_kwargs['html_message']) self.assertNotIn("<p>", send_kwargs['message']) self.assertTrue(event.city in send_kwargs['html_message'])
def test_email_recipients(self): """ All emails should go to event.email and all team members, but only once. """ event = Event.objects.create(email='*****@*****.**') self.sending_args['events'] = [event] for x in range(2): user = User.objects.create(email='user-{}@example.com'.format(x)) event.team.add(user) with mock.patch('core.management.commands.handle_emails.send_mail' ) as mock_send_mail: handle_emails.send_event_emails(**self.sending_args) _, send_kwargs = mock_send_mail.call_args self.assertCountEqual(send_kwargs['recipient_list'], ['*****@*****.**', '*****@*****.**'])
def test_email_recipients(self): """ All emails should go to event.email and all team members, but only once. """ event = Event.objects.create(email='*****@*****.**') self.sending_args['events'] = [event] for x in range(2): user = User.objects.create(email='user-{}@example.com'.format(x)) event.team.add(user) with mock.patch('core.management.commands.handle_emails.send_mail') as mock_send_mail: handle_emails.send_event_emails( **self.sending_args ) _, send_kwargs = mock_send_mail.call_args self.assertCountEqual(send_kwargs['recipient_list'], ['*****@*****.**', '*****@*****.**'])
def test_email_template_rendering(self): """ Test basic email rendering for templates and content. """ city_name = "definitely not a city that will actually show up in a template" event = Event.objects.create(city=city_name, email='*****@*****.**') self.sending_args['events'] = [event] self.sending_args['subject'] = "testing {{event.city}} {{event.email}}" with mock.patch('core.management.commands.handle_emails.send_mail') as mock_send_mail: handle_emails.send_event_emails( **self.sending_args ) _, send_kwargs = mock_send_mail.call_args self.assertEqual(mock_send_mail.call_count, 1) self.assertIn("<p>", send_kwargs['html_message']) self.assertNotIn("<p>", send_kwargs['message']) self.assertEqual("testing {} {}".format(event.city, event.email), send_kwargs['subject']) self.assertTrue(event.city in send_kwargs['html_message'])
def test_approximate_date_behaviour(self): """ Test logic for the behaviour of skipping events with approximate dates. Events with approximate dates should be skipped if ignore_approximate_dates is True """ # Create an event with an approximate date event = Event.objects.create(date=ApproximateDate(year=2017, month=1)) self.sending_args['events'] = [event] with mock.patch('core.management.commands.handle_emails.send_mail' ) as mock_send_mail: # We're ignoring approximate dates, so no email should be sent self.sending_args['ignore_approximate_events'] = True handle_emails.send_event_emails(**self.sending_args) self.assertEqual(mock_send_mail.call_count, 0) mock_send_mail.reset_mock() # Now we're not ignoring approximate dates, so a mail should be sent. self.sending_args['ignore_approximate_events'] = False handle_emails.send_event_emails(**self.sending_args) self.assertEqual(mock_send_mail.call_count, 1) mock_send_mail.reset_mock() # Still ignoring approximate dates, but now the event date is fixed, so a mail should be sent. event.date = timezone.datetime.now() event.save() handle_emails.send_event_emails(**self.sending_args) self.assertEqual(mock_send_mail.call_count, 1) mock_send_mail.reset_mock()
def test_approximate_date_behaviour(mailoutbox, send_kwargs): """ Test logic for the behaviour of skipping events with approximate dates. Events with approximate dates should be skipped if ignore_approximate_dates is True """ # Create an event with an approximate date event = Event.objects.create( date=ApproximateDate(year=2017, month=1), email="*****@*****.**") send_kwargs['events'] = [event] # We're ignoring approximate dates, so no email should be sent send_kwargs['ignore_approximate_events'] = True handle_emails.send_event_emails(**send_kwargs) assert len(mailoutbox) == 0 # Now we're not ignoring approximate dates, so a mail should be sent. send_kwargs['ignore_approximate_events'] = False handle_emails.send_event_emails(**send_kwargs) assert len(mailoutbox) == 1 # Still ignoring approximate dates, but now the event date is fixed, # so a mail should be sent. event.date = timezone.datetime.now() event.save() handle_emails.send_event_emails(**send_kwargs) assert len(mailoutbox) == 2
def test_approximate_date_behaviour(mailoutbox, send_kwargs): """ Test logic for the behaviour of skipping events with approximate dates. Events with approximate dates should be skipped if ignore_approximate_dates is True """ # Create an event with an approximate date event = Event.objects.create(date=ApproximateDate(year=2017, month=1), email="*****@*****.**") send_kwargs['events'] = [event] # We're ignoring approximate dates, so no email should be sent send_kwargs['ignore_approximate_events'] = True handle_emails.send_event_emails(**send_kwargs) assert len(mailoutbox) == 0 # Now we're not ignoring approximate dates, so a mail should be sent. send_kwargs['ignore_approximate_events'] = False handle_emails.send_event_emails(**send_kwargs) assert len(mailoutbox) == 1 # Still ignoring approximate dates, but now the event date is fixed, # so a mail should be sent. event.date = timezone.datetime.now() event.save() handle_emails.send_event_emails(**send_kwargs) assert len(mailoutbox) == 2
def test_approximate_date_behaviour(self): """ Test logic for the behaviour of skipping events with approximate dates. Events with approximate dates should be skipped if ignore_approximate_dates is True """ # Create an event with an approximate date event = Event.objects.create(date=ApproximateDate(year=2017, month=1)) self.sending_args['events'] = [event] with mock.patch('core.management.commands.handle_emails.send_mail') as mock_send_mail: # We're ignoring approximate dates, so no email should be sent self.sending_args['ignore_approximate_events'] = True handle_emails.send_event_emails( **self.sending_args ) self.assertEqual(mock_send_mail.call_count, 0) mock_send_mail.reset_mock() # Now we're not ignoring approximate dates, so a mail should be sent. self.sending_args['ignore_approximate_events'] = False handle_emails.send_event_emails( **self.sending_args ) self.assertEqual(mock_send_mail.call_count, 1) mock_send_mail.reset_mock() # Still ignoring approximate dates, but now the event date is fixed, so a mail should be sent. event.date = timezone.datetime.now() event.save() handle_emails.send_event_emails( **self.sending_args ) self.assertEqual(mock_send_mail.call_count, 1) mock_send_mail.reset_mock()