mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-12-17 08:00:13 +01:00
feat(themes): whitelist governance, synergy cap, docs + tests; feat(random): laid roadwork for random implementation, testing in headless confirmed
This commit is contained in:
parent
03e839fb87
commit
16261bbf09
34 changed files with 12594 additions and 23 deletions
45
code/tests/test_random_reroll_endpoints.py
Normal file
45
code/tests/test_random_reroll_endpoints.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import os
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def client():
|
||||
# Ensure flags and frozen dataset
|
||||
os.environ["RANDOM_MODES"] = "1"
|
||||
os.environ["RANDOM_UI"] = "1"
|
||||
os.environ["CSV_FILES_DIR"] = os.path.join("csv_files", "testdata")
|
||||
|
||||
from web.app import app
|
||||
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
|
||||
|
||||
def test_api_random_reroll_increments_seed(client: TestClient):
|
||||
r1 = client.post("/api/random_full_build", json={"seed": 123})
|
||||
assert r1.status_code == 200, r1.text
|
||||
data1 = r1.json()
|
||||
assert data1.get("seed") == 123
|
||||
|
||||
r2 = client.post("/api/random_reroll", json={"seed": 123})
|
||||
assert r2.status_code == 200, r2.text
|
||||
data2 = r2.json()
|
||||
assert data2.get("seed") == 124
|
||||
assert data2.get("permalink")
|
||||
|
||||
|
||||
def test_hx_random_reroll_returns_html(client: TestClient):
|
||||
headers = {"HX-Request": "true", "Content-Type": "application/json"}
|
||||
r = client.post("/hx/random_reroll", data=json.dumps({"seed": 42}), headers=headers)
|
||||
assert r.status_code == 200, r.text
|
||||
# Accept either HTML fragment or JSON fallback
|
||||
content_type = r.headers.get("content-type", "")
|
||||
if "text/html" in content_type:
|
||||
assert "Seed:" in r.text
|
||||
else:
|
||||
j = r.json()
|
||||
assert j.get("seed") in (42, 43) # depends on increment policy
|
||||
Loading…
Add table
Add a link
Reference in a new issue