]> littlesong.place Git - littlesongplace.git/commitdiff
Add notification test button
authorChris Fulljames <christianfulljames@gmail.com>
Tue, 26 Aug 2025 22:47:16 +0000 (18:47 -0400)
committerChris Fulljames <christianfulljames@gmail.com>
Tue, 26 Aug 2025 22:47:16 +0000 (18:47 -0400)
src/littlesongplace/push_notifications.py
src/littlesongplace/templates/settings.html
test/test_push_notifications.py

index c7184c960b6bfa68a4805c0f1590b13cd84dbc10..602758cc16bdfd229001f6f7571e2c0e5e8ea46b 100644 (file)
@@ -115,6 +115,12 @@ def update_settings():
 
     return {"status": "success"}
 
+@bp.get("/test")
+@auth.requires_login
+def test_subscriptions():
+    notify([g.userid], "Test Notification", "If you're seeing this, it worked!", "/", None)
+    return {"status": "success"}
+
 def get_user_subscriptions(userid):
     rows = db.query(
             """
@@ -170,7 +176,7 @@ def _do_push(app, userids, title, body, url, setting):
         for userid in userids:
             subs = get_user_subscriptions(userid)
             for subid, sub_settings, sub in subs:
-                if not (sub_settings & setting):
+                if (setting is not None) and not (sub_settings & setting):
                     continue  # This setting is disabled for this subscription
                 try:
                     if private_key:
index 42c3c7b151aea0a7aca72e2bfde3742cb8720633..5c957b49e223fc8b985d3da1955995f8fdd70726 100644 (file)
@@ -16,6 +16,8 @@
     <label><input type="checkbox" onclick="updateSettings()" id="song-push">Anyone uploads a new song (at most once per day)</label>
 </div>
 
+<button class="button" onclick="fetch('/push-notifications/test')">Test Notifications</button>
+
 <script>
 
 function updateSelections() {
index ca5bdb89315567f3a5c8a8a43c4270c537cf0634..75c0dadb423c5cf725eb8d6e7c1c0eddca12fedf 100644 (file)
@@ -144,7 +144,7 @@ def test_update_settings_ok(client, user, subid):
     response = client.get(f"/push-notifications/settings?subid={subid}")
     assert response.json["comments"] == True
     assert response.json["songs"] == True
-    
+
 def test_update_settings_not_logged_in(client):
     response = client.post(
             "/push-notifications/settings",
@@ -301,3 +301,12 @@ def test_subscription_not_deleted_on_500(pushmock, app, client, user, subid, vap
         lsp.push_notifications.wait_all()
         pushmock.assert_called_once()
 
+################################################################################
+# Notification self-test
+
+@mock.patch("pywebpush.webpush")
+def test_notification_self_test(pushmock, app, client, user, subid, vapid_keys):
+    client.get("/push-notifications/test")
+    lsp.push_notifications.wait_all()
+    pushmock.assert_called_once()
+