2019-09-03 02:09:31 +00:00
|
|
|
from unittest import mock
|
|
|
|
|
2019-10-01 14:04:44 +00:00
|
|
|
from django.contrib.messages import constants
|
2021-11-25 13:13:16 +00:00
|
|
|
from django.contrib.messages.storage import base
|
2019-10-01 14:04:44 +00:00
|
|
|
from django.contrib.messages.storage.base import Message
|
2021-11-25 13:13:16 +00:00
|
|
|
from django.test import SimpleTestCase, override_settings
|
2019-10-01 14:04:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MessageTests(SimpleTestCase):
|
|
|
|
def test_eq(self):
|
|
|
|
msg_1 = Message(constants.INFO, 'Test message 1')
|
|
|
|
msg_2 = Message(constants.INFO, 'Test message 2')
|
|
|
|
msg_3 = Message(constants.WARNING, 'Test message 1')
|
|
|
|
self.assertEqual(msg_1, msg_1)
|
2019-09-03 02:09:31 +00:00
|
|
|
self.assertEqual(msg_1, mock.ANY)
|
2019-10-01 14:04:44 +00:00
|
|
|
self.assertNotEqual(msg_1, msg_2)
|
|
|
|
self.assertNotEqual(msg_1, msg_3)
|
|
|
|
self.assertNotEqual(msg_2, msg_3)
|
2021-11-25 13:13:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestLevelTags(SimpleTestCase):
|
|
|
|
message_tags = {
|
|
|
|
constants.INFO: 'info',
|
|
|
|
constants.DEBUG: '',
|
|
|
|
constants.WARNING: '',
|
|
|
|
constants.ERROR: 'bad',
|
|
|
|
constants.SUCCESS: '',
|
|
|
|
12: 'custom',
|
|
|
|
}
|
|
|
|
|
|
|
|
@override_settings(MESSAGE_TAGS=message_tags)
|
|
|
|
def test_override_settings_level_tags(self):
|
|
|
|
self.assertEqual(base.LEVEL_TAGS, self.message_tags)
|