Files
cookbook/scripts/test_endpoints.py
T

48 lines
1.7 KiB
Python

import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from fastapi.testclient import TestClient
from app.main import app, create_auth_token, COOKIE_NAME
sys.stdout.reconfigure(encoding='utf-8')
client = TestClient(app)
token = create_auth_token("admin")
client.cookies.set(COOKIE_NAME, token)
def test_routes():
# Test Home
res = client.get("/")
assert res.status_code == 200, f"Home failed: {res.status_code}"
assert "Wochenmenü" in res.text or "Wochenmen" in res.text
assert "Shuffle" in res.text
print("✓ Home page (/) OK: contains Wochenmenü and Shuffle")
# Test Cookbook
res = client.get("/cookbook")
assert res.status_code == 200, f"Cookbook failed: {res.status_code}"
assert "Grießnockerlsuppe" in res.text
assert "Fleischpflanzerl" in res.text
assert "Kaiserschmarren" in res.text
assert "Kartoffelsalat" in res.text
print("✓ Cookbook page (/cookbook) OK: 200 OK and recipes found")
# Test Recipe Detail
res = client.get("/cookbook/recipe/1")
assert res.status_code == 200, f"Recipe 1 failed: {res.status_code}"
print("✓ Recipe detail (/cookbook/recipe/1) OK")
# Verify no double numbers in /cookbook
import re
res_cb = client.get("/cookbook")
pattern = re.compile(r'<div class="step-text">\s*((?:Schritt\s*\d+[:.]?|\d+[\.\)\:])\s*[^<]*)', re.IGNORECASE)
matches = pattern.findall(res_cb.text)
assert len(matches) == 0, f"Found {len(matches)} double numbers in /cookbook: {matches[:3]}"
print("✓ Zero double numbers in rendered /cookbook steps confirmed!")
print("\nAll route tests passed successfully!")
if __name__ == "__main__":
test_routes()