Add retry-safe scan completion notifications

This commit is contained in:
Joren de Graaf
2026-10-26 01:57:24 +01:00
parent 0e4077d8e3
commit 31266b1533
5 changed files with 68 additions and 11 deletions
+13 -1
View File
@@ -5,7 +5,7 @@ from django.test import TestCase
from django.urls import reverse
from .models import UserSettings
from .services.notifications import NotificationError, send_notification
from .services.notifications import NotificationError, send_notification, send_ntfy_notification
class NtfySettingsTests(TestCase):
@@ -47,3 +47,15 @@ class NtfySettingsTests(TestCase):
def test_disabled_preference_suppresses_delivery(self, sender):
self.assertFalse(send_notification(self.user, 'Title', 'Message'))
sender.assert_not_called()
@patch('planner.services.notifications.urlopen')
def test_send_ntfy_notification_includes_stable_sequence_id(self, urlopen):
response = Mock()
response.getcode.return_value = 200
urlopen.return_value.__enter__.return_value = response
send_ntfy_notification(self.topic, 'Title', 'Message', sequence_id='inventory-scan-123')
request = urlopen.call_args.args[0]
headers = {key.lower(): value for key, value in request.header_items()}
self.assertEqual(headers['x-sequence-id'], 'inventory-scan-123')