Trainer_LLM/tests/test_integrity_wp15.py
Lars 4fbfdb1c6a
All checks were successful
Deploy Trainer_LLM to llm-node / deploy (push) Successful in 1s
tests/test_integrity_wp15.py hinzugefügt
2025-08-12 16:24:33 +02:00

93 lines
3.1 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.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Integritätstests für Referenzen (Templates, Exercises, Plans)."""
import os, requests, uuid
from datetime import datetime, timezone
BASE = os.getenv("BASE_URL", "http://127.0.0.1:8000").rstrip("/")
def _make_exercise(ext_id: str):
payload = {
"external_id": ext_id,
"fingerprint": "it-sha",
"source": "IntegrityTest",
"title": "Übung Dummy",
"summary": "",
"short_description": "",
"keywords": ["Reaktion"],
"discipline": "Karate",
"age_group": "Teenager",
"target_group": "Breitensport",
"min_participants": 1,
"duration_minutes": 5,
"capabilities": {"Reaktionsfähigkeit": 1},
"category": "Übungen",
"purpose": "",
"execution": "",
"notes": "",
"preparation": "",
"method": "",
"equipment": []
}
r = requests.post(f"{BASE}/exercise", json=payload)
assert r.status_code == 200, r.text
def test_plan_requires_existing_template():
# Übung anlegen für gültigen Plan (damit Exercise-Check nicht stört)
exid = f"it:{uuid.uuid4()}"; _make_exercise(exid)
# Plan mit nicht existenter template_id
plan = {
"template_id": "does-not-exist",
"title": "Plan mit falschem Template",
"discipline": "Karate",
"age_group": "Teenager",
"target_group": "Breitensport",
"total_minutes": 30,
"sections": [{"name": "Block", "minutes": 30, "items": [{"exercise_external_id": exid, "duration": 10, "why": ""}]}],
"goals": [],
"capability_summary": {},
"created_by": "tester",
"created_at": datetime.now(timezone.utc).isoformat(),
"source": "test"
}
r = requests.post(f"{BASE}/plan", json=plan)
assert r.status_code == 422
def test_plan_session_requires_existing_plan():
sess = {
"plan_id": "does-not-exist",
"executed_at": datetime.now(timezone.utc).isoformat(),
"location": "Dojo",
"coach": "X",
"group_label": "Y",
"feedback": {"rating": 3, "notes": ""},
"used_equipment": []
}
r = requests.post(f"{BASE}/plan_sessions", json=sess)
assert r.status_code == 422
def test_strict_exercises_if_env():
# Nur sinnvoll, wenn Server mit PLAN_STRICT_EXERCISES=1 gestartet wurde
if os.getenv("PLAN_STRICT_EXERCISES") not in {"1", "true", "yes", "on"}:
import pytest; pytest.skip("Strict-Mode nicht aktiv Test übersprungen")
plan = {
"title": "Plan mit unbekannter Übung",
"discipline": "Karate",
"age_group": "Teenager",
"target_group": "Breitensport",
"total_minutes": 10,
"sections": [{"name": "Block", "minutes": 10, "items": [{"exercise_external_id": "unknown:xyz", "duration": 5, "why": ""}]}],
"goals": [],
"capability_summary": {},
"created_by": "tester",
"created_at": datetime.now(timezone.utc).isoformat(),
"source": "test"
}
r = requests.post(f"{BASE}/plan", json=plan)
assert r.status_code == 422