diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/check_framework/tests.py | 20 | ||||
| -rw-r--r-- | tests/file_storage/tests.py | 5 | ||||
| -rw-r--r-- | tests/mail/tests.py | 26 |
3 files changed, 50 insertions, 1 deletions
diff --git a/tests/check_framework/tests.py b/tests/check_framework/tests.py index e669b11c2b..9e461c5040 100644 --- a/tests/check_framework/tests.py +++ b/tests/check_framework/tests.py @@ -4,6 +4,7 @@ from io import StringIO from django.apps import apps from django.core import checks from django.core.checks import Error, Warning +from django.core.checks.messages import CheckMessage from django.core.checks.registry import CheckRegistry from django.core.management import call_command from django.core.management.base import CommandError @@ -74,6 +75,20 @@ class SystemCheckFrameworkTests(SimpleTestCase): def no_kwargs(app_configs, databases): pass + def test_register_run_checks_non_iterable(self): + registry = CheckRegistry() + + @registry.register + def return_non_iterable(**kwargs): + return Error('Message') + + msg = ( + 'The function %r did not return a list. All functions registered ' + 'with the checks registry must return a list.' % return_non_iterable + ) + with self.assertRaisesMessage(TypeError, msg): + registry.run_checks() + class MessageTests(SimpleTestCase): @@ -132,6 +147,11 @@ class MessageTests(SimpleTestCase): e = Error("Error", obj=DummyObj()) self.assertNotEqual(e, 'a string') + def test_invalid_level(self): + msg = 'The first argument should be level.' + with self.assertRaisesMessage(TypeError, msg): + CheckMessage('ERROR', 'Message') + def simple_system_check(**kwargs): simple_system_check.kwargs = kwargs diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index 6d17a7118b..381bc6b7b5 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -501,7 +501,10 @@ class FileStorageTests(SimpleTestCase): Calling delete with an empty name should not try to remove the base storage directory, but fail loudly (#20660). """ - with self.assertRaises(AssertionError): + msg = 'The name must be given to delete().' + with self.assertRaisesMessage(ValueError, msg): + self.storage.delete(None) + with self.assertRaisesMessage(ValueError, msg): self.storage.delete('') def test_delete_deletes_directories(self): 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): |
