SurfSense/surfsense_backend/tests/integration/podcasts/test_cancel.py
CREDO23 c84525897b test(podcasts): relocate stateful tests to integration
Move the lifecycle service, Celery task bodies, and mark_failed coverage out of
DB-faking unit tests and into integration tests against a real Postgres, faking
only true externals (broker, object store, TTS, ffmpeg, billing, LLM). Add HTTP
slices for cancel, voices, scoping, and public-chat streaming. The unit tier is
now fake-free pure logic with no session doubles.
2026-06-11 06:27:00 +02:00

39 lines
1 KiB
Python

"""Cancelling a podcast: allowed while in flight, refused once terminal.
Cancellation is a user escape hatch from any non-terminal state; a podcast that
has already finished (READY) has no exit, so the disallowed transition surfaces
as 409.
"""
import pytest
from app.podcasts.persistence import PodcastStatus
pytestmark = pytest.mark.integration
BASE = "/api/v1/podcasts"
async def test_cancel_from_a_live_state_succeeds(
client, db_search_space, make_podcast
):
podcast = await make_podcast(
search_space_id=db_search_space.id, status=PodcastStatus.AWAITING_BRIEF
)
resp = await client.post(f"{BASE}/{podcast.id}/cancel")
assert resp.status_code == 200
assert resp.json()["status"] == "cancelled"
async def test_cancel_from_a_terminal_state_conflicts(
client, db_search_space, make_podcast
):
podcast = await make_podcast(
search_space_id=db_search_space.id, status=PodcastStatus.READY
)
resp = await client.post(f"{BASE}/{podcast.id}/cancel")
assert resp.status_code == 409