Files
cookbook/test_live.py
T

57 lines
2.0 KiB
Python
Executable File

import urllib.request
import json
import ssl
ctx = ssl.create_default_context()
def test_live():
# 1. Roll 3 slots
url = "https://wtc.dev.waiswuaschd.de/api/roll"
payload = {
"slots": [
{"slot_number": 1, "category": "Nudeln", "efforts": ["gering", "mittel"]},
{"slot_number": 2, "category": "asiatisch", "efforts": ["mittel"]},
{"slot_number": 3, "category": "Hausmannskost", "efforts": ["hoch"]}
]
}
req = urllib.request.Request(
url,
data=json.dumps(payload).encode("utf-8"),
headers={"Content-Type": "application/json"}
)
with urllib.request.urlopen(req, context=ctx) as resp:
data = json.loads(resp.read().decode("utf-8"))
print("Initial Roll:")
for r in data["results"]:
dish = r["dish"]
print(f" Slot {r['slot_number']}: ID={dish['id']} - {dish['name']}")
slot1_dish = data["results"][0]["dish"]
other_ids = [r["dish"]["id"] for r in data["results"][1:]]
# 2. Reroll slot 1
reroll_url = "https://wtc.dev.waiswuaschd.de/api/roll-single"
reroll_payload = {
"slot_number": 1,
"category": "Nudeln",
"efforts": ["gering", "mittel"],
"current_dish_id": slot1_dish["id"],
"other_dish_ids": other_ids
}
req2 = urllib.request.Request(
reroll_url,
data=json.dumps(reroll_payload).encode("utf-8"),
headers={"Content-Type": "application/json"}
)
with urllib.request.urlopen(req2, context=ctx) as resp2:
reroll_data = json.loads(resp2.read().decode("utf-8"))
new_dish = reroll_data["dish"]
print("\nReroll Slot 1 Result:")
print(f" New Dish: ID={new_dish['id']} - {new_dish['name']}")
assert new_dish["id"] != slot1_dish["id"], "Reroll gave same dish!"
assert new_dish["id"] not in other_ids, "Reroll duplicated another slot!"
print(" SUCCESS: Different dish picked, no duplication with active slots!")
if __name__ == "__main__":
test_live()