Initial commit: What To Cook (WTC) v4.4 - Digitales Kochbuch, Wochenmenueplan & Buchdruck
This commit is contained in:
Executable
+97
@@ -0,0 +1,97 @@
|
||||
"""
|
||||
Automated Integration and Unit Tests for WTC Essen-Zufallsgenerator
|
||||
"""
|
||||
import sys
|
||||
import unittest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.main import app
|
||||
from app.database import (
|
||||
init_db,
|
||||
get_all_dishes,
|
||||
add_dish,
|
||||
update_dish,
|
||||
delete_dish,
|
||||
query_candidates,
|
||||
CATEGORIES,
|
||||
EFFORTS
|
||||
)
|
||||
|
||||
class TestWtcApp(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
init_db()
|
||||
cls.client = TestClient(app)
|
||||
# Create a few temporary dishes for test execution
|
||||
cls.created_dish_ids = []
|
||||
for i, cat in enumerate(["Reis", "Nudeln", "Kartoffeln", "asiatisch", "Hausmannskost"]):
|
||||
d = add_dish(f"_Testgericht {cat} {i}", cat, "mittel")
|
||||
cls.created_dish_ids.append(d["id"])
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
for did in cls.created_dish_ids:
|
||||
delete_dish(did)
|
||||
|
||||
def test_01_categories_present(self):
|
||||
self.assertIn("Nudeln", CATEGORIES)
|
||||
self.assertIn("Reis", CATEGORIES)
|
||||
self.assertIn("Kartoffeln", CATEGORIES)
|
||||
self.assertEqual(len(EFFORTS), 3)
|
||||
|
||||
def test_02_roll_5_dishes_no_duplicates(self):
|
||||
payload = {
|
||||
"slots": [
|
||||
{"slot_number": 1, "category": "Reis", "efforts": ["mittel"]},
|
||||
{"slot_number": 2, "category": "Nudeln", "efforts": ["mittel"]},
|
||||
{"slot_number": 3, "category": "Kartoffeln", "efforts": None},
|
||||
{"slot_number": 4, "category": "asiatisch", "efforts": ["mittel"]},
|
||||
{"slot_number": 5, "category": "Hausmannskost", "efforts": None},
|
||||
]
|
||||
}
|
||||
res = self.client.post("/api/roll", json=payload)
|
||||
self.assertEqual(res.status_code, 200)
|
||||
data = res.json()
|
||||
self.assertEqual(data["status"], "ok")
|
||||
results = data["results"]
|
||||
self.assertEqual(len(results), 5)
|
||||
|
||||
chosen_ids = set()
|
||||
for r in results:
|
||||
self.assertEqual(r["status"], "ok")
|
||||
dish = r["dish"]
|
||||
self.assertIsNotNone(dish)
|
||||
self.assertNotIn(dish["id"], chosen_ids)
|
||||
chosen_ids.add(dish["id"])
|
||||
|
||||
def test_03_admin_crud(self):
|
||||
test_dish_name = "_CRUD_Test_Dish"
|
||||
# 1. Create
|
||||
create_res = self.client.post("/api/dishes", json={
|
||||
"name": test_dish_name,
|
||||
"category": "Teigig",
|
||||
"effort": "gering"
|
||||
})
|
||||
self.assertEqual(create_res.status_code, 200)
|
||||
dish_id = create_res.json()["dish"]["id"]
|
||||
|
||||
# 2. Read
|
||||
get_res = self.client.get(f"/api/dishes?search={test_dish_name}")
|
||||
self.assertEqual(get_res.status_code, 200)
|
||||
dishes = get_res.json()
|
||||
self.assertEqual(len(dishes), 1)
|
||||
|
||||
# 3. Update
|
||||
up_res = self.client.put(f"/api/dishes/{dish_id}", json={
|
||||
"name": test_dish_name + "_upd",
|
||||
"category": "Teigig",
|
||||
"effort": "mittel"
|
||||
})
|
||||
self.assertEqual(up_res.status_code, 200)
|
||||
|
||||
# 4. Delete
|
||||
del_res = self.client.delete(f"/api/dishes/{dish_id}")
|
||||
self.assertEqual(del_res.status_code, 200)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user