From 4fbfdb1c6ac2d7e3c5c4dc60ff4ce2ff42c3e2de Mon Sep 17 00:00:00 2001 From: Lars Date: Tue, 12 Aug 2025 16:24:33 +0200 Subject: [PATCH] =?UTF-8?q?tests/test=5Fintegrity=5Fwp15.py=20=20hinzugef?= =?UTF-8?q?=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_integrity_wp15.py | 93 +++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 tests/test_integrity_wp15.py diff --git a/tests/test_integrity_wp15.py b/tests/test_integrity_wp15.py new file mode 100644 index 0000000..68983e4 --- /dev/null +++ b/tests/test_integrity_wp15.py @@ -0,0 +1,93 @@ +#!/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 \ No newline at end of file