Ticket #13364: t13364-test.diff

File t13364-test.diff, 2.5 KB (added by Ramiro Morales, 15 years ago)

Patch for Django mail regressiontests demonstrating this works

  • new file tests/regressiontests/mail/templates/mail/output.html

    diff --git a/tests/regressiontests/mail/templates/mail/output.html b/tests/regressiontests/mail/templates/mail/output.html
    new file mode 100644
    - +  
     1<p><strong>Mr. {{ user }}</strong>: Pay us $ {{ amt }} before next Friday.</p>
  • new file tests/regressiontests/mail/templates/mail/output.txt

    diff --git a/tests/regressiontests/mail/templates/mail/output.txt b/tests/regressiontests/mail/templates/mail/output.txt
    new file mode 100644
    - +  
     1{{ user }}: This is an important message. You owe us $ {{ amt }}.
  • tests/regressiontests/mail/tests.py

    diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
    a b  
    1414>>> from django.core.mail.backends.base import BaseEmailBackend
    1515>>> from django.core.mail.backends import console, dummy, locmem, filebased, smtp
    1616>>> from django.utils.translation import ugettext_lazy
     17>>> from django.template import Context, loader
    1718
    1819# Test normal ascii character case:
    1920
     
    204205JVBERi0xLjQuJS4uLg==
    205206...
    206207
     208# #13364
     209>>> subject, from_email, to = 'hello', 'from@example.com', '"Surname, Firstname" <to@example.com>'
     210>>> ctx = Context({'user': 'Joe', 'amt': '1000.00'})
     211>>> text_template = loader.get_template('mail/output.txt')
     212>>> html_template = loader.get_template('mail/output.html')
     213>>> text_content = text_template.render(ctx)
     214>>> html_content = html_template.render(ctx)
     215>>> msg = EmailMultiAlternatives('Message from Firstname Surname', text_content, from_email, [to])
     216>>> msg.attach_alternative(html_content, "text/html")
     217>>> print msg.message().as_string()
     218Content-Type: multipart/alternative; boundary="..."
     219MIME-Version: 1.0
     220Subject: Message from Firstname Surname
     221From: from@example.com
     222To: "Surname, Firstname" <to@example.com>
     223Date: ...
     224Message-ID: ...
     225<BLANKLINE>
     226...
     227Content-Type: text/plain; charset="utf-8"
     228MIME-Version: 1.0
     229Content-Transfer-Encoding: quoted-printable
     230<BLANKLINE>
     231Joe: This is an important message. You owe us $ 1000.00.
     232<BLANKLINE>
     233...
     234Content-Type: text/html; charset="utf-8"
     235MIME-Version: 1.0
     236Content-Transfer-Encoding: quoted-printable
     237<BLANKLINE>
     238<p><strong>Mr. Joe</strong>: Pay us $ 1000.00 before next Friday.</p>
     239<BLANKLINE>
     240...
     241
    207242# Make sure that the console backend writes to stdout by default
    208243>>> connection = console.EmailBackend()
    209244>>> email = EmailMessage('Subject', 'Content', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'})
Back to Top