def test_clean_invite_attendees__invalid(self): expected = ['*****@*****.**', 'test@democom'] data = ','.join(expected) org = OrganizationFactory() form = EventRegistrationForm(None, org) form.cleaned_data = {'invite_attendees': data} with self.assertRaises(ValidationError): form.clean_invite_attendees()
def test_clean_invite_attendees__strip_whitespace(self): expected = ['*****@*****.**', '*****@*****.**'] data = ', '.join(expected) org = OrganizationFactory() form = EventRegistrationForm(None, org) form.cleaned_data = {'invite_attendees': data} cleaned = form.clean_invite_attendees() self.assertEqual(cleaned, expected)
def test_attendee_invites_on_save(self): emails = ['*****@*****.**', '*****@*****.**'] event = EventFactory() data = model_to_dict(event) data['invite_attendees'] = ','.join(emails) request = RequestFactory().get('/') request.user = PersonFactory() form = EventRegistrationForm(request, event.organization, instance=event, data=data) self.assertTrue(form.is_valid()) self.assertTrue(form.cleaned_data.get('invite_attendees')) self.assertEqual(EventInvite.get_invites(event).count(), 0) self.assertEqual(len(mail.outbox), 0) form.save() self.assertEqual(EventInvite.get_invites(event).count(), 2) self.assertEqual(len(mail.outbox), 2)
def test_attendee_invites_on_save(self): emails = ['*****@*****.**', '*****@*****.**'] event = EventFactory() data = model_to_dict(event) data['invite_attendees'] = ','.join(emails) request = RequestFactory().get('/') request.user = PersonFactory() form = EventRegistrationForm( request, event.organization, instance=event, data=data ) self.assertTrue(form.is_valid()) self.assertTrue(form.cleaned_data.get('invite_attendees')) self.assertEqual(EventInvite.get_invites(event).count(), 0) self.assertEqual(len(mail.outbox), 0) form.save() self.assertEqual(EventInvite.get_invites(event).count(), 2) self.assertEqual(len(mail.outbox), 2)