Read big boards within the agents' reach: countries and remote from the enabled agents, Europe for favourites, filtered at the source by six hosts

app/jobs/reach.py derives each board's reach once per pull and the pull hands it to the runner through the batch payload. SmartRecruiters, Eightfold and SuccessFactors filter one country a request, Phenom a list, Workday and Oracle by host ids from facets. Remote beside countries is a series of its own, since two facets intersect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-30 09:55:18 +02:00
1 parent 3adafd8950
commit 3462a4abe7
17 files changed
+1324 -116

No files matched your search

+87
View File
@@ -0,0 +1,87 @@
{
"items": [
{
"SearchId": 1,
"Facets": "LOCATIONS;WORKPLACE_TYPES",
"Offset": 0,
"Limit": 1,
"TotalJobsCount": 550,
"SiteNumber": "CX_1",
"locationsFacet": [
{
"Id": 300000000480126,
"Name": "United States",
"TotalCount": 215
},
{
"Id": 300000000471745,
"Name": "India",
"TotalCount": 123
},
{
"Id": 300000000471544,
"Name": "Canada",
"TotalCount": 79
},
{
"Id": 300000000471982,
"Name": "Portugal",
"TotalCount": 38
},
{
"Id": 300000000471904,
"Name": "Malaysia",
"TotalCount": 31
},
{
"Id": 300000000471640,
"Name": "Finland",
"TotalCount": 23
},
{
"Id": 300000000471967,
"Name": "Poland",
"TotalCount": 21
},
{
"Id": 300000000480081,
"Name": "Thailand",
"TotalCount": 17
},
{
"Id": 300000000471760,
"Name": "Italy",
"TotalCount": 12
},
{
"Id": 300000000471601,
"Name": "Germany",
"TotalCount": 10
}
],
"workplaceTypesFacet": [
{
"Id": "ORA_HYBRID",
"Name": "Hybrid",
"TotalCount": 317
},
{
"Id": "ORA_ON_SITE",
"Name": "Onsite",
"TotalCount": 230
},
{
"Id": "ORA_REMOTE",
"Name": "Remote",
"TotalCount": 3
}
],
"categoriesFacet": [],
"requisitionList": []
}
],
"count": 1,
"hasMore": false,
"limit": 25,
"offset": 0
}
+109
View File
@@ -0,0 +1,109 @@
{
"total": 455,
"jobPostings": [],
"facets": [
{
"facetParameter": "Location",
"descriptor": "Location",
"values": [
{
"descriptor": "United States of America",
"id": "bc33aa3152ec42d4995f4791a106ed09",
"count": 173
},
{
"descriptor": "Denmark",
"id": "49ab063f422741e2aef271de00efeac8",
"count": 97
},
{
"descriptor": "China",
"id": "6cb77610a8a543aea2d6bc10457e35d4",
"count": 30
},
{
"descriptor": "United Kingdom",
"id": "29247e57dbaf46fb855b224e03170bc7",
"count": 29
},
{
"descriptor": "Czechia",
"id": "fc078443155c4ad294201ecf5a61a499",
"count": 25
},
{
"descriptor": "Hungary",
"id": "9db257f5937e4421b2fac64eec6832f8",
"count": 21
},
{
"descriptor": "Germany",
"id": "dcc5b7608d8644b3a93716604e78e995",
"count": 18
},
{
"descriptor": "Vietnam",
"id": "db69e8c8446c11de98360015c5e6daf6",
"count": 17
}
]
},
{
"facetParameter": "timeType",
"descriptor": "Time Type",
"values": [
{
"descriptor": "Full time",
"id": "07564020a44510063cb1bcb298e20001",
"count": 270
},
{
"descriptor": "Part time",
"id": "07564020a44510063cb1bcb298e20000",
"count": 162
}
]
},
{
"facetParameter": "locationMainGroup",
"values": [
{
"facetParameter": "locationRegionStateProvince",
"descriptor": "Region/State/Province",
"values": [
{
"descriptor": "Alabama",
"id": "31475924e5494080a8a458bf4fa293ed",
"count": 2
},
{
"descriptor": "Alberta",
"id": "588eb24f950e4c5b93d5ad3f37aebad2",
"count": 3
},
{
"descriptor": "Arizona",
"id": "c7b20b0d4bc04711a00900569e9afabd",
"count": 4
},
{
"descriptor": "Arkansas",
"id": "cea6c5355e1b4983b5fd0640310385b5",
"count": 1
},
{
"descriptor": "Bavaria",
"id": "bd89fff5ffa6440a9abeaf2c5c1dc37c",
"count": 1
},
{
"descriptor": "Beijing",
"id": "4b194fc4ae3b4cbe95a1b379454e1775",
"count": 1
}
]
}
]
}
]
}
+2 -2
View File
@@ -204,10 +204,10 @@ def test_discovery_reads_the_host_and_domain_from_a_link_that_has_both() -> None
assert "eightfold" not in {h for h, _ in discover._UNREADABLE if h not in readers.HOSTS}
def test_it_declares_a_paged_read_of_ten_with_a_total_and_no_filter_yet() -> None:
def test_it_declares_a_paged_read_of_ten_with_a_total_and_one_country_a_request() -> None:
reads = eightfold.READS
assert (reads.listing, reads.page_size, reads.text, reads.complete, reads.places) == (
"paged", 10, "detail", "stated", "many")
assert reads.filters.declared() == {} and reads.fields.posted == "listed"
assert reads.filters.declared() == {"country": "one"} and reads.fields.posted == "listed"
assert reads.robots.startswith("read: robots.txt allows /careers")
assert not hasattr(eightfold, "robots_page")
+212
View File
@@ -0,0 +1,212 @@
"""The reach of a pull (`app.jobs.reach`): from the enabled agents' gates and
favourites to each board's `reach`, and through the pull's batches to the
runner's `Ask`. No network: the runner's listing is stubbed."""
from __future__ import annotations
import sys
from pathlib import Path
from typing import ClassVar
import pytest
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from pipeline import Tally # noqa: E402
from app.jobs import pull, reach # noqa: E402
from app.models import Gate # noqa: E402
from app.storage import Store # noqa: E402
from plugins.readers import Ask, _runner # noqa: E402
EUROPE = ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IE",
"IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE", "IS",
"LI", "NO", "GB", "CH", "EU"]
class FakeConfig:
sources: ClassVar[dict[str, object]] = {}
searches: ClassVar[list[object]] = []
@pytest.fixture
def store(tmp_path: Path) -> Store:
return Store(tmp_path / "roledesk.db")
def _wolf(store: Store, **extra: object) -> int:
"""The live agent 2 of 2026-09-30: Europe required, Denmark, Sweden, remote
or a town in Skåne or Denmark."""
gates = [Gate(field="country", values=EUROPE, mode="require"),
Gate(field="country", values=["DK", "SE"], mode="any"),
Gate(field="remote", values=["remote"], mode="any"),
Gate(field="place", values=["Malmö", "Lund", "copenhagen", "odense"], mode="any"),
Gate(field="remote", values=["hybrid"], mode="prefer", weight=0.05)]
return store.save_agent("Wolf", gates=gates, **extra).id # type: ignore[arg-type]
def _board(store: Store, target: str, company: str, size: int | None = 1000,
params: dict[str, object] | None = None) -> None:
store.add_subscription("ats", target, label=company, company=company,
board=target.partition(":")[0], params=params or {})
store.add_company(company)
if size is not None:
store.state[f"ats:size:{target}"] = str(size)
# ------------------------------------------------------------------ gates
def test_the_base_reach_is_the_union_of_the_any_gates_with_towns_as_countries(
store: Store) -> None:
_wolf(store)
store.save_agent("Berlin", gates=[Gate(field="place", values=["Berlin"], mode="any")])
plan = reach.plan(store)
assert plan.base == reach.Reach(frozenset({"DK", "SE", "DE"}), remote=True)
assert plan.base.params() == {"countries": ["DE", "DK", "SE"], "remote": True}
@pytest.mark.parametrize("gates", [
[],
[Gate(field="country", values=["DK"], mode="any"),
Gate(field="function", values=["engineering"], mode="any")],
[Gate(field="remote", values=["hybrid"], mode="any")],
[Gate(field="place", values=["Nowhereville"], mode="any")],
], ids=["no any gates", "a function in the group", "hybrid anywhere", "an unknown town"])
def test_an_agent_that_can_take_a_role_from_anywhere_makes_the_reach_everywhere(
store: Store, gates: list[Gate]) -> None:
_wolf(store)
store.save_agent("Other", gates=gates)
assert reach.plan(store).base == reach.EVERYWHERE
def test_an_agent_switched_off_does_not_widen_the_reach(store: Store) -> None:
_wolf(store)
store.save_agent("Off", gates=[], enabled=False)
assert reach.plan(store).base.countries == {"DK", "SE"}
def test_with_no_agent_switched_on_every_board_is_read_whole(store: Store) -> None:
_wolf(store, enabled=False)
assert reach.plan(store).base == reach.EVERYWHERE
def test_the_require_reach_intersects_and_expands_europe(store: Store) -> None:
gaz = store.gazetteer()
agent = store.agent(_wolf(store))
assert agent is not None
europe = reach.require_reach(agent, gaz)
assert {"DK", "SE", "DE", "FR", "GB", "NO", "CH"} <= europe.countries
assert "US" not in europe.countries and "EU" not in europe.countries
narrower = agent.model_copy(update={"gates": [
*agent.gates, Gate(field="country", values=["DK", "US"], mode="require")]})
assert reach.require_reach(narrower, gaz) == reach.Reach(frozenset({"DK"}))
plain = agent.model_copy(update={"gates": []})
assert reach.require_reach(plain, gaz) == reach.EVERYWHERE
# ------------------------------------------------------------- per board
def test_a_favourite_is_read_across_the_require_reach(store: Store) -> None:
wolf = _wolf(store)
_board(store, "smartrecruiters:mistral", "Mistral AI")
_board(store, "smartrecruiters:acme", "Acme")
store.set_affinity(wolf, "mistral-ai", 2)
plan = reach.plan(store)
subs = {s.target: s for s in store.subscriptions(source="ats")}
favourite, why = plan.why(subs["smartrecruiters:mistral"])
assert why == "favourite" and {"DE", "FR", "DK"} <= favourite.countries
assert plan.why(subs["smartrecruiters:acme"]) == (plan.base, "agents")
def test_a_company_starred_by_one_agent_keeps_the_others_reach(store: Store) -> None:
wolf = _wolf(store)
store.save_agent("Anywhere", gates=[Gate(field="country", values=["US"], mode="any")])
_board(store, "smartrecruiters:mistral", "Mistral AI")
store.set_affinity(wolf, "mistral-ai", 2)
favourite = reach.plan(store).favourites["mistral-ai"]
assert "US" in favourite.countries and "FR" in favourite.countries
@pytest.mark.parametrize("size, params, why", [
(299, {}, "small"),
(None, {}, "unknown"),
(5000, {"reach": "all"}, "override"),
(5000, {"countries": ["DE"]}, "override"),
(300, {}, "agents"),
])
def test_small_unknown_and_overridden_boards_get_no_reach(
store: Store, size: int | None, params: dict[str, object], why: str) -> None:
_wolf(store)
_board(store, "workday:acme.wd3/Jobs", "Acme", size, params)
[sub] = store.subscriptions(source="ats")
found, said = reach.plan(store).why(sub)
assert said == why
assert (found.params() is None) == (why != "agents")
def test_a_board_read_before_sizes_were_kept_is_sized_by_its_open_roles(store: Store) -> None:
_board(store, "workday:acme.wd3/Jobs", "Acme", size=None)
[sub] = store.subscriptions(source="ats")
store.state["ats:ok:workday:acme.wd3/Jobs"] = "run-0"
assert reach.sizes(store, [sub]) == {"workday:acme.wd3/Jobs": 0}
# A filtered board's open roles are not its size.
store.state["ats:filtered:workday:acme.wd3/Jobs"] = "1"
assert reach.sizes(store, [sub]) == {}
def test_describe_is_short() -> None:
assert reach.Reach(frozenset({"SE", "DK"}), True).describe() == "DK, SE, remote"
assert reach.Reach(frozenset(EUROPE[:10])).describe() == "10 countries"
assert reach.EVERYWHERE.describe() == "everywhere"
# ---------------------------------------------------------------- the pull
def _row(job_id: str) -> dict[str, object]:
return {"source_id": job_id, "title": f"Engineer {job_id}", "url": f"https://x.example/{job_id}",
"places": [{"text": "Copenhagen", "remote": None}], "posted": None,
"description": "", "remote": None, "salary_text": ""}
def _pull(store: Store) -> list[dict[str, object]]:
batches = pull._boards(FakeConfig(), store) # type: ignore[arg-type]
results = [pull.run_batch(FakeConfig(), store, **batch) # type: ignore[arg-type]
for batch in batches]
pull.close_boards(FakeConfig(), store, Tally(results=tuple(results))) # type: ignore[arg-type]
return batches
def test_the_pull_hands_each_board_its_reach_and_the_runner_narrows_it(
store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
_wolf(store)
_board(store, "smartrecruiters:BoschGroup", "Bosch")
_board(store, "smartrecruiters:tiny", "Tiny", size=12)
asked: dict[str, Ask] = {}
def fake(module: object, slug: str, get: object, ask: Ask, **kwargs: object
) -> _runner.Listing:
asked[slug] = ask
return _runner.Listing([_row("1")], True, ["1"], _runner.filtered(ask)) # type: ignore[list-item]
monkeypatch.setattr(_runner, "read_listing", fake)
[batch] = _pull(store)
assert batch["reach"] == {"smartrecruiters:BoschGroup": {"countries": ["DK", "SE"],
"remote": True}}
# SmartRecruiters filters countries one a request and cannot ask for remote.
assert asked["BoschGroup"] == Ask(countries=("DK", "SE"))
assert asked["tiny"] == Ask()
assert store.state["ats:filtered:smartrecruiters:BoschGroup"] == "1"
# The small board, read whole, keeps its size; the filtered one keeps its last.
assert store.state["ats:size:smartrecruiters:tiny"] == "1"
assert store.state["ats:size:smartrecruiters:BoschGroup"] == "1000"
def test_a_batch_queued_before_the_reach_existed_still_runs(
store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
_board(store, "smartrecruiters:acme", "Acme")
monkeypatch.setattr(_runner, "read_listing", lambda *a, **k: _runner.Listing(
[_row("1")], True, ["1"])) # type: ignore[list-item]
result = pull.run_batch(FakeConfig(), store, # type: ignore[arg-type]
targets=["smartrecruiters:acme"], run="r")
assert result["roles"] == 1
+268
View File
@@ -0,0 +1,268 @@
"""Filtering at the source: what the six hosts that filter by country (and
Workday and Oracle by remote) send for an `Ask`, their `facets`, and the
runner's series for a reach of countries and remote. Against saved answers;
no network."""
from __future__ import annotations
import json
import sys
from pathlib import Path
from typing import Any
from urllib.parse import parse_qs, unquote, urlsplit
import pytest
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from plugins.readers import ( # noqa: E402
Ask, _countries, _runner, eightfold, oracle, phenom, smartrecruiters, successfactors,
workday,
)
FIXTURES = ROOT / "tests" / "fixtures" / "ats"
class Recorder:
"""A `get` that answers `body` to every request and keeps what was asked."""
def __init__(self, body: bytes) -> None:
self.body = body
self.asked: list[tuple[str, dict[str, Any] | None]] = []
def __call__(self, url: str, *, method: str = "GET", payload: dict[str, Any] | None = None,
headers: dict[str, str] | None = None) -> bytes:
self.asked.append((url, payload))
return self.body
def _query(url: str) -> dict[str, list[str]]:
return parse_qs(urlsplit(url).query)
# ------------------------------------------------------------ declarations
def test_the_six_hosts_declare_what_their_search_filters() -> None:
declared = {module.NAME: module.READS.filters.declared() for module in
(smartrecruiters, eightfold, workday, successfactors, phenom, oracle)}
assert declared == {
"smartrecruiters": {"country": "one"},
"eightfold": {"country": "one"},
"workday": {"country": "ids", "remote": "ids"},
"successfactors": {"country": "one"},
"phenom": {"country": "many"},
"oracle": {"country": "ids", "remote": "one"},
}
def test_country_names_read_both_ways_with_the_hosts_own_spellings() -> None:
assert _countries.name_of("dk") == "Denmark" and _countries.name_of("ZZ") == ""
assert _countries.code_of("United States of America") == "US"
assert _countries.code_of("Korea, Republic of") == "KR"
assert _countries.code_of(" czech republic ") == "CZ"
assert _countries.code_of("Türkiye") == "TR" and _countries.code_of("Turkey") == "TR"
assert _countries.code_of("Atlantis") == ""
assert successfactors._COUNTRIES["SE"] == "Sweden"
# -------------------------------------------------------- one a request
def test_smartrecruiters_asks_one_country_in_lower_case() -> None:
get = Recorder(b'{"content": [], "totalFound": 0}')
smartrecruiters.page(get, "BoschGroup", None, Ask(countries=("DK",)))
smartrecruiters.page(get, "BoschGroup", 100, Ask())
assert _query(get.asked[0][0])["country"] == ["dk"]
assert "country" not in _query(get.asked[1][0])
def test_eightfold_asks_one_country_by_its_english_name() -> None:
get = Recorder(b'{"status": 200, "data": {"positions": [], "count": 0}}')
eightfold.page(get, "jobs.ericsson.com/ericsson.com", None, Ask(countries=("SE",)))
eightfold.page(get, "jobs.ericsson.com/ericsson.com", None, Ask(countries=("GB",)))
eightfold.page(get, "jobs.ericsson.com/ericsson.com", None, Ask(countries=("ZZ",)))
assert _query(get.asked[0][0])["location"] == ["Sweden"]
assert _query(get.asked[1][0])["location"] == ["United Kingdom"]
# A code with no name is read unfiltered: a superset, never too little.
assert "location" not in _query(get.asked[2][0])
def test_successfactors_asks_one_country_by_its_facet() -> None:
body = (FIXTURES / "successfactors-table.html").read_bytes()
get = Recorder(body)
successfactors.page(get, "careers.vestas.com", None, Ask(countries=("DK",)))
successfactors.page(get, "jobs.teradyne.com/MiR", None, Ask(countries=("DE",)))
successfactors.page(get, "careers.vestas.com", None, Ask())
assert get.asked[0][0] == ("https://careers.vestas.com/search/?q=&locationsearch="
"&optionsFacetsDD_country=DK&startrow=0")
assert get.asked[1][0].startswith("https://jobs.teradyne.com/MiR/search/?")
assert _query(get.asked[1][0])["optionsFacetsDD_country"] == ["DE"]
assert "optionsFacetsDD_country" not in get.asked[2][0]
# ------------------------------------------------------------ a list
def test_phenom_asks_every_country_by_name_in_one_request() -> None:
get = Recorder((FIXTURES / "phenom.json").read_bytes())
phenom.page(get, "www.careers.philips.com/global/en", None,
Ask(countries=("NL", "DE", "ZZ")))
phenom.page(get, "www.careers.philips.com/global/en", None, Ask())
phenom.page(get, "www.careers.philips.com/global/en", None, Ask(countries=("ZZ",)))
assert get.asked[0][1]["selected_fields"] == {"country": ["Netherlands", "Germany"]}
assert get.asked[1][1]["selected_fields"] == {}
assert get.asked[2][1]["selected_fields"] == {}
# ------------------------------------------------------------ host ids
LEGO = "lego.wd103/LEGO_External"
def _workday_facets(**extra: Any) -> dict[str, Any]:
saved = json.loads((FIXTURES / "workday-facets.json").read_text())
saved["facets"] += extra.get("facets", [])
return saved
def test_workday_facets_find_the_facet_of_countries_and_the_remote_values() -> None:
remote = {"facetParameter": "remoteType", "descriptor": "Remote Type", "values": [
{"descriptor": "Fully Flexible", "id": "ff1", "count": 30},
{"descriptor": "Hybrid", "id": "hy1", "count": 20},
{"descriptor": "Remote", "id": "rm1", "count": 3}]}
get = Recorder(json.dumps(_workday_facets(facets=[remote])).encode())
found = workday.facets(get, LEGO)
assert found["country"]["DK"] == "Location=49ab063f422741e2aef271de00efeac8"
assert found["country"]["US"] == "Location=bc33aa3152ec42d4995f4791a106ed09"
# The regions nested under `locationMainGroup` and the time types are
# not countries.
assert all(v.startswith("Location=") for v in found["country"].values())
assert found["remote"] == {"fully flexible": "remoteType=ff1", "remote": "remoteType=rm1"}
url, payload = get.asked[0]
assert url == "https://lego.wd103.myworkdayjobs.com/wday/cxs/lego/LEGO_External/jobs"
assert payload == {"appliedFacets": {}, "limit": 1, "offset": 0, "searchText": ""}
def test_workday_facets_of_a_tenant_without_remote_state_no_remote() -> None:
found = workday.facets(Recorder(json.dumps(_workday_facets()).encode()), LEGO)
assert set(found) == {"country"}
def test_workday_applies_the_host_ids_grouped_by_facet() -> None:
get = Recorder(b'{"total": 0, "jobPostings": []}')
workday.page(get, LEGO, None, Ask(countries=("Location=a", "Location=b")))
workday.page(get, LEGO, None, Ask(remote=True, remote_ids=("remoteType=r", "Location=x")))
workday.page(get, LEGO, None, Ask())
assert get.asked[0][1]["appliedFacets"] == {"Location": ["a", "b"]}
assert get.asked[1][1]["appliedFacets"] == {"remoteType": ["r"], "Location": ["x"]}
assert get.asked[2][1]["appliedFacets"] == {}
POD = "fa-evmr-saasfaprod1.fa.ocs.oraclecloud.com/CX_1"
def test_oracle_facets_map_the_listed_countries_and_mark_the_rest_unknown() -> None:
get = Recorder((FIXTURES / "oracle-facets.json").read_bytes())
found = oracle.facets(get, POD)["country"]
assert found["FI"] == "300000000471640" and found["US"] == "300000000480126"
# Ten listed: the pod lists only its biggest, so Denmark may be there.
assert found["DK"] == "*"
assert "facetsList=LOCATIONS" in get.asked[0][0] and "expand" not in get.asked[0][0]
def test_oracle_facets_of_a_short_list_leave_the_rest_out() -> None:
saved = json.loads((FIXTURES / "oracle-facets.json").read_text())
saved["items"][0]["locationsFacet"] = saved["items"][0]["locationsFacet"][:3]
found = oracle.facets(Recorder(json.dumps(saved).encode()), POD)["country"]
assert set(found) == {"US", "IN", "CA"}
def test_oracle_selects_locations_and_remote_in_the_finder() -> None:
get = Recorder(b'{"items": [{"requisitionList": [], "TotalJobsCount": 0}]}')
oracle.page(get, POD, None, Ask(countries=("300000000471640", "300000000480126")))
oracle.page(get, POD, None, Ask(remote=True))
oracle.page(get, POD, None, Ask(countries=("300000000471640", "*")))
finders = [unquote(_query(url)["finder"][0]) for url, _ in get.asked]
assert finders[0] == ("findReqs;siteNumber=CX_1,selectedLocationsFacet="
"300000000471640;300000000480126,limit=200,offset=0")
assert finders[1] == ("findReqs;siteNumber=CX_1,selectedWorkplaceTypesFacet=ORA_REMOTE,"
"limit=200,offset=0")
# A country the pod did not list: the series reads the whole board.
assert finders[2] == "findReqs;siteNumber=CX_1,limit=200,offset=0"
# --------------------------------------------------------------- series
def test_countries_and_remote_are_two_series_on_a_host_that_filters_both() -> None:
ask = _runner.ask_for(workday, {}, {"countries": ["DK", "SE"], "remote": True})
facets = {"country": {"DK": "Location=dk", "SE": "Location=se"},
"remote": {"remote": "remoteType=r"}}
asks = _runner.series(workday, ask, facets)
assert [(a.countries, a.remote, a.remote_ids) for a in asks] == [
(("Location=dk", "Location=se"), None, ()),
((), True, ("remoteType=r",))]
def test_remote_is_left_out_beside_countries_where_the_host_has_no_remote_facet() -> None:
ask = Ask(countries=("DK",), remote=True)
asks = _runner.series(workday, ask, {"country": {"DK": "Location=dk"}})
assert [(a.countries, a.remote) for a in asks] == [(("Location=dk",), None)]
# Remote alone on such a host is the whole board.
[alone] = _runner.series(workday, Ask(remote=True), {"country": {}})
assert (alone.countries, alone.remote, alone.remote_ids) == ((), None, ())
def test_a_host_with_no_country_facet_is_read_unfiltered_not_emptied() -> None:
[whole] = _runner.series(workday, Ask(countries=("DK",)), {})
assert whole.countries == ()
def test_oracle_reads_countries_and_remote_as_two_series() -> None:
ask = _runner.ask_for(oracle, {}, {"countries": ["FI"], "remote": True})
asks = _runner.series(oracle, ask, {"country": {"FI": "300000000471640"}})
assert [(a.countries, a.remote) for a in asks] == [
(("300000000471640",), None), ((), True)]
def test_a_one_host_gets_a_series_a_country_and_no_remote() -> None:
ask = _runner.ask_for(smartrecruiters, {}, {"countries": ["DK", "SE"], "remote": True})
assert ask.remote is None
assert [a.countries for a in _runner.series(smartrecruiters, ask)] == [("DK",), ("SE",)]
def test_a_reach_too_wide_for_a_one_host_reads_it_unfiltered() -> None:
europe = [c for c in _countries.NAMES if c in {
"AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IE"}]
assert len(europe) > _runner.MAX_SERIES
assert _runner.ask_for(eightfold, {}, {"countries": europe}) == Ask()
# A list in one request takes it whole.
assert _runner.ask_for(phenom, {}, {"countries": europe}).countries == tuple(europe)
# A board's own params are kept however many.
assert len(_runner.ask_for(eightfold, {"countries": europe}, None).countries) == len(europe)
@pytest.mark.parametrize("params, expected", [
({"reach": "all"}, Ask()),
({"countries": ["DE"], "remote": False}, Ask(countries=("DE",))),
({"remote": True}, Ask(countries=("DK",), remote=True)),
])
def test_a_boards_params_win_over_the_reach(params: dict[str, Any], expected: Ask) -> None:
reach = {"countries": ["DK"], "remote": True}
assert _runner.ask_for(oracle, params, reach) == expected
def test_facets_are_asked_for_remote_alone_on_a_host_that_names_it_by_id() -> None:
calls: list[str] = []
def facets(get: Any, slug: str) -> dict[str, dict[str, str]]:
calls.append(slug)
return {"remote": {"remote": "remoteType=r"}}
state: dict[str, str] = {}
original = workday.facets
try:
workday.facets = facets # type: ignore[assignment]
found = _runner.facets_for(workday, LEGO, Recorder(b""), Ask(remote=True), state, "k")
finally:
workday.facets = original # type: ignore[assignment]
assert found == {"remote": {"remote": "remoteType=r"}} and calls == [LEGO]