def test_email_event_attendees(self, mock_success): """Send email to selected event attendees.""" user = UserFactory.create(groups=['Rep']) event = EventFactory.create(slug='test-event', owner=user) AttendanceFactory.create_batch(3, event=event) self.client.login(username=user.username, password='******') reps = event.attendees.all() valid_data = dict() for rep in reps: field_name = '%s' % rep.id valid_data[field_name] = 'True' valid_data['subject'] = 'This is the mail subject' valid_data['body'] = 'This is the mail subject' valid_data['slug'] = 'test-event' url = reverse('email_attendees', kwargs={'slug': event.slug}) response = self.client.post(url, valid_data, follow=True) self.assertTemplateUsed(response, 'view_event.html') mock_success.assert_called_with(ANY, 'Email sent successfully.') eq_(len(mail.outbox), 4) for i in range(0, len(mail.outbox)): eq_(len(mail.outbox[i].cc), 1) eq_(len(mail.outbox[i].to), 1)
def test_email_event_attendees(self, mock_success): """Send email to selected event attendees.""" user = UserFactory.create(groups=['Rep']) event = EventFactory.create(slug='test-event', owner=user) AttendanceFactory.create_batch(3, event=event) reps = event.attendees.all() valid_data = dict() for rep in reps: field_name = '%s' % rep.id valid_data[field_name] = 'True' valid_data['subject'] = 'This is the mail subject' valid_data['body'] = 'This is the mail subject' valid_data['slug'] = 'test-event' url = reverse('email_attendees', kwargs={'slug': event.slug}) with self.login(user) as client: response = client.post(url, valid_data, follow=True) ok_('view_event.jinja' in [template.template.name for template in response.templates if isinstance(template, Jinja_Template)]) mock_success.assert_called_with(ANY, 'Email sent successfully.') eq_(len(mail.outbox), 4) for i in range(0, len(mail.outbox)): eq_(len(mail.outbox[i].cc), 1) eq_(len(mail.outbox[i].to), 1)
def test_email_event_attendees(self, mock_success): """Send email to selected event attendees.""" user = UserFactory.create(groups=['Rep']) event = EventFactory.create(slug='test-event', owner=user) AttendanceFactory.create_batch(3, event=event) reps = event.attendees.all() valid_data = dict() for rep in reps: field_name = '%s' % rep.id valid_data[field_name] = 'True' valid_data['subject'] = 'This is the mail subject' valid_data['body'] = 'This is the mail subject' valid_data['slug'] = 'test-event' url = reverse('email_attendees', kwargs={'slug': event.slug}) with self.login(user) as client: response = client.post(url, valid_data, follow=True) ok_('view_event.jinja' in [ template.template.name for template in response.templates if isinstance(template, Jinja_Template) ]) mock_success.assert_called_with(ANY, 'Email sent successfully.') eq_(len(mail.outbox), 4) for i in range(0, len(mail.outbox)): eq_(len(mail.outbox[i].cc), 1) eq_(len(mail.outbox[i].to), 1)
def test_email_event_attendees(self, mock_success): """Send email to selected event attendees.""" user = UserFactory.create(groups=['Rep']) event = EventFactory.create(slug='test-event', owner=user) AttendanceFactory.create_batch(3, event=event) self.client.login(username=user.username, password='******') reps = event.attendees.all() valid_data = dict() for rep in reps: field_name = '%s %s <%s>' % (rep.first_name, rep.last_name, rep.email) valid_data[field_name] = 'True' valid_data['subject'] = 'This is the mail subject' valid_data['body'] = 'This is the mail subject' valid_data['slug'] = 'test-event' url = reverse('email_attendees', kwargs={'slug': 'test-event'}) response = self.client.post(url, valid_data, follow=True) self.assertTemplateUsed(response, 'view_event.html') mock_success.assert_called_with(ANY, 'Email sent successfully.') eq_(len(mail.outbox), 1) email = mail.outbox[0] eq_(len(email.to), 4) eq_(len(email.cc), 1)
def test_attendance_list_sorting(self): """Test sorting of event attendance list.""" e = EventFactory.create(start=START_DT, end=self.single_day_end) AttendanceFactory.create_batch(2, event=e) sorted_list = get_sorted_attendance_list(e) eq_(sorted_list[0], e.owner, 'Owner is not first.') copy_list = sorted_list[1:] sorted(copy_list, key=lambda x: '%s %s' % (x.last_name, x.first_name)) eq_(copy_list, sorted_list[1:], 'List is not properly sorted.')
def test_attendance_list_sorting(self): """Test sorting of event attendance list.""" e = EventFactory.create(start=START_DT, end=self.single_day_end) AttendanceFactory.create_batch(2, event=e) sorted_list = get_sorted_attendance_list(e) eq_(sorted_list[0], e.owner, 'Owner is not first.') copy_list = sorted_list[1:] sorted(copy_list, key=lambda x: '%s %s' % (x.last_name, x.first_name)) eq_(copy_list, sorted_list[1:], 'List is not properly sorted.')