clipwright/tests/test_channels_endpoint.py

41 lines
1.5 KiB
Python

"""GET /api/channels (PLAN #1, dashboard profile selector).
Pins the response shape ``{"channels": [{"slug", "name"}]}``, that the seeded
profiles show up with their display names, and that a malformed profile file is
skipped instead of breaking the list.
"""
import asyncio
import httpx
import pytest
app_module = pytest.importorskip("clipwright.api.app")
def _get(path):
async def _do():
transport = httpx.ASGITransport(app=app_module.app)
async with httpx.AsyncClient(transport=transport,
base_url="http://testserver") as client:
return await client.get(path)
return asyncio.run(_do())
def test_returns_seeded_profiles_with_display_names():
resp = _get("/api/channels")
assert resp.status_code == 200
data = resp.json()
assert set(data) == {"channels"}
by_slug = {item["slug"]: item["name"] for item in data["channels"]}
assert by_slug["cseea"] == "cseea"
assert by_slug["pedro"] == "Pedro Bento"
assert all(set(item) == {"slug", "name"} for item in data["channels"])
def test_skips_malformed_profile_files(monkeypatch, tmp_path):
(tmp_path / "good.json").write_text('{"name": "Good"}', encoding="utf-8")
(tmp_path / "broken.json").write_text("{ not json", encoding="utf-8")
monkeypatch.setattr(app_module.profiles, "CHANNELS_DIR", tmp_path)
resp = _get("/api/channels")
assert resp.status_code == 200
assert resp.json() == {"channels": [{"slug": "good", "name": "Good"}]}