Add pytest suite, uv project setup and ruff compliance
- pyproject.toml: dev deps via uv (pytest, ruff), pytest and ruff config - tests/: 24 tests for extend_pins (helpers + mocked main flow) and glutz_api.load_env; no network access - translate source code to English per AGENT.md - fix ruff findings (unused import, max() simplification, shebang)
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
"""Shared fixtures: canned Glutz API data and a fake rpc()."""
|
||||
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
import glutz_api
|
||||
from extend_pins import main
|
||||
|
||||
USERS = [
|
||||
{"id": 50, "label": "Graf Markus 225313", "class": 1}, # wyby booking user
|
||||
{"id": 42, "label": "Markus", "class": 1}, # manual user -> excluded
|
||||
{"id": 33, "label": "Forum", "class": 1}, # manual user -> excluded
|
||||
{"id": 12, "label": "Gr. Gemeinschaftsraum Hueb. 8a", "class": 2}, # group
|
||||
]
|
||||
|
||||
FUTURE_FROM = "2099-02-18T17:45:00.000"
|
||||
FUTURE_TO = "2099-02-20T22:15:00.000"
|
||||
|
||||
|
||||
def code_row(**overrides):
|
||||
"""A wyby code row: booking Fri 18:00 - Sun 22:00 with +/-15 min window."""
|
||||
row = {
|
||||
"id": 77,
|
||||
"userId": 50,
|
||||
"code": "225313",
|
||||
"description": "reservation",
|
||||
"actionProfileId": "2",
|
||||
"validFrom": FUTURE_FROM,
|
||||
"validTo": FUTURE_TO,
|
||||
}
|
||||
row.update(overrides)
|
||||
return row
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def install_rpc(monkeypatch):
|
||||
"""Install a fake glutz_api.rpc; returns (calls, set_calls) lists."""
|
||||
calls = []
|
||||
|
||||
def _install(users=USERS, codes=None, write_result=None, write_error=None):
|
||||
codes = [] if codes is None else codes
|
||||
|
||||
def fake_rpc(method, params):
|
||||
calls.append((method, params))
|
||||
if method == "eAccess.getModel":
|
||||
return {"UsersGroups": users, "Codes": codes}[params[0]]
|
||||
if write_error is not None:
|
||||
raise SystemExit(write_error)
|
||||
return {"id": "99"} if write_result is None else write_result
|
||||
|
||||
monkeypatch.setattr(glutz_api, "rpc", fake_rpc)
|
||||
return calls
|
||||
|
||||
return _install
|
||||
|
||||
|
||||
def run_main(monkeypatch, *argv):
|
||||
monkeypatch.setattr(sys, "argv", ["extend_pins.py", *argv])
|
||||
main()
|
||||
Reference in New Issue
Block a user