diff options
author | Daniyal <abbasi.daniyal98@gmail.com> | 2021-03-16 21:11:27 +0530 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-03-19 08:04:37 +0100 |
commit | 474cc420bf6bc1067e2aaa4b40cf6a08d62096f7 (patch) | |
tree | 1281ae03beab376bbc08c0741da3b91d285cc2e3 /tests/mail | |
parent | 37044817f9a57126d655f216019e8c8cca7c151b (diff) | |
download | django-474cc420bf6bc1067e2aaa4b40cf6a08d62096f7.tar.gz |
Refs #32508 -- Raised Type/ValueError instead of using "assert" in django.core.
Diffstat (limited to 'tests/mail')
-rw-r--r-- | tests/mail/tests.py | 26 |
1 files changed, 26 insertions, 0 deletions
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('<p>content</p>', None) + @requires_tz_support class MailTimeZoneTests(SimpleTestCase): |