Files
Forge-Engine/tests/test_add_row_action.py
T
williamandClaude Sonnet 5 e82eb7ce88
Build and deploy / test-python (push) Successful in 7m5s
Build and deploy / test-js (push) Successful in 58s
Build and deploy / build-and-push (push) Skipped
Build and deploy / deploy (push) Skipped
Retire l'export exécutable (.exe) et la partie publique en ligne (/jouer)
Décision produit : seul l'export Web/SCORM (LMS) est pertinent — l'export
exécutable Windows autonome (publish/build_package.py, bouton "Publier")
et la partie publique par joueur (/jouer/<slug>, routes/public_play/,
"Publier en ligne") sont jugés redondants et retirés.

Conserve le mécanisme d'état "par joueur" (db/global_vars,
db/rows, per_player) : infrastructure générique déjà utilisée par
Score/Progression et testée indépendamment de toute route publique
(voir tests/test_player_state.py), aucune raison de la retirer.

_STATIC_ITEMS/_copy_characters (copie sélective des sprites CraftPix
réellement utilisés) migrent de build_package.py vers
build_scorm_package.py, seul appelant restant.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-02 10:59:28 +02:00

102 lines
3.8 KiB
Python

"""Tests de l'action "Ajouter une ligne" (ajouter_ligne, Phase 4) : crée
une ligne VIDE, dont l'id devient LAST_INSERTED_ROW_ID pour un nœud
"Modifier une donnée" enchaîné dans le MÊME flow — verrouille le
mécanisme complet (route -> DB -> répéteur) plutôt que juste la fonction
Python isolée."""
import json
import re
import db
import screens
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 _add_flow_node(client, slug, screen_id, **fields):
resp = client.post(
f"/game/{slug}/screens/{screen_id}/flow/nodes/add",
data=json.dumps(fields),
content_type="application/json",
)
assert resp.status_code == 200
return resp.get_json()["id"]
def _create_inventory_object(client, slug):
resp = client.post(
f"/game/{slug}/objects/new",
data={
"object_name": "Inventaire",
"field_name[]": ["objet"],
"field_type[]": ["texte"],
"field_relation[]": [""],
"field_required[]": ["0"],
},
follow_redirects=False,
)
assert resp.status_code == 302
return int(resp.headers["Location"].rstrip("/").split("/")[-1])
def test_run_add_row_route_creates_an_empty_row(client, game):
definition_id = _create_inventory_object(client, game)
screen_id = _create_screen(client, game)
node_id = _add_flow_node(
client, game, screen_id, node_type="action", action_type="ajouter_ligne", target_definition_id=definition_id,
)
resp = client.post(f"/game/{game}/flow/nodes/{node_id}/run-add-row")
assert resp.status_code == 200
body = resp.get_json()
assert body["ok"] is True
assert isinstance(body["row_id"], int)
definition = db.get_definition(game, definition_id)
rows = db.list_rows(game, definition)
assert len(rows) == 1
assert rows[0]["id"] == body["row_id"]
assert rows[0]["objet"] is None
def test_run_add_row_route_rejects_wrong_action_type(client, game):
screen_id = _create_screen(client, game)
node_id = _add_flow_node(client, game, screen_id, node_type="action", action_type="attendre", data_value="1")
resp = client.post(f"/game/{game}/flow/nodes/{node_id}/run-add-row")
assert resp.status_code == 400
assert resp.get_json()["ok"] is False
def test_chained_ajouter_ligne_then_modifier_donnee_sets_the_new_row_fields(client, game):
"""Le scénario réel : "Ajouter une ligne" crée une ligne vide, puis un
"Modifier une donnée" ciblant LAST_INSERTED_ROW_ID (transmis par le
client via last_inserted_row_id, voir static/js/play/actions.js) la
renseigne — exactement comme CLICKED_ROW_ID pour une ligne cliquée."""
definition_id = _create_inventory_object(client, game)
screen_id = _create_screen(client, game)
add_node_id = _add_flow_node(
client, game, screen_id, node_type="action", action_type="ajouter_ligne", target_definition_id=definition_id,
)
set_node_id = _add_flow_node(
client, game, screen_id, node_type="action", action_type="modifier_donnee",
target_definition_id=definition_id, target_row_id=screens.LAST_INSERTED_ROW_ID,
target_field="objet", data_operation="definir_texte", data_value="épée",
)
add_resp = client.post(f"/game/{game}/flow/nodes/{add_node_id}/run-add-row")
new_row_id = add_resp.get_json()["row_id"]
set_resp = client.post(
f"/game/{game}/flow/nodes/{set_node_id}/run-data",
data=json.dumps({"last_inserted_row_id": new_row_id}),
content_type="application/json",
)
assert set_resp.get_json()["ok"] is True
definition = db.get_definition(game, definition_id)
row = db.get_row(game, definition, new_row_id)
assert row["objet"] == "épée"