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:
2026-10-23 08:49:49 +02:00
parent 66fef822de
commit d2a612a37e
9 changed files with 519 additions and 67 deletions
+12 -12
View File
@@ -1,13 +1,12 @@
#!/usr/bin/env python3
"""Glutz eAccess Cloud — minimaler JSON-RPC-Client (nur Stdlib).
"""Glutz eAccess Cloud — minimal JSON-RPC client (stdlib only).
Übernommen aus ../glutz-eaccess-api/glutz_api.py (auf Client-Funktionen
reduziert), damit dieses Deployment selbst-contained ist.
Taken from ../glutz-eaccess-api/glutz_api.py (reduced to the client
functions) so that this deployment is self-contained.
* Endpunkt: https://<instanz>.eaccess.glutz.com/rpc
* Auth: HTTP Basic (GLUTZ_USER / GLUTZ_PASS aus .env)
* Lesen: eAccess.getModel params=[Collection, Filter, Fields]
* Schreiben: eAccess.setModel params=[Collection, DataObject]
* Endpoint: https://<instance>.eaccess.glutz.com/rpc
* Auth: HTTP Basic (GLUTZ_USER / GLUTZ_PASS from .env)
* Read: eAccess.getModel params=[Collection, Filter, Fields]
* Write: eAccess.setModel params=[Collection, DataObject]
"""
from __future__ import annotations
@@ -24,7 +23,8 @@ RPC_ID = 4711
def load_env(path: Path | None = None) -> None:
"""Lädt KEY=VALUE aus .env (neben diesem Script), ohne bestehende ENV zu überschreiben."""
"""Load KEY=VALUE pairs from .env (next to this script); never overrides
variables already present in the environment."""
env_file = path or Path(__file__).resolve().parent / ".env"
if not env_file.is_file():
return
@@ -39,7 +39,7 @@ def load_env(path: Path | None = None) -> None:
def rpc(method: str, params: list) -> dict:
"""Einzelner JSON-RPC-Aufruf; bei Fehler sys.exit mit Meldung."""
"""Single JSON-RPC call; exits with an error message on failure."""
host = os.environ["GLUTZ_HOST"].rstrip("/")
user = os.environ["GLUTZ_USER"]
password = os.environ["GLUTZ_PASS"]
@@ -62,7 +62,7 @@ def rpc(method: str, params: list) -> dict:
except urllib.error.HTTPError as err:
sys.exit(f"HTTP {err.code}: {err.read().decode(errors='replace')[:400]}")
except urllib.error.URLError as err:
sys.exit(f"Netzwerkfehler bei {method}: {err}")
sys.exit(f"Network error during {method}: {err}")
if "error" in data:
sys.exit(f"RPC-Fehler bei {method}: {json.dumps(data['error'])}")
sys.exit(f"RPC error during {method}: {json.dumps(data['error'])}")
return data.get("result", {})