diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a22f94..a4f57da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## Unreleased + +* `staff()` gains `status="lent"` (API term `"efetivo-cedido"`): the Assembly's + own permanent staff lent to other bodies. The API publishes them with + `vinculo` `"Efetivo"`, so this server-side filter is the only way to single + them out. `positions()` refuses it, because `/cargos` ignores the value and + returns every status. + ## 0.1.1 * `set_cache_ttl(0)` now always re-fetches. Stale entries were detected by diff --git a/docs/portugues.md b/docs/portugues.md index e9537ad..8dd6052 100644 --- a/docs/portugues.md +++ b/docs/portugues.md @@ -53,8 +53,10 @@ alepe.servidores(status="efetivo") alepe.staff(status="permanent") ``` -Os valores originais da API são `efetivo`, `comissionado` e `a-disposicao`; os -equivalentes em inglês são `permanent`, `commissioned` e `seconded`. +Os valores originais da API são `efetivo`, `comissionado`, `a-disposicao` e +`efetivo-cedido`; os equivalentes em inglês são `permanent`, `commissioned`, +`seconded` e `lent`. `efetivo-cedido` (efetivos da Alepe cedidos a outros +órgãos) só existe em `servidores()`: a API o ignora em `/cargos`. ## Nomes de coluna diff --git a/src/alepe/people.py b/src/alepe/people.py index 947f017..e3275ca 100644 --- a/src/alepe/people.py +++ b/src/alepe/people.py @@ -40,20 +40,26 @@ "a-disposicao": "a-disposicao", } +# Only /servidores honours efetivo-cedido; /cargos ignores it and returns every +# status, as it does for any unknown value, so positions() must refuse it. +_STAFF_STATUS = {**_STATUS, "lent": "efetivo-cedido", "efetivo-cedido": "efetivo-cedido"} -def map_status(status: str | None) -> str | None: + +def map_status(status: str | None, lent: bool = False) -> str | None: """Translate an employment-status filter to the API's ``vinculo`` value. Accepts the English vocabulary and the original API terms alike, so - ``"permanent"`` and ``"efetivo"`` are the same query. + ``"permanent"`` and ``"efetivo"`` are the same query. ``lent`` also allows + ``"lent"`` / ``"efetivo-cedido"``, which only the staff endpoint supports. """ if status is None: return None + table = _STAFF_STATUS if lent else _STATUS try: - return _STATUS[status] + return table[status] except KeyError: raise ValueError( - f"Unknown status {status!r}. Use one of: {', '.join(sorted(_STATUS))}." + f"Unknown status {status!r}. Use one of: {', '.join(sorted(table))}." ) from None @@ -64,13 +70,27 @@ def representatives(refresh: bool = False) -> pd.DataFrame: def staff(status: str | None = None, refresh: bool = False) -> pd.DataFrame: - """The Assembly's staff roster, optionally filtered by employment status.""" - records = _client.fetch_json("servidores", {"vinculo": map_status(status)}, refresh=refresh) + """The Assembly's staff roster, optionally filtered by employment status. + + ``status`` is ``"permanent"``, ``"commissioned"``, ``"seconded"`` (staff from + other bodies placed at the Assembly's disposal) or ``"lent"`` (the Assembly's + own permanent staff lent to other bodies, a subset of ``"permanent"``); the + API terms ``"efetivo"``, ``"comissionado"``, ``"a-disposicao"`` and + ``"efetivo-cedido"`` work too. Lent staff are published with ``vinculo`` + ``"Efetivo"``, so this filter is the only way to tell them apart. + """ + records = _client.fetch_json( + "servidores", {"vinculo": map_status(status, lent=True)}, refresh=refresh + ) return to_frame(records, STAFF_SCHEMA) def positions(status: str | None = None, refresh: bool = False) -> pd.DataFrame: - """Staff counts per position and level.""" + """Staff counts per position and level. + + ``status`` takes the same values as :func:`staff` except ``"lent"``, which + the API ignores for this endpoint. + """ records = _client.fetch_json("cargos", {"vinculo": map_status(status)}, refresh=refresh) return to_frame(records, POSITIONS_SCHEMA) diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index 9a7a0f9..ac72f50 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -147,6 +147,24 @@ def test_status_filter_accepts_both_vocabularies(serve_json): alepe.staff(status="nope") +def test_lent_status_reaches_staff_but_not_positions(monkeypatch, fixture_json): + sent = {} + + def fake_fetch(endpoint, params=None, **kwargs): + sent[endpoint] = (params or {}).get("vinculo") + return fixture_json("servidores.json") + + monkeypatch.setattr(_client, "fetch_json", fake_fetch) + alepe.staff(status="lent") + assert sent["servidores"] == "efetivo-cedido" + alepe.servidores(status="efetivo-cedido") + assert sent["servidores"] == "efetivo-cedido" + + with pytest.raises(ValueError): + alepe.positions(status="lent") + assert "cargos" not in sent + + def test_portuguese_aliases_reach_the_same_functions(serve_json, serve_text): serve_json("servidores.json") assert alepe.servidores().equals(alepe.staff())