Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7773 -- Added some simple tests for EmailMessage. Thanks to se…

…rialx for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7975 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 825622d912aa8e87ddcda1af65edef9bb765e389 1 parent 69ac815
Russell Keith-Magee authored July 19, 2008
2  tests/regressiontests/mail/__init__.py
... ...
@@ -0,0 +1,2 @@
  1
+
  2
+
1  tests/regressiontests/mail/models.py
... ...
@@ -0,0 +1 @@
  1
+# This file intentionally left blank
41  tests/regressiontests/mail/tests.py
... ...
@@ -0,0 +1,41 @@
  1
+# coding: utf-8
  2
+r"""
  3
+# Tests for the django.core.mail.
  4
+
  5
+>>> from django.core.mail import EmailMessage
  6
+
  7
+# Test normal ascii character case:
  8
+
  9
+>>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'])
  10
+>>> message = email.message()
  11
+>>> message['Subject']
  12
+'Subject'
  13
+>>> message.get_payload()
  14
+'Content'
  15
+>>> message['From']
  16
+'from@example.com'
  17
+>>> message['To']
  18
+'to@example.com'
  19
+
  20
+# Test multiple-recipient case
  21
+
  22
+>>> email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com','other@example.com'])
  23
+>>> message = email.message()
  24
+>>> message['Subject']
  25
+'Subject'
  26
+>>> message.get_payload()
  27
+'Content'
  28
+>>> message['From']
  29
+'from@example.com'
  30
+>>> message['To']
  31
+'to@example.com, other@example.com'
  32
+
  33
+# Test for header injection
  34
+
  35
+>>> email = EmailMessage('Subject\nInjection Test', 'Content', 'from@example.com', ['to@example.com'])
  36
+>>> message = email.message()
  37
+Traceback (most recent call last):
  38
+    ...
  39
+BadHeaderError: Header values can't contain newlines (got 'Subject\nInjection Test' for header 'Subject')
  40
+
  41
+"""

0 notes on commit 825622d

Please sign in to comment.
Something went wrong with that request. Please try again.