mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-12-17 08:00:13 +01:00
feat(random): multi-theme groundwork, locked reroll export parity, duplicate export fix, expanded diagnostics and test coverage
This commit is contained in:
parent
a029d430c5
commit
73685f22c8
39 changed files with 2671 additions and 271 deletions
43
code/tests/test_random_fallback_and_constraints.py
Normal file
43
code/tests/test_random_fallback_and_constraints.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import os
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
|
||||
def _mk_client(monkeypatch):
|
||||
monkeypatch.setenv("RANDOM_MODES", "1")
|
||||
monkeypatch.setenv("CSV_FILES_DIR", os.path.join("csv_files", "testdata"))
|
||||
app_module = importlib.import_module('code.web.app')
|
||||
return TestClient(app_module.app)
|
||||
|
||||
|
||||
def test_invalid_theme_triggers_fallback_and_echoes_original_theme(monkeypatch):
|
||||
client = _mk_client(monkeypatch)
|
||||
payload = {"seed": 777, "theme": "this theme does not exist"}
|
||||
r = client.post('/api/random_full_build', json=payload)
|
||||
assert r.status_code == 200
|
||||
data = r.json()
|
||||
# Fallback flag should be set with original_theme echoed
|
||||
assert data.get("fallback") is True
|
||||
assert data.get("original_theme") == payload["theme"]
|
||||
# Theme is still the provided theme (we indicate fallback via the flag)
|
||||
assert data.get("theme") == payload["theme"]
|
||||
# Commander/decklist should be present
|
||||
assert isinstance(data.get("commander"), str) and data["commander"]
|
||||
assert isinstance(data.get("decklist"), list)
|
||||
|
||||
|
||||
def test_constraints_impossible_returns_422_with_detail(monkeypatch):
|
||||
client = _mk_client(monkeypatch)
|
||||
# Set an unrealistically high requirement to force impossible constraint
|
||||
payload = {"seed": 101, "constraints": {"require_min_candidates": 1000000}}
|
||||
r = client.post('/api/random_full_build', json=payload)
|
||||
assert r.status_code == 422
|
||||
data = r.json()
|
||||
# Structured error payload
|
||||
assert data.get("status") == 422
|
||||
detail = data.get("detail")
|
||||
assert isinstance(detail, dict)
|
||||
assert detail.get("error") == "constraints_impossible"
|
||||
assert isinstance(detail.get("pool_size"), int)
|
||||
Loading…
Add table
Add a link
Reference in a new issue