From 474cc420bf6bc1067e2aaa4b40cf6a08d62096f7 Mon Sep 17 00:00:00 2001 From: Daniyal Date: Tue, 16 Mar 2021 21:11:27 +0530 Subject: Refs #32508 -- Raised Type/ValueError instead of using "assert" in django.core. --- tests/mail/tests.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/mail') diff --git a/tests/mail/tests.py b/tests/mail/tests.py index 475e204b32..de8ff159c0 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -529,6 +529,24 @@ class MailTests(HeadersCheckMixin, SimpleTestCase): self.assertEqual(content, b'\xff') self.assertEqual(mimetype, 'application/octet-stream') + def test_attach_mimetext_content_mimetype(self): + email_msg = EmailMessage() + txt = MIMEText('content') + msg = ( + 'content and mimetype must not be given when a MIMEBase instance ' + 'is provided.' + ) + with self.assertRaisesMessage(ValueError, msg): + email_msg.attach(txt, content='content') + with self.assertRaisesMessage(ValueError, msg): + email_msg.attach(txt, mimetype='text/plain') + + def test_attach_content_none(self): + email_msg = EmailMessage() + msg = 'content must be provided.' + with self.assertRaisesMessage(ValueError, msg): + email_msg.attach('file.txt', mimetype="application/pdf") + def test_dummy_backend(self): """ Make sure that dummy backends returns correct number of sent messages @@ -835,6 +853,14 @@ class MailTests(HeadersCheckMixin, SimpleTestCase): with self.assertRaisesMessage(ValueError, msg): sanitize_address(email_address, encoding='utf-8') + def test_email_multi_alternatives_content_mimetype_none(self): + email_msg = EmailMultiAlternatives() + msg = 'Both content and mimetype must be provided.' + with self.assertRaisesMessage(ValueError, msg): + email_msg.attach_alternative(None, 'text/html') + with self.assertRaisesMessage(ValueError, msg): + email_msg.attach_alternative('

content

', None) + @requires_tz_support class MailTimeZoneTests(SimpleTestCase): -- cgit v1.3