"""Personio: every office of a role, the level and the employment it states. No network: the fixtures are saved feeds.""" from __future__ import annotations import logging import sys from pathlib import Path import pytest ROOT = Path(__file__).resolve().parents[1] if str(ROOT) not in sys.path: sys.path.insert(0, str(ROOT)) from app.models import SENIORITIES # noqa: E402 from plugins.readers import Ask, personio # noqa: E402 FIXTURES = ROOT / "tests" / "fixtures" / "ats" def _rows() -> list[dict]: return personio.parse((FIXTURES / "personio-places.xml").read_bytes(), "acme") def test_the_declaration_says_what_the_feed_gives() -> None: reads = personio.READS assert (reads.listing, reads.places, reads.text) == ("whole", "many", "listing") assert reads.fields.posted == "trusted" and reads.fields.seniority == "stated" assert reads.robots.startswith("api: no robots.txt check needed") assert not hasattr(personio, "robots_page") assert personio.feed_url("acme", Ask()) == "https://acme.jobs.personio.de/xml" def test_additional_offices_are_places_of_the_role_each_once() -> None: first = _rows()[0] assert [p["text"] for p in first["places"]] == ["Remote - Germany", "Berlin", "Hamburg"] assert [p["remote"] for p in first["places"]] == [True, None, None] assert first["location"] == "Remote - Germany; Berlin; Hamburg" assert first["remote"] is True # one of the places is remote assert _rows()[1]["places"] == [{"text": "Munich", "remote": None}] assert _rows()[1]["remote"] is None def test_the_stated_level_and_employment_are_mapped() -> None: rows = _rows() assert [r["seniority"] for r in rows] == ["junior", "exec", "intern"] # permanent + full-time; permanent + full-time; working student wins over part-time assert [r["employment"] for r in rows] == ["full_time", "full_time", "internship"] def test_the_table_speaks_the_apps_vocabulary_and_a_new_word_is_logged( caplog: pytest.LogCaptureFixture) -> None: assert {v for v in personio._SENIORITY.values() if v} <= set(SENIORITIES) with caplog.at_level(logging.DEBUG, logger=personio.__name__): assert personio._seniority("wizard") is None assert personio._seniority("experienced") is None # known, names no level assert personio._seniority("") is None assert [r.getMessage() for r in caplog.records] == ["personio: unknown seniority 'wizard'"]