Skip to content

Commit af0f343

Browse files
pandafynemesifier
authored andcommitted
[fix] Fixed target URL in "config_error" notification type
Bug: The target_link callable was not returning the correct URL due to changes in openwisp-notifications. Fix: Updated the target_link callable for "config_error" notification type and improved test for better E2E testing.
1 parent 35dbfe5 commit af0f343

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

openwisp_controller/config/tests/test_notifications.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.apps.registry import apps
55
from django.conf import settings
66
from django.test import TransactionTestCase
7+
from django.urls import reverse
78
from requests.exceptions import RequestException
89
from swapper import load_model
910

@@ -40,6 +41,7 @@ def setUp(self):
4041

4142
def test_config_problem_notification(self):
4243
config = self._create_config()
44+
device = config.device
4345
config.set_status_error()
4446

4547
self.assertEqual(config.status, 'error')
@@ -53,8 +55,15 @@ def test_config_problem_notification(self):
5355
f'[example.com] ERROR: "{config.device}"'
5456
' configuration encountered an error',
5557
)
56-
self.assertIn('encountered an error', notification.message)
57-
self.assertEqual(notification.target_url.endswith('#config-group'), True)
58+
expected_target_url = ('https://example.com{}#config-group').format(
59+
reverse(f'admin:{self.app_label}_device_change', args=[device.id])
60+
)
61+
self.assertEqual(
62+
notification.message,
63+
f'<p>The configuration of <a href="{expected_target_url}">{device.name}</a>'
64+
' has encountered an error. The last working configuration has been'
65+
' restored from a backup present on the filesystem of the device.</p>',
66+
)
5867

5968
def test_device_registered(self):
6069
# To avoid adding repetitive code for registering a device,

openwisp_controller/config/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,5 @@ def get_default_templates_queryset(
203203

204204

205205
def get_config_error_notification_target_url(obj, field, absolute_url=True):
206-
url = _get_object_link(obj, field, absolute_url)
206+
url = _get_object_link(obj._related_object(field), absolute_url)
207207
return f'{url}#config-group'

0 commit comments

Comments
 (0)