From eb5d6830a57f15bf0c5f2303baf7c0d840486276 Mon Sep 17 00:00:00 2001 From: Steven Tischer Date: Sat, 22 Aug 2026 14:12:03 +0200 Subject: [PATCH] test: add tests for person bio generation --- service/src/main/inse/persons/test_bio.py | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 service/src/main/inse/persons/test_bio.py diff --git a/service/src/main/inse/persons/test_bio.py b/service/src/main/inse/persons/test_bio.py new file mode 100644 index 00000000..87c7f4fd --- /dev/null +++ b/service/src/main/inse/persons/test_bio.py @@ -0,0 +1,52 @@ +import pytest + +from inse import config +from inse.persons import service + +NO_PERSON_FOUND = "No person found." + + +@pytest.fixture() +def anyio_backend(): + return "asyncio" + + +def elasticsearch_configured(): + return bool( + config.settings.elasticsearch_url and config.settings.elasticsearch_api_key + ) + + +def llm_configured(): + return bool( + config.settings.llm_api_url + and config.settings.llm_api_key + and config.settings.llm_model + ) + + +requires_elasticsearch = pytest.mark.skipif( + not elasticsearch_configured(), reason="Elasticsearch is not configured" +) +requires_elasticsearch_and_llm = pytest.mark.skipif( + not (elasticsearch_configured() and llm_configured()), + reason="Elasticsearch and/or LLM are not configured", +) + + +@pytest.mark.anyio +@requires_elasticsearch_and_llm +async def test_bio_is_generated_for_person(): + response = await service.generate_person_bio(author_id="A5093075883") + + assert response.bio != "No person found.", "author was not found in Elasticsearch" + assert response.bio != "Etwas ist schiefgelaufen." , "the LLM returned no valid bio" + assert len(response.bio) >= 10, f"bio is too short: {response.bio!r}" + + +@pytest.mark.anyio +@requires_elasticsearch +async def test_bio_reports_unknown_author(): + response = await service.generate_person_bio(author_id="A000") + + assert response.bio == "No person found.", "author was not found in Elasticsearch"