Split backend tests into unit and integration suites, add isolated fixtures and coverage enforcement, and update CI and test documentation. Cover current authentication, content, notification, payment, media, and admin flows; fix behaviors revealed by the new tests. Validate both suites and the per-module gate against local PostgreSQL.
39 lines
2.1 KiB
Python
39 lines
2.1 KiB
Python
from datetime import timedelta
|
|
|
|
import pytest
|
|
from django.utils import timezone
|
|
|
|
from apps.notifications import services
|
|
|
|
|
|
pytestmark = pytest.mark.integration
|
|
|
|
|
|
def test_fake_redis_store_add_filter_mark_and_delete(fake_notification_redis, monkeypatch):
|
|
monkeypatch.setattr(services, "redis_client", fake_notification_redis)
|
|
first = services.RedisNotificationStore.add("user-1", {"type": "news", "title": "One", "body_markdown": "# Long body"})
|
|
second = services.RedisNotificationStore.add("user-1", {"type": "event", "title": "Two"})
|
|
assert services.RedisNotificationStore.unread_count("user-1") == 2
|
|
assert services.RedisNotificationStore.list("user-1", type_filter="news")[1] == 1
|
|
assert services.RedisNotificationStore.get("user-2", first["id"]) is None
|
|
marked = services.RedisNotificationStore.mark_seen("user-1", first["id"])
|
|
assert marked["unread_count"] == 1
|
|
assert services.RedisNotificationStore.list("user-1", read_filter="read")[1] == 1
|
|
assert services.RedisNotificationStore.mark_all_seen("user-1") == 2
|
|
assert services.RedisNotificationStore.unread_count("user-1") == 0
|
|
assert services.RedisNotificationStore.delete("user-1", second["id"])
|
|
assert not services.RedisNotificationStore.delete("user-1", second["id"])
|
|
assert services.RedisNotificationStore.get("user-1", second["id"]) is None
|
|
|
|
|
|
def test_fake_redis_store_cleans_expired_and_corrupt_records(fake_notification_redis, monkeypatch):
|
|
monkeypatch.setattr(services, "redis_client", fake_notification_redis)
|
|
old = (timezone.now() - timedelta(days=90)).isoformat()
|
|
expired = services.RedisNotificationStore.add("user-1", {"created_at": old, "title": "Old"})
|
|
recent = services.RedisNotificationStore.add("user-1", {"title": "Recent"})
|
|
assert services.RedisNotificationStore.cleanup_expired(retention_days=30) == 1
|
|
assert services.RedisNotificationStore.get("user-1", expired["id"]) is None
|
|
fake_notification_redis.hset(services.RedisNotificationStore._data_key("user-1"), recent["id"], "broken json")
|
|
assert services.RedisNotificationStore.list("user-1") == ([], 0)
|
|
assert services.RedisNotificationStore.get("user-1", recent["id"]) is None
|