Skip to content

Commit 864739c

Browse files
authored
Fix bug with on site notification (#2478)
* Fix bug with on site notification It would help if the notification went to the correct user. * Fix tests * Replace monkey patched add_message with actual method for linting fix
1 parent ed4f90e commit 864739c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

readthedocs/notifications/backends.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Notification to message backends"""
22

33
from django.conf import settings
4-
from django.contrib.messages import add_message
54
from django.utils.module_loading import import_string
65
from messages_extends.constants import INFO_PERSISTENT
6+
from messages_extends import add_message
77

88
from readthedocs.core.utils import send_email
99

@@ -75,4 +75,5 @@ def send(self, notification):
7575
),
7676
level=LEVEL_MAPPING.get(notification.level, INFO_PERSISTENT),
7777
extra_tags='',
78+
user=notification.user,
7879
)

readthedocs/rtd_tests/tests/test_notifications.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import django_dynamic_fixture as fixture
55
from django.test import TestCase
66
from django.test.utils import override_settings
7+
from django.contrib.auth.models import User
78

89
from readthedocs.notifications import Notification
910
from readthedocs.notifications.backends import EmailBackend, SiteBackend
@@ -76,11 +77,13 @@ class TestNotification(Notification):
7677
context_object_name = 'foo'
7778

7879
build = fixture.get(Build)
80+
user = fixture.get(User)
7981
req = mock.MagicMock()
80-
notify = TestNotification(object=build, request=req)
82+
notify = TestNotification(object=build, request=req, user=user)
8183
backend = SiteBackend(request=req)
8284
backend.send(notify)
8385

8486
add_message.assert_has_calls([
85-
mock.call(level=21, request=req, message=mock.ANY, extra_tags='')
87+
mock.call(level=21, request=req, message=mock.ANY, extra_tags='',
88+
user=user)
8689
])

0 commit comments

Comments
 (0)