update
This commit is contained in:
63
backup 24.2.26 - Kopie/workforce_planner/test_api.py
Normal file
63
backup 24.2.26 - Kopie/workforce_planner/test_api.py
Normal file
@@ -0,0 +1,63 @@
|
||||
# -*- 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()
|
||||
Reference in New Issue
Block a user