forked from django/django
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #35528 -- Added EmailMultiAlternatives.body_contains() helper m…
…ethod.
- Loading branch information
1 parent
7a0cd09
commit 5fef6d2
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -436,6 +436,26 @@ Django's email library, you can do this using the | |
msg.attach_alternative(html_content, "text/html") | ||
msg.send() | ||
|
||
.. method:: body_contains(text) | ||
|
||
.. versionadded:: 5.2 | ||
|
||
Returns a boolean indicating whether the provided ``text`` is | ||
contained in the email ``body`` and in all attached MIME type | ||
``text/*`` alternatives. | ||
|
||
This can be useful when testing emails. For example:: | ||
|
||
def test_contains_email_content(self): | ||
subject = "Hello World" | ||
from_email = "[email protected]" | ||
to = "[email protected]" | ||
msg = EmailMultiAlternatives(subject, "I am content.", from_email, [to]) | ||
msg.attach_alternative("<p>I am content.</p>", "text/html") | ||
|
||
self.assertIs(msg.body_contains("I am content"), True) | ||
self.assertIs(msg.body_contains("<p>I am content.</p>"), False) | ||
|
||
Updating the default content type | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters