Fail the read when Lever answers something other than a list or Oracle an answer without its search wrapper, instead of reading an empty board that is complete
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
19fb73caa0
commit
85aed0807b
4 files changed
+67
-5
No files matched your search
+26
-1
@@ -1,15 +1,20 @@
|
||||
"""The Lever host module's places, country and employment, against a small
|
||||
saved board. No network. The pay and the plain row are in `test_ats.py`."""
|
||||
saved board, and an answer that is no board. No network. The pay and the
|
||||
plain row are in `test_ats.py`."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
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 plugins import ats # noqa: E402
|
||||
from plugins.readers import Ask, lever # noqa: E402
|
||||
|
||||
BOARD = (ROOT / "tests" / "fixtures" / "ats" / "lever-places.json").read_bytes()
|
||||
@@ -33,6 +38,26 @@ def test_the_commitment_is_the_hosts_word() -> None:
|
||||
assert several["employment"] == "Full-time" and one["employment"] == "Permanent"
|
||||
|
||||
|
||||
def test_an_answer_that_is_not_a_list_raises_and_an_empty_list_is_no_roles() -> None:
|
||||
with pytest.raises(ValueError, match="JSON dict, not a list"):
|
||||
lever.parse(b'{"ok": false, "error": "Document not found"}', "acme")
|
||||
assert lever.parse(b"[]", "acme") == []
|
||||
|
||||
|
||||
def test_an_error_document_with_a_200_fails_the_read_and_stamps_nothing(
|
||||
monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""It used to read as a complete board with no roles, which the settle
|
||||
closed whole under ten roles, where the 10% guard does not hold."""
|
||||
monkeypatch.setattr(ats, "_get", lambda *a, **kw: b'{"ok": false}')
|
||||
source = ats.ATSSource({"boards": [{"url": "lever:acme", "label": "Acme", "params": {}}],
|
||||
"run": "r"})
|
||||
source.state = {}
|
||||
assert list(source.fetch()) == []
|
||||
assert "ats:ok:lever:acme" not in source.state
|
||||
assert json.loads(source.state["ats:failing:lever:acme"])["reason"].startswith(
|
||||
"ValueError: Lever's answer is a JSON dict")
|
||||
|
||||
|
||||
def test_it_declares_a_whole_listing_of_trusted_dates_and_its_robots_record() -> None:
|
||||
reads = lever.READS
|
||||
assert (reads.listing, reads.text, reads.places) == ("whole", "listing", "many")
|
||||
|
||||
@@ -165,6 +165,28 @@ def test_an_empty_board_is_complete(monkeypatch: pytest.MonkeyPatch, no_delay: N
|
||||
assert ats._fetch_rows(object(), f"oracle:{SLUG}") == ([], True) # type: ignore[arg-type]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("answer", [
|
||||
{}, {"items": []}, {"items": {}}, {"items": [None]}, [], {"title": "Unauthorized"}])
|
||||
def test_an_answer_without_the_search_wrapper_fails_the_read(
|
||||
monkeypatch: pytest.MonkeyPatch, no_delay: None, answer: Any) -> None:
|
||||
"""It used to read as an empty last page with no total: a complete
|
||||
read of a board with no roles."""
|
||||
monkeypatch.setattr(ats, "_get", lambda *a, **k: json.dumps(answer).encode())
|
||||
with pytest.raises(ValueError, match="no search wrapper in items"):
|
||||
ats._fetch_rows(object(), f"oracle:{SLUG}") # type: ignore[arg-type]
|
||||
|
||||
|
||||
def test_a_board_answering_without_the_wrapper_is_recorded_failing(
|
||||
monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None:
|
||||
monkeypatch.setattr(ats, "_get", lambda *a, **k: b'{"title": "Unauthorized"}')
|
||||
source = ats.ATSSource({"boards": [{"url": f"oracle:{SLUG}", "label": "Nokia",
|
||||
"params": {}}], "run": "r"})
|
||||
source.state = {}
|
||||
assert list(source.fetch()) == []
|
||||
assert f"ats:ok:oracle:{SLUG}" not in source.state
|
||||
assert "no search wrapper" in json.loads(source.state[f"ats:failing:oracle:{SLUG}"])["reason"]
|
||||
|
||||
|
||||
# ----------------------------------------------------------------- detail
|
||||
|
||||
def _detail_get(body: bytes, asked: list[str]) -> Any:
|
||||
|
||||
Reference in new issue
Block a user