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.
23 lines
759 B
Python
23 lines
759 B
Python
import pytest
|
|
from django.core import signing
|
|
|
|
from apps.notifications.api.views import _format_sse_event, _issue_stream_token_for_user, _safe_int, _validate_stream_token
|
|
|
|
|
|
pytestmark = pytest.mark.unit
|
|
|
|
|
|
def test_stream_token_round_trip_and_invalid_token():
|
|
token = _issue_stream_token_for_user("42")
|
|
assert _validate_stream_token(token) == "42"
|
|
with pytest.raises(signing.BadSignature):
|
|
_validate_stream_token("wrong")
|
|
with pytest.raises(signing.BadSignature):
|
|
_validate_stream_token(None)
|
|
|
|
|
|
def test_sse_formatter_and_safe_integer_limits():
|
|
assert _safe_int("-5", 10) == 0
|
|
assert _safe_int("oops", 10) == 10
|
|
assert 'event: connected\ndata: {"ready": true}\n\n' == _format_sse_event("connected", {"ready": True})
|