mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
[5.0.x] Fixed #34923 -- Avoided initializing LEVEL_TAGS when importing django.contrib.messages.
Regression inb7fe36ad37. Thanks James Gillard for the report. Backport of311718feb5from main
This commit is contained in:
committed by
Natalia
parent
25fec8940b
commit
00805ff436
@@ -1,5 +1,6 @@
|
||||
from unittest import mock
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.messages import Message, add_message, constants
|
||||
from django.contrib.messages.storage import base
|
||||
from django.contrib.messages.test import MessagesTestMixin
|
||||
@@ -63,6 +64,26 @@ class TestLevelTags(SimpleTestCase):
|
||||
def test_override_settings_level_tags(self):
|
||||
self.assertEqual(base.LEVEL_TAGS, self.message_tags)
|
||||
|
||||
def test_lazy(self):
|
||||
# Don't use @override_settings to avoid calling the setting_changed
|
||||
# signal.
|
||||
old_message_tags = getattr(settings, "MESSAGE_TAGS", None)
|
||||
settings.MESSAGE_TAGS = {constants.ERROR: "bad"}
|
||||
try:
|
||||
self.assertEqual(base.LEVEL_TAGS[constants.ERROR], "bad")
|
||||
finally:
|
||||
if old_message_tags is None:
|
||||
del settings.MESSAGE_TAGS
|
||||
else:
|
||||
settings.MESSAGE_TAGS = old_message_tags
|
||||
|
||||
@override_settings(MESSAGE_TAGS=message_tags)
|
||||
def test_override_settings_lazy(self):
|
||||
# The update_level_tags handler has been called at least once before
|
||||
# running this code when using @override_settings.
|
||||
settings.MESSAGE_TAGS = {constants.ERROR: "very-bad"}
|
||||
self.assertEqual(base.LEVEL_TAGS[constants.ERROR], "very-bad")
|
||||
|
||||
|
||||
class FakeResponse:
|
||||
def __init__(self):
|
||||
|
||||
Reference in New Issue
Block a user