From af5aa21e45402bef859ee6113d52b1dbf472a3e3 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 7 Jul 2026 12:39:43 -0400 Subject: [PATCH] test(translation): API endpoint tests for status + run (#143 step 6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /settings/translation/status defaults (off → no health call) + /run 400-when- unconfigured + 202-when-configured (monkeypatched .delay). requests is already a backend dep, so no requirements/ci-requirements change. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01CDgx8bQS5YrGRK76v8HUnM --- tests/test_api_settings.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_api_settings.py b/tests/test_api_settings.py index d6bfdc6..73ed908 100644 --- a/tests/test_api_settings.py +++ b/tests/test_api_settings.py @@ -53,6 +53,36 @@ async def test_translation_settings_defaults_and_patch(client): "/api/settings/import", json={"interpreter_base_url": 123})).status_code == 400 +@pytest.mark.asyncio +async def test_translation_status_defaults(client): + # Off + no URL → no network health call, healthy False (#143). + body = await (await client.get("/api/settings/translation/status")).get_json() + assert body["enabled"] is False + assert body["base_url_set"] is False + assert body["healthy"] is False + assert "untranslated_count" in body + + +@pytest.mark.asyncio +async def test_translation_run_requires_config(client): + resp = await client.post("/api/settings/translation/run") + assert resp.status_code == 400 # disabled / no base URL + + +@pytest.mark.asyncio +async def test_translation_run_enqueues_when_configured(client, monkeypatch): + monkeypatch.setattr( + "backend.app.tasks.translation.translate_posts.delay", + lambda *a, **k: type("R", (), {"id": "t1"})(), + ) + await client.patch("/api/settings/import", json={ + "translation_enabled": True, "interpreter_base_url": "http://i.lan", + }) + resp = await client.post("/api/settings/translation/run") + assert resp.status_code == 202 + assert (await resp.get_json())["celery_task_id"] == "t1" + + @pytest.mark.asyncio async def test_patch_rejects_non_object(client): resp = await client.patch("/api/settings/import", json=[1, 2, 3])