first commit
Build and deploy / build-and-push (push) Successful in 17s
Build and deploy / deploy (push) Successful in 10s

This commit is contained in:
william
2026-08-21 16:23:49 +02:00
committed by william
commit 3f4ebc4527
248 changed files with 10180 additions and 0 deletions
+108
View File
@@ -0,0 +1,108 @@
"""Tests des conditions combinées ET/OU (2.4).
Un nœud Condition peut porter plusieurs clauses (cond_clauses, JSON) combinées
par cond_combinator ('et'/'ou'), en plus de sa clause "historique" unique
(cond_definition_id/cond_field/...). Un nœud sans cond_clauses doit garder
EXACTEMENT son comportement d'avant (une seule comparaison) — c'est ce que
vérifient les tests de non-régression ci-dessous, en plus des tests dédiés
à la nouvelle fonctionnalité.
"""
import json
import re
def _create_screen(client, slug, name="Accueil"):
resp = client.post(f"/game/{slug}/screens/new", data={"name": name}, follow_redirects=False)
return int(re.search(r"/screens/(\d+)/edit", resp.headers["Location"]).group(1))
def _create_object_two_fields(client, slug):
"""Crée un objet "Partie" avec deux champs numériques et une ligne."""
resp = client.post(f"/game/{slug}/objects/new", data={
"object_name": "Partie",
"field_name[]": ["reputation", "niveau"],
"field_type[]": ["nombre_entier", "nombre_entier"],
"field_relation[]": ["", ""],
"field_required[]": ["0", "0"],
"field_min[]": ["", ""],
"field_max[]": ["", ""],
}, follow_redirects=False)
def_id = int(resp.headers["Location"].rstrip("/").split("/")[-1])
client.post(f"/game/{slug}/objects/{def_id}/data/new", data={"reputation": "5", "niveau": "3"})
return def_id
def test_legacy_single_clause_condition_still_works_without_cond_clauses(client, game):
"""Non-régression : un nœud Condition créé SANS cond_clauses (comme avant
2.4) doit toujours fonctionner à l'identique."""
screen_id = _create_screen(client, game)
def_id = _create_object_two_fields(client, game)
resp = client.post(
f"/game/{game}/screens/{screen_id}/flow/nodes/add",
data=json.dumps({
"node_type": "condition",
"cond_definition_id": def_id, "cond_row_id": 1,
"cond_field": "reputation", "cond_field_type": "nombre_entier",
"cond_operator": "superieur", "cond_value": "10",
}),
content_type="application/json",
)
node = resp.get_json()
assert node["cond_clauses"] is None
resp = client.get(f"/game/{game}/play")
html = resp.data.decode()
assert "evaluateConditionClause" in html
assert "cond_clauses" in html
def test_condition_node_persists_clauses_and_combinator(client, game):
screen_id = _create_screen(client, game)
def_id = _create_object_two_fields(client, game)
clauses = [
{"definition_id": def_id, "row_id": 1, "field": "reputation", "field_type": "nombre_entier", "operator": "inferieur", "value": "20"},
{"definition_id": def_id, "row_id": 1, "field": "niveau", "field_type": "nombre_entier", "operator": "superieur_egal", "value": "3"},
]
resp = client.post(
f"/game/{game}/screens/{screen_id}/flow/nodes/add",
data=json.dumps({
"node_type": "condition",
"cond_definition_id": def_id, "cond_row_id": 1,
"cond_field": "reputation", "cond_field_type": "nombre_entier",
"cond_operator": "inferieur", "cond_value": "20",
"cond_clauses": json.dumps(clauses), "cond_combinator": "ou",
}),
content_type="application/json",
)
assert resp.status_code == 200
node = resp.get_json()
assert node["cond_combinator"] == "ou"
stored_clauses = json.loads(node["cond_clauses"])
assert len(stored_clauses) == 2
assert stored_clauses[0]["field"] == "reputation"
assert stored_clauses[1]["field"] == "niveau"
def test_condition_combinator_defaults_to_et_when_absent(client, game):
"""cond_combinator a une valeur par défaut 'et' en base même si on ne la
précise jamais (jeux migrés depuis avant 2.4)."""
screen_id = _create_screen(client, game)
def_id = _create_object_two_fields(client, game)
resp = client.post(
f"/game/{game}/screens/{screen_id}/flow/nodes/add",
data=json.dumps({
"node_type": "condition",
"cond_definition_id": def_id, "cond_row_id": 1,
"cond_field": "reputation", "cond_field_type": "nombre_entier",
"cond_operator": "superieur", "cond_value": "10",
}),
content_type="application/json",
)
node = resp.get_json()
assert node["cond_combinator"] == "et"
def test_play_page_exposes_combinator_logic(client, game):
resp = client.get(f"/game/{game}/play")
html = resp.data.decode()
assert "cond_combinator" in html
assert "'ou'" in html