added tests
This commit is contained in:
parent
4e359cf3ef
commit
cbe9369712
9 changed files with 960 additions and 150 deletions
83
backend/run_tests.py
Normal file
83
backend/run_tests.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Einfacher Test-Runner für die Tschunk Order API
|
||||
Führt automatisch alle Tests aus
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
|
||||
def run_tests():
|
||||
"""Führe alle Tests aus"""
|
||||
print("🧪 Tschunk Order API - Automatisierte Tests")
|
||||
print("=" * 60)
|
||||
print()
|
||||
|
||||
# Prüfe ob wir im richtigen Verzeichnis sind
|
||||
if not os.path.exists("main.py"):
|
||||
print("❌ Fehler: main.py nicht gefunden!")
|
||||
print(" Stelle sicher, dass du im backend/ Verzeichnis bist.")
|
||||
return False
|
||||
|
||||
# Prüfe ob virtuelle Environment aktiviert ist
|
||||
if not hasattr(sys, 'real_prefix') and not (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
|
||||
print("⚠️ Warnung: Virtuelles Environment scheint nicht aktiviert zu sein.")
|
||||
print(" Führe 'source venv/bin/activate' aus, falls Tests fehlschlagen.")
|
||||
print()
|
||||
|
||||
try:
|
||||
# Führe pytest aus
|
||||
print("🚀 Starte Tests...")
|
||||
print()
|
||||
|
||||
result = subprocess.run([
|
||||
sys.executable, "-m", "pytest",
|
||||
"test_automated.py",
|
||||
"-v",
|
||||
"--tb=short",
|
||||
"--color=yes"
|
||||
], capture_output=False, text=True)
|
||||
|
||||
print()
|
||||
print("=" * 60)
|
||||
|
||||
if result.returncode == 0:
|
||||
print("✅ Alle Tests erfolgreich!")
|
||||
print("🎉 Die API funktioniert einwandfrei!")
|
||||
return True
|
||||
else:
|
||||
print("❌ Einige Tests fehlgeschlagen!")
|
||||
print("🔧 Überprüfe die Fehlermeldungen oben.")
|
||||
return False
|
||||
|
||||
except FileNotFoundError:
|
||||
print("❌ Fehler: pytest nicht gefunden!")
|
||||
print(" Installiere pytest mit: pip install pytest")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ Unerwarteter Fehler: {e}")
|
||||
return False
|
||||
|
||||
def show_test_info():
|
||||
"""Zeige Informationen über die Tests"""
|
||||
print("📋 Test-Übersicht:")
|
||||
print(" • HTTP-Endpunkte (GET, POST, DELETE)")
|
||||
print(" • Datenvalidierung (Pydantic)")
|
||||
print(" • WebSocket-Funktionalität")
|
||||
print(" • Datenbankoperationen")
|
||||
print(" • Fehlerbehandlung")
|
||||
print()
|
||||
print("🔧 Verfügbare Befehle:")
|
||||
print(" python run_tests.py - Führe alle Tests aus")
|
||||
print(" python -m pytest - Führe pytest direkt aus")
|
||||
print(" python -m pytest -v - Detaillierte Ausgabe")
|
||||
print(" python -m pytest -k 'test_create' - Nur bestimmte Tests")
|
||||
print()
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "--info":
|
||||
show_test_info()
|
||||
else:
|
||||
success = run_tests()
|
||||
sys.exit(0 if success else 1)
|
Loading…
Add table
Add a link
Reference in a new issue