Files
aza/AzA march 2026 - Kopie (17)/workforce_planner/test_api.py
2026-04-19 20:41:37 +02:00

64 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""Schnelltest für die API-Endpunkte."""
import requests
BASE = "http://127.0.0.1:8000/api/v1"
def main():
print("=== Health ===")
r = requests.get(f"{BASE}/health")
print(f" {r.status_code}: {r.json()}")
print("\n=== Login (admin@praxis.ch) ===")
r = requests.post(f"{BASE}/auth/login", json={"email": "admin@praxis.ch", "password": "admin123"})
print(f" {r.status_code}")
data = r.json()
token = data["access_token"]
emp = data["employee"]
print(f" User: {emp['name']} ({emp['role']})")
print(f" Token: {token[:40]}...")
headers = {"Authorization": f"Bearer {token}"}
print("\n=== Mitarbeiter auflisten ===")
r = requests.get(f"{BASE}/employees/", headers=headers)
print(f" {r.status_code}: {len(r.json())} Mitarbeiter")
for e in r.json():
print(f" {e['name']:20s} {e['role']:10s} {e['vacation_days_per_year']} Tage/Jahr")
print("\n=== Abwesenheit erstellen (Stefan, 16-20 Mär Skiferien) ===")
r = requests.post(f"{BASE}/absences/", headers=headers, json={
"employee_id": "emp_1",
"category": "urlaub",
"start_date": "2026-03-16",
"end_date": "2026-03-20",
"reason": "Skiferien",
})
print(f" {r.status_code}")
ab = r.json()
if r.status_code == 201:
print(f" {ab['category']} {ab['start_date']} {ab['end_date']} ({ab['business_days']} Arbeitstage)")
print(f" Status: {ab['status']}")
else:
print(f" Fehler: {ab}")
print("\n=== Ferientage-Konto (Stefan, 2026) ===")
r = requests.get(f"{BASE}/balance/emp_1/2026", headers=headers)
bal = r.json()
print(f" {r.status_code}")
print(f" Anspruch: {bal['total_available']} | Genommen: {bal['used_days']} | Rest: {bal['remaining']}")
print("\n=== Alle Abwesenheiten 2026 ===")
r = requests.get(f"{BASE}/absences/?year=2026", headers=headers)
print(f" {r.status_code}: {len(r.json())} Einträge")
for a in r.json():
print(f" {a['employee_id']:12s} {a['category']:15s} {a['start_date']} {a['end_date']}")
print("\n=== FERTIG alle Tests bestanden ===")
if __name__ == "__main__":
main()