mirror of
https://github.com/django/django.git
synced 2025-08-31 07:47:37 +00:00
Cosmetic edits for messages_tests.
This commit is contained in:
parent
944610a86c
commit
0793182694
8 changed files with 45 additions and 86 deletions
|
@ -14,7 +14,7 @@ class DummyStorage(object):
|
|||
self.store.append(message)
|
||||
|
||||
|
||||
class ApiTest(SimpleTestCase):
|
||||
class ApiTests(SimpleTestCase):
|
||||
def setUp(self):
|
||||
self.rf = RequestFactory()
|
||||
self.request = self.rf.request()
|
||||
|
@ -22,33 +22,23 @@ class ApiTest(SimpleTestCase):
|
|||
|
||||
def test_ok(self):
|
||||
msg = 'some message'
|
||||
|
||||
self.request._messages = self.storage
|
||||
messages.add_message(self.request, messages.DEBUG, msg)
|
||||
self.assertIn(msg, self.storage.store)
|
||||
|
||||
def test_request_is_none(self):
|
||||
msg = 'some message'
|
||||
|
||||
msg = "add_message() argument must be an HttpRequest object, not 'NoneType'."
|
||||
self.request._messages = self.storage
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
messages.add_message(None, messages.DEBUG, msg)
|
||||
|
||||
self.assertEqual([], self.storage.store)
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
messages.add_message(None, messages.DEBUG, 'some message')
|
||||
self.assertEqual(self.storage.store, [])
|
||||
|
||||
def test_middleware_missing(self):
|
||||
msg = 'some message'
|
||||
|
||||
with self.assertRaises(messages.MessageFailure):
|
||||
messages.add_message(self.request, messages.DEBUG, msg)
|
||||
|
||||
self.assertEqual([], self.storage.store)
|
||||
msg = 'You cannot add messages without installing django.contrib.messages.middleware.MessageMiddleware'
|
||||
with self.assertRaisesMessage(messages.MessageFailure, msg):
|
||||
messages.add_message(self.request, messages.DEBUG, 'some message')
|
||||
self.assertEqual(self.storage.store, [])
|
||||
|
||||
def test_middleware_missing_silently(self):
|
||||
msg = 'some message'
|
||||
|
||||
messages.add_message(self.request, messages.DEBUG, msg,
|
||||
fail_silently=True)
|
||||
|
||||
self.assertEqual([], self.storage.store)
|
||||
messages.add_message(self.request, messages.DEBUG, 'some message', fail_silently=True)
|
||||
self.assertEqual(self.storage.store, [])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue