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):
|
2022-02-03 19:24:19 +00:00
|
|
|
msg_1 = Message(constants.INFO, "Test message 1")
|
|
|
|
msg_2 = Message(constants.INFO, "Test message 2")
|
|
|
|
msg_3 = Message(constants.WARNING, "Test message 1")
|
2019-10-01 14:04:44 +00:00
|
|
|
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 = {
|
2022-02-03 19:24:19 +00:00
|
|
|
constants.INFO: "info",
|
|
|
|
constants.DEBUG: "",
|
|
|
|
constants.WARNING: "",
|
|
|
|
constants.ERROR: "bad",
|
|
|
|
constants.SUCCESS: "",
|
|
|
|
12: "custom",
|
2021-11-25 13:13:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override_settings(MESSAGE_TAGS=message_tags)
|
|
|
|
def test_override_settings_level_tags(self):
|
|
|
|
self.assertEqual(base.LEVEL_TAGS, self.message_tags)
|