Wire freehire, Jobnet and Akademikernes Jobbank into the CLI, the Sources form, dupes and the docs
Provider names, the CLI's choices and the dupes rule's search hosts now come from readers.PROVIDERS, and the regions, work modes and remote words from the modules' REGIONS, MODES and REMOTE, read with getattr so main works before and after the readers merge. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
018a1ad895
commit
6e6e655203
16 files changed
+422
-39
No files matched your search
@@ -0,0 +1,72 @@
|
||||
"""Fixtures shared by the app's tests."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from types import ModuleType
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, ROOT.as_posix())
|
||||
|
||||
from plugins import readers # noqa: E402
|
||||
from plugins.readers import Filters, Reads # noqa: E402
|
||||
|
||||
|
||||
def _stub(name: str, label: str, params: dict[str, str], filters: Filters,
|
||||
**tables: dict[str, str]) -> ModuleType:
|
||||
"""A search provider as `plugins/readers/<name>.py` is planned to declare it:
|
||||
`NAME`, `LABEL`, `PARAMS`, `clean_params` and the tables that fill the
|
||||
form. Only what `app/` reads, and no listing, since a test that needs one
|
||||
fakes `plugins.search.run_search`. `clean_params` strips each value, lowers a
|
||||
country and refuses a region or remote word the tables do not hold."""
|
||||
module = ModuleType(f"plugins.readers.{name}")
|
||||
module.NAME, module.LABEL, module.PARAMS = name, label, params
|
||||
module.READS = Reads(scope="search", listing="paged", page_size=100, ceiling=10000,
|
||||
text="listing", complete="stated", filters=filters, places="one",
|
||||
robots="read: stub, checked 2026-10-03")
|
||||
for table, values in tables.items():
|
||||
setattr(module, table, values)
|
||||
allowed = {"region": tables.get("REGIONS"), "remote": tables.get("MODES")
|
||||
or tables.get("REMOTE")}
|
||||
|
||||
def clean_params(given: dict[str, Any]) -> dict[str, Any]:
|
||||
out = {key: str(value).strip() for key, value in given.items()}
|
||||
for key, known in allowed.items():
|
||||
if known is not None and out.get(key) and out[key] not in known:
|
||||
raise ValueError(f"{key} is not one of {', '.join(known)}")
|
||||
if "country" in out:
|
||||
out["country"] = out["country"].lower()
|
||||
return out
|
||||
|
||||
module.clean_params = clean_params
|
||||
return module
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def search_stubs(monkeypatch: pytest.MonkeyPatch) -> dict[str, ModuleType]:
|
||||
"""freehire, jobnet and jobbank as stub modules in `readers.PROVIDERS`, so
|
||||
the wiring is tested with or without the real readers merged; a real
|
||||
module of the name is replaced for the test."""
|
||||
stubs = {
|
||||
"freehire": _stub("freehire", "freehire (tech, many countries)",
|
||||
{"q": "query", "country": "country", "remote": "remote"},
|
||||
Filters(query="one", country="many", remote="one"),
|
||||
MODES={"remote": "Remote", "hybrid": "Hybrid", "onsite": "On-site"}),
|
||||
"jobnet": _stub("jobnet", "Jobnet (Denmark)", {"q": "query", "region": "place"},
|
||||
Filters(query="one", place="one"),
|
||||
REGIONS={"HovedstadenOgBornholm": "Hovedstaden og Bornholm",
|
||||
"Midtjylland": "Midtjylland"}),
|
||||
"jobbank": _stub("jobbank", "Akademikernes Jobbank (Denmark)",
|
||||
{"q": "query", "region": "place", "remote": "remote"},
|
||||
Filters(query="one", place="one", remote="one"),
|
||||
REGIONS={"2": "Storkøbenhavn", "8": "Østjylland"},
|
||||
REMOTE={"helt": "Fully remote", "delvist": "Partly remote"}),
|
||||
}
|
||||
for name, module in stubs.items():
|
||||
monkeypatch.setitem(readers.PROVIDERS, name, module)
|
||||
return stubs
|
||||
Reference in new issue
Block a user