def test_send_to(self): to = '*****@*****.**' send_email('to.md', {'to': to}) assert len(mail.outbox) == 1 assert len(mail.outbox[0].to) == 1 assert to in mail.outbox[0].to
def send_registration_verification_email(to): ogmios.send_email( 'registration/mail/email_verification.md', { 'confirm_email_url': build_absolute_uri(reverse_registration_url(to)), 'to': to, }, )
def test_html(self): send_email('html.html', {}) assert len(mail.outbox) == 1 message = mail.outbox[0].message() assert message.is_multipart() content_types = {m.get_content_type() for m in message.get_payload()} assert content_types == {'text/plain', 'text/html'}
def initiate_email_change(user, new_email): signed_data = { 'old_email': user.email, 'email': new_email, 'pk': user.pk } ogmios.send_email('verified_email_change/change_email_confirmation_email.html', { 'user': user, 'new_email': new_email, 'signed_data': signing.dumps(signed_data, salt=EMAIL_CHANGE_SALT, compress=True) })
def test_attachment_validation(self): content = 'Some content' with NamedTemporaryFile() as fp: fp.write(content.encode('utf-8')) fp.flush() with self.assertRaises(OgmiosError): send_email('attachment.md', context={}, attachments=[{ 'name': 'file.txt' }])
def test_send_attachement(self): # Encode to bytes for Python 3 compatibility content = 'Some content'.encode('utf-8') with NamedTemporaryFile() as fp: fp.write(content) fp.flush() send_email('attachment.md', {'file': fp.name}) assert len(mail.outbox) == 1 assert len(mail.outbox[0].attachments) == 1 assert mail.outbox[0].attachments[0][1] == content
def send_verification_email(self, protocol="https"): """ Send the verification email. The activation key is simply the username, signed using TimestampSigner. """ activation_key = signing.dumps(obj=self.email, salt="registration") ogmios.send_email( "mail/verification.html", { "site": Site.objects.get_current(), "protocol": protocol, "to_email": self.email, "from": settings.DEFAULT_FROM_EMAIL, "activation_key": activation_key, }, )
def test_context_application(self): context = { 'to_name': 'Leroy Jenkins', 'to_address': '*****@*****.**', 'from_name': 'Onyxia', 'from_address': '*****@*****.**', 'subject': 'Raid', 'survival_percent': "33.3 (repeating of course) percent", } send_email('context.html', context) sent_mail = mail.outbox[0] assert sent_mail.to[0] == '{} <{}>'.format(context['to_name'], context['to_address']) assert sent_mail.from_email == '{} <{}>'.format(context['from_name'], context['from_address']) assert sent_mail.subject == context['subject'] assert get_message_text(sent_mail).strip() == "Chance of survival: {}".format(context['survival_percent'])
def test_send_renamed_attachment_without_mimetype(self): content = 'Some content' with NamedTemporaryFile() as fp: # Encode to bytes for Python 3 compatibility. fp.write(content.encode('utf-8')) fp.flush() send_email('attachment.md', context={}, attachments=[{ 'path': fp.name, 'name': 'file_test.txt', }]) assert len(mail.outbox) == 1 assert len(mail.outbox[0].attachments) == 1 assert mail.outbox[0].attachments[0][1] == content assert mail.outbox[0].attachments[0][0] == 'file_test.txt'
def send_notifications(action): # Prevents notification users of their on actions and notifying about the # same action twice. blacklist = {action.user} if hasattr(action, 'setassignment') and action.setassignment.assigned_to not in blacklist: blacklist.add(action.setassignment.assigned_to) ogmios.send_email('buggy/mail/bug_assigned.md', { 'bug': action.bug, 'action': action, 'assigned_to': action.setassignment.assigned_to, }) if hasattr(action, 'comment'): for mention in action.comment.mentioned_users - blacklist: ogmios.send_email('buggy/mail/bug_mention.md', { 'bug': action.bug, 'action': action, 'to': mention, })
def test_comma(self): send_email('comma.md', {}) assert mail.outbox[0].to == [ '"Foo," <*****@*****.**>', ]