def test_send_organizer_associated_to_event_sends_mails_with_subject(self): """ Testing that function 'send_organizer_associated_to_event' sends emails to the listed organizers with the correct subject.""" event = Event.objects.filter(name='MyTest01').first() create_organizer_set() email_notifier.send_organizer_associated_to_event( event, Organizer.objects.all(), {'domain': 'testserver', 'protocol': 'http'} ) self.assertEqual(len(mail.outbox), Organizer.objects.all().count()) send_to = [] for email in mail.outbox: send_to.extend(email.to) self.assertEqual(email.subject, render_to_string('mails/organizer_associated_to_event_subject.txt')) self.assertIn('*****@*****.**', send_to) self.assertIn('*****@*****.**', send_to)
def save_formset(self, request, form, formset, change): instances = formset.save(commit=False) event_instance = form.save(commit=False) notify_organizers = [] for instance in instances: if type(instance) == EventOrganizer: exists_organizer = EventOrganizer.objects.filter( event=instance.event, organizer=instance.organizer).exists() if not exists_organizer: notify_organizers.append(instance.organizer) super(EventAdmin, self).save_formset(request, form, formset, change) if len(notify_organizers): current_site = get_current_site(request) context = { 'domain': current_site.domain, 'protocol': 'https' if request.is_secure() else 'http' } email_notifier.send_organizer_associated_to_event( event_instance, notify_organizers, context)