mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-12-17 08:00:13 +01:00
web: DRY Step 5 and alternatives (partial+macro), centralize start_ctx/owned_set, adopt builder_*
This commit is contained in:
parent
fe9aabbce9
commit
014bcc37b7
24 changed files with 1200 additions and 766 deletions
60
code/tests/test_build_utils_ctx.py
Normal file
60
code/tests/test_build_utils_ctx.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from code.web.services.build_utils import start_ctx_from_session, owned_set, owned_names
|
||||
|
||||
|
||||
def _fake_session(**kw):
|
||||
# Provide minimal session keys used by start_ctx_from_session
|
||||
base = {
|
||||
"commander": "Cmdr",
|
||||
"tags": ["Aggro", "Spells"],
|
||||
"bracket": 3,
|
||||
"ideals": {"creatures": 25},
|
||||
"tag_mode": "AND",
|
||||
"use_owned_only": False,
|
||||
"prefer_owned": False,
|
||||
"locks": [],
|
||||
"custom_export_base": "TestDeck",
|
||||
"multi_copy": None,
|
||||
"prefer_combos": False,
|
||||
"combo_target_count": 2,
|
||||
"combo_balance": "mix",
|
||||
}
|
||||
base.update(kw)
|
||||
return base
|
||||
|
||||
|
||||
def test_owned_helpers_do_not_crash():
|
||||
# These reflect over the owned store; they should be resilient
|
||||
s = owned_set()
|
||||
assert isinstance(s, set)
|
||||
n = owned_names()
|
||||
assert isinstance(n, list)
|
||||
|
||||
|
||||
def test_start_ctx_from_session_minimal(monkeypatch):
|
||||
# Avoid integration dependency by faking orchestrator.start_build_ctx
|
||||
calls = {}
|
||||
def _fake_start_build_ctx(**kwargs):
|
||||
calls.update(kwargs)
|
||||
return {"builder": object(), "stages": [], "idx": 0, "last_visible_idx": 0}
|
||||
import code.web.services.build_utils as bu
|
||||
monkeypatch.setattr(bu.orch, "start_build_ctx", _fake_start_build_ctx)
|
||||
|
||||
sess = _fake_session()
|
||||
ctx = start_ctx_from_session(sess, set_on_session=False)
|
||||
assert isinstance(ctx, dict)
|
||||
assert "builder" in ctx
|
||||
assert "stages" in ctx
|
||||
assert "idx" in ctx
|
||||
|
||||
|
||||
def test_start_ctx_from_session_sets_on_session(monkeypatch):
|
||||
def _fake_start_build_ctx(**kwargs):
|
||||
return {"builder": object(), "stages": [], "idx": 0}
|
||||
import code.web.services.build_utils as bu
|
||||
monkeypatch.setattr(bu.orch, "start_build_ctx", _fake_start_build_ctx)
|
||||
|
||||
sess = _fake_session()
|
||||
ctx = start_ctx_from_session(sess, set_on_session=True)
|
||||
assert sess.get("build_ctx") == ctx
|
||||
Loading…
Add table
Add a link
Reference in a new issue