Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
110 lines
3.6 KiB
Python
110 lines
3.6 KiB
Python
"""Integration (in-proc): RedditStoryService.thread_to_reel with a fake fetcher."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
import pytest
|
|
|
|
from app.domains.stories.contract import StoryDraftResult
|
|
from app.domains.stories.service import RedditStoryService, StoryIngestError
|
|
from app.domains.templates.service import instantiate_draft
|
|
|
|
_LISTING = [
|
|
{
|
|
"kind": "Listing",
|
|
"data": {
|
|
"children": [
|
|
{
|
|
"kind": "t3",
|
|
"data": {
|
|
"title": "AITA for locking my roommate out?",
|
|
"subreddit": "AmItheAsshole",
|
|
"author": "op_throwaway",
|
|
"selftext": (
|
|
"My roommate keeps eating my food. Last night I finally "
|
|
"snapped and changed the locks. Was I wrong?"
|
|
),
|
|
"selftext_html": "",
|
|
},
|
|
}
|
|
]
|
|
},
|
|
},
|
|
{
|
|
"kind": "Listing",
|
|
"data": {
|
|
"children": [
|
|
{"kind": "t1", "data": {"body": "NTA, set boundaries."}},
|
|
{"kind": "more", "data": {"body": "load more"}},
|
|
]
|
|
},
|
|
},
|
|
]
|
|
|
|
|
|
def _fake_fetch(_url: str) -> str:
|
|
return json.dumps(_LISTING)
|
|
|
|
|
|
def test_thread_to_reel_produces_submittable_draft():
|
|
result = RedditStoryService().thread_to_reel(
|
|
"https://www.reddit.com/r/AmItheAsshole/comments/abc/title/",
|
|
fetcher=_fake_fetch,
|
|
)
|
|
assert isinstance(result, StoryDraftResult)
|
|
# Normalized URL is the .json API form.
|
|
assert result.url.endswith(".json")
|
|
assert result.thread.subreddit == "AmItheAsshole"
|
|
assert result.thread.top_comments == ("NTA, set boundaries.",)
|
|
assert result.script.endswith("Comment if you want Part 2.")
|
|
|
|
draft = result.reel_draft
|
|
assert draft["layout"] == "split"
|
|
assert draft["background_id"] == "voxel-parkour"
|
|
|
|
# The draft is genuinely submittable: re-running it through the real template
|
|
# compiler validates it against JobCreateRequest without raising.
|
|
recompiled = instantiate_draft(
|
|
"minecraft-reddit-split",
|
|
{"story": result.script, "subject": result.thread.title},
|
|
)
|
|
assert recompiled["reel_draft"]["video_script"] == result.script
|
|
|
|
|
|
def test_thread_to_reel_uses_subject_override():
|
|
result = RedditStoryService().thread_to_reel(
|
|
"https://reddit.com/r/x/comments/abc/t/",
|
|
fetcher=_fake_fetch,
|
|
subject="Custom Subject",
|
|
)
|
|
assert result.reel_draft["video_subject"] == "Custom Subject"
|
|
|
|
|
|
def test_thread_to_reel_maps_bad_url_to_ingest_error():
|
|
with pytest.raises(StoryIngestError) as ei:
|
|
RedditStoryService().thread_to_reel("ftp://nope", fetcher=_fake_fetch)
|
|
assert ei.value.status_code == 400
|
|
|
|
|
|
def test_thread_to_reel_maps_malformed_json_to_422():
|
|
with pytest.raises(StoryIngestError) as ei:
|
|
RedditStoryService().thread_to_reel(
|
|
"https://reddit.com/r/x/comments/abc/t/", fetcher=lambda _u: "{bad json"
|
|
)
|
|
assert ei.value.status_code == 422
|
|
|
|
|
|
def test_thread_to_reel_does_not_persist(monkeypatch):
|
|
# No DB session factory should ever be constructed by the stateless flow.
|
|
import app.models.db.base as db_base
|
|
|
|
def _boom(*_a, **_k):
|
|
raise AssertionError("thread_to_reel must not touch the database")
|
|
|
|
monkeypatch.setattr(db_base, "get_session", _boom, raising=False)
|
|
result = RedditStoryService().thread_to_reel(
|
|
"https://reddit.com/r/x/comments/abc/t/", fetcher=_fake_fetch
|
|
)
|
|
assert result.reel_draft
|