test: add tests for person bio generation
This commit is contained in:
@@ -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"
|
||||
Reference in New Issue
Block a user