Test the unread count in the push payload and its APNs badge mapping

Provider tests cover aps.badge, the invalid values that leave it out
and the unchanged Web Push body. Funnel tests cover the count for
single notifications, grouped and ungrouped users and an in-app channel
that is off. Written in the existing unit style; not executed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 04:06:15 +01:00
co-authored by Claude Sonnet 5.5
parent 585fab74a6
commit 6a5ed75072
3 changed files with 86 additions and 1 deletions
+33
View File
@@ -136,6 +136,39 @@ def test_apns_prepare_survives_an_empty_payload():
body = json.loads(providers.PROVIDERS["apns"].prepare({}))
assert body["aps"]["alert"]["title"] == "DevPlace"
assert body["url"] == "/notifications"
assert "badge" not in body["aps"]
def test_apns_prepare_maps_unread_to_the_icon_badge():
import json
from devplacepy.push import providers
apns = providers.PROVIDERS["apns"]
assert json.loads(apns.prepare({"unread": 7}))["aps"]["badge"] == 7
assert json.loads(apns.prepare({"unread": 0}))["aps"]["badge"] == 0
def test_apns_prepare_omits_the_badge_for_an_invalid_unread_count():
import json
from devplacepy.push import providers
apns = providers.PROVIDERS["apns"]
for unread in (None, -1, True, "3", 2.5):
assert "badge" not in json.loads(apns.prepare({"unread": unread}))["aps"]
def test_webpush_prepare_forwards_the_shared_payload_unchanged():
import json
from devplacepy.push import providers
payload = {
"title": "DevPlace",
"message": "hi",
"icon": "/static/apple-touch-icon.png",
"url": "/notifications",
"unread": 3,
}
assert json.loads(providers.PROVIDERS["webpush"].prepare(payload)) == payload
def _apns_settings(monkeypatch, **values):