dodil/erp-brick-time-off
DODIL ERP brick: time off
tests/test_seams.py
"""hr - the one neighbour - behind one adapter: every answer is a reply, never an exception. Not installed (409), failed (502), silent (503). And every
call this brick makes is checked against hr's signed spec (conftest.checked_seams)."""
import pytest
from conftest import EMPLOYEE, ask, refused, request
from erp_platform import seam
from erp_platform.contract import ContractViolation
from brick_time_off.infrastructure import seams
def test_a_call_hrs_spec_would_refuse_fails_the_test_at_the_call(hr, checked_seams):
with pytest.raises(ContractViolation):
seams.HR.get("/persons/4410/salary", params={}, actor="x") # a route the spec does not list
with pytest.raises(ContractViolation):
seams.HR.get("/persons/4410/work-pattern", params={"from": "2026-12-21"}, actor="x") # `to` is required
seams.HR.get("/persons/4410/work-pattern", params={"from": "2026-12-21", "to": "2026-12-31"}, actor="x") # the real one passes
seams.HR.get("/persons/4410/employment", params={"on": "2026-12-21"}, actor="x")
seams.HR.get("/persons/4410/manager", params={"on": "2026-12-21", "level": 1}, actor="x")
seams.HR.get("/persons", params={"pool_user_sub": "sub-4410"}, actor="x")
assert len(checked_seams.violations) == 2 # recorded too, so a swallowed exception still fails a test
checked_seams.violations.clear()
def test_hr_down_is_a_reply_and_nothing_is_written(hr):
hr.status = 500
refused(ask("2026-12-21"), 502, "hr failed")
refused(balance_call(), 502, "hr failed")
hr.status = None
assert request("2026-12-21")["request_id"] == "UK01-TOF-2026-00001" # no number was spent by the failed ask
def test_without_hr_nobody_can_book_time_off():
seam.unregister_local("hr")
refused(ask("2026-12-21"), 409, "hr is not part of this installation")
def test_hr_answering_a_shape_it_did_not_promise_is_a_502_not_a_500(hr):
hr.malformed = True
refused(ask("2026-12-21"), 502, "did not have the shape")
def balance_call():
from conftest import api
return api("GET", "/balance", EMPLOYEE)