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.
71 lines
2.7 KiB
Python
71 lines
2.7 KiB
Python
"""Caption keyword-SEO — keyword extraction + platform caption/hashtag build."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
|
|
from fastapi import FastAPI
|
|
from starlette.responses import JSONResponse
|
|
from starlette.testclient import TestClient
|
|
|
|
from app.models.exception import HttpException
|
|
from app.services.captions.keyword_seo import build_seo_caption, extract_keywords
|
|
from app.utils import utils
|
|
|
|
|
|
def test_extract_ranks_by_frequency_stopword_filtered():
|
|
text = "The parkour parkour minecraft story is the best minecraft story ever told"
|
|
kw = extract_keywords(text, limit=5)
|
|
# 'parkour' (2) and 'minecraft' (2) and 'story' (2) outrank singletons; 'the'/'is' dropped.
|
|
assert kw[:3] == ["parkour", "minecraft", "story"]
|
|
assert "the" not in kw and "is" not in kw
|
|
|
|
|
|
def test_build_caption_caps_hashtags_per_platform():
|
|
text = "glass cutting asmr satisfying kinetic sand soap oddly satisfying loop trigger"
|
|
shorts = build_seo_caption(text, platform="shorts") # max 5 hashtags
|
|
reels = build_seo_caption(text, platform="reels") # max 8 hashtags
|
|
assert len(shorts.hashtags) <= 5
|
|
assert len(reels.hashtags) <= 8
|
|
assert all(h.startswith("#") for h in shorts.hashtags)
|
|
|
|
|
|
def test_base_caption_leads_else_keywords_fill():
|
|
text = "movie recap thriller plot twist ending explained"
|
|
with_base = build_seo_caption(text, base_caption="You won't believe this ending")
|
|
assert with_base.caption.startswith("You won't believe")
|
|
without = build_seo_caption(text)
|
|
# No base -> keywords front-load the searchable caption (never empty).
|
|
assert without.caption and "recap" in without.caption or "movie" in without.caption
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
# Endpoint
|
|
# --------------------------------------------------------------------------- #
|
|
def _client():
|
|
mod = importlib.import_module("app.domains.captions.router")
|
|
app = FastAPI()
|
|
app.include_router(mod.router)
|
|
app.add_exception_handler(
|
|
HttpException,
|
|
lambda r, exc: JSONResponse(status_code=exc.status_code,
|
|
content=utils.get_response(exc.status_code, exc.data, exc.message)),
|
|
)
|
|
return TestClient(app)
|
|
|
|
|
|
def test_seo_endpoint():
|
|
client = _client()
|
|
resp = client.post("/api/v1/captions/seo", json={
|
|
"text": "minecraft parkour reddit story satisfying", "platform": "tiktok",
|
|
"base_caption": "This changed everything",
|
|
})
|
|
assert resp.status_code == 200
|
|
data = resp.json()["data"]
|
|
assert data["caption"].startswith("This changed")
|
|
assert len(data["hashtags"]) <= 5 and data["keywords"]
|
|
|
|
|
|
def test_seo_requires_text():
|
|
assert _client().post("/api/v1/captions/seo", json={"text": " "}).status_code == 422
|