Files
andros d5377e94eb Initial implementation of push notification backend
Django backend that listens to the relay SSE global stream and dispatches
APNs push notifications to subscribed iOS devices (TestFlight/sandbox).
2026-05-19 09:34:46 +02:00

72 lines
2.5 KiB
Python

import pytest
from django.urls import reverse
from app.subscriptions.models import Device
@pytest.mark.django_db
class TestSubscribeView:
def test_subscribe_creates_device(self, client):
response = client.post(
reverse("subscribe"),
data={"feed": "https://example.com/social.org", "device_token": "abc123token"},
content_type="application/json",
)
assert response.status_code == 201
assert Device.objects.filter(device_token="abc123token").exists()
def test_subscribe_updates_existing_feed(self, client):
Device.objects.create(feed="https://old.org/social.org", device_token="abc123token")
response = client.post(
reverse("subscribe"),
data={"feed": "https://new.org/social.org", "device_token": "abc123token"},
content_type="application/json",
)
assert response.status_code == 200
assert Device.objects.get(device_token="abc123token").feed == "https://new.org/social.org"
def test_subscribe_missing_feed(self, client):
response = client.post(
reverse("subscribe"),
data={"device_token": "abc123token"},
content_type="application/json",
)
assert response.status_code == 400
def test_subscribe_missing_device_token(self, client):
response = client.post(
reverse("subscribe"),
data={"feed": "https://example.com/social.org"},
content_type="application/json",
)
assert response.status_code == 400
@pytest.mark.django_db
class TestUnsubscribeView:
def test_unsubscribe_removes_device(self, client):
Device.objects.create(feed="https://example.com/social.org", device_token="abc123token")
response = client.delete(
reverse("unsubscribe"),
data={"device_token": "abc123token"},
content_type="application/json",
)
assert response.status_code == 200
assert not Device.objects.filter(device_token="abc123token").exists()
def test_unsubscribe_not_found(self, client):
response = client.delete(
reverse("unsubscribe"),
data={"device_token": "nonexistent"},
content_type="application/json",
)
assert response.status_code == 404
def test_unsubscribe_missing_device_token(self, client):
response = client.delete(
reverse("unsubscribe"),
data={},
content_type="application/json",
)
assert response.status_code == 400