def test_send_invitation(self): invited_email = 'test1@localhost' data = { 'department': self.department.id, 'email': invited_email, 'account_category': self.account_category.id, } self.client.login(username=self.user.username, password='******') response = self.client.post(reverse('eggplant:invitations:invite'), data=data, follow=True) self.assertRedirects(response, reverse('eggplant:dashboard:home')) expected = 'Invitation has been send to {}'.format(invited_email) self.assertContains(response, expected, 1, 200) self.assertEqual(len(mail.outbox), 1) self.assertTrue(bool(mail.outbox[0].subject)) invitation = DepartmentInvitation.objects.get(email=invited_email) url = absolute_url_reverse( 'eggplant:invitations:accept_invitation', kwargs=dict(verification_key=invitation.verification_key.hex) ) self.assertRegex(invitation.verification_key.hex, r'^[a-z0-9]{32}\Z') self.assertIn(url, mail.outbox[0].body)
def test_send_invitation(self): invited_email = 'test1@localhost' data = { 'department': self.department.id, 'email': invited_email, 'account_category': self.account_category.id, } self.client.login(username=self.user.username, password='******') response = self.client.post(reverse('eggplant:invitations:invite'), data=data, follow=True) self.assertRedirects(response, reverse('eggplant:dashboard:home')) expected = 'Invitation has been send to {}'.format(invited_email) self.assertContains(response, expected, 1, 200) self.assertEqual(len(mail.outbox), 1) self.assertTrue(bool(mail.outbox[0].subject)) invitation = DepartmentInvitation.objects.get(email=invited_email) url = absolute_url_reverse( 'eggplant:invitations:accept_invitation', kwargs=dict(verification_key=invitation.verification_key.hex)) self.assertRegex(invitation.verification_key.hex, r'^[a-z0-9]{32}\Z') self.assertIn(url, mail.outbox[0].body)
def send_email_invitation(sender, instance, created, **kwargs): department = instance.department.name if created: subject = _('You have been invited to join {department}!').format( department=department ) to_addrs = [instance.email, ] invite_url = absolute_url_reverse( url_name='eggplant:invitations:accept_invitation', kwargs=dict( verification_key=instance.verification_key.hex ) ) body = _( """Hi there!\n""" """Thank you for signing up as a member for {department}. We're """ """happy that you want to be part of our community.\n""" """\n""" """Please click the following link to confirm you email address """ """and fill out your membership details:\n""" """{invite_url}\n""" """\n""" """\n""" """Cheers,\n""" """all of us at {department}""" ).format(invite_url=invite_url, department=department) send_mail( subject, body, settings.DEFAULT_FROM_EMAIL, to_addrs, fail_silently=not settings.DEBUG )
def send_email_invitation(sender, instance, created, **kwargs): ''' TODO: Implement an HTML message, commenting out the html_* lines below ''' department = instance.department.name if created: subject = _( 'Your invitation to join the {department} department of {coop_name}!' ).format(department=department, coop_name=settings.COOP_NAME) to_addrs = [ instance.email, ] invite_url = absolute_url_reverse( url_name='eggplant:invitations:accept_invitation', kwargs=dict(verification_key=instance.verification_key.hex)) context = Context({ 'department': department, 'coop_name': settings.COOP_NAME, 'invite_url': invite_url, }) plain_template_path = 'eggplant/invitations/email/department_invitation.txt' # html_template_path = 'eggplant/invitations/email/department_invitation.html' plain_body = get_template(plain_template_path).render(context) # html_body = get_template(html_template_path).render(context) send_mail( subject, plain_body, settings.DEFAULT_FROM_EMAIL, to_addrs, fail_silently=not settings.DEBUG, # html_message=html_body )
def send_email_invitation(sender, instance, created, **kwargs): department = instance.department.name if created: subject = _('You have been invited to join {department}!').format( department=department) to_addrs = [ instance.email, ] invite_url = absolute_url_reverse( url_name='eggplant:invitations:accept_invitation', kwargs=dict(verification_key=instance.verification_key.hex)) body = _( """Hi there!\n""" """Thank you for signing up as a member for {department}. We're """ """happy that you want to be part of our community.\n""" """\n""" """Please click the following link to confirm you email address """ """and fill out your membership details:\n""" """{invite_url}\n""" """\n""" """\n""" """Cheers,\n""" """all of us at {department}""").format(invite_url=invite_url, department=department) send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, to_addrs, fail_silently=not settings.DEBUG)
def send_email_invitation(sender, instance, created, **kwargs): ''' TODO: Implement an HTML message, commenting out the html_* lines below ''' department = instance.department.name if created: subject = _('Your invitation to join the {department} department of {coop_name}!').format( department=department, coop_name=settings.COOP_NAME ) to_addrs = [instance.email, ] invite_url = absolute_url_reverse( url_name='eggplant:invitations:accept_invitation', kwargs=dict( verification_key=instance.verification_key.hex ) ) context = Context({ 'department': department, 'coop_name': settings.COOP_NAME, 'invite_url': invite_url, }) plain_template_path = 'eggplant/invitations/email/department_invitation.txt' # html_template_path = 'eggplant/invitations/email/department_invitation.html' plain_body = get_template(plain_template_path).render(context) # html_body = get_template(html_template_path).render(context) send_mail( subject, plain_body, settings.DEFAULT_FROM_EMAIL, to_addrs, fail_silently=not settings.DEBUG, # html_message=html_body )