Files
cookbook/scripts/test_endpoints.py
T

40 lines
1.3 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")
print("\nAll route tests passed successfully!")
if __name__ == "__main__":
test_routes()