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>
129 lines
5.0 KiB
Python
129 lines
5.0 KiB
Python
"""Score/progression (db/scoring/) — voir le plan "Feuille de route
|
|
produit" : concept de premier ordre, distinct des variables globales,
|
|
préalable aux futurs exports SCORM/xAPI (qui ont besoin d'un signal
|
|
"score"/"terminé" propre)."""
|
|
import json
|
|
|
|
import db
|
|
import screens
|
|
|
|
|
|
def test_get_score_defaults_before_any_write(game):
|
|
assert db.get_score(game) == {"player_id": db.PLAYER_SHARED, "score": 0, "status": "non_commence"}
|
|
|
|
|
|
def test_set_score_value_and_status(game):
|
|
db.set_score_value(game, 42)
|
|
db.set_status(game, "en_cours")
|
|
score = db.get_score(game)
|
|
assert score["score"] == 42
|
|
assert score["status"] == "en_cours"
|
|
|
|
|
|
def test_set_status_rejects_unknown_value(game):
|
|
assert db.set_status(game, "n_importe_quoi") is False
|
|
assert db.get_score(game)["status"] == "non_commence"
|
|
|
|
|
|
def test_score_is_tracked_per_player(game):
|
|
db.set_score_value(game, 5, player_id="joueur-a")
|
|
db.set_score_value(game, 99, player_id="joueur-b")
|
|
assert db.get_score(game, "joueur-a")["score"] == 5
|
|
assert db.get_score(game, "joueur-b")["score"] == 99
|
|
assert db.get_score(game)["score"] == 0 # PLAYER_SHARED (aperçu créateur) inchangé
|
|
|
|
|
|
def test_apply_score_action_reuses_data_operations(game):
|
|
db.set_score_value(game, 10)
|
|
ok = screens.apply_score_action(game, {"data_operation": "incrementer", "data_value": "5"})
|
|
assert ok
|
|
assert db.get_score(game)["score"] == 15
|
|
|
|
ok = screens.apply_score_action(game, {"data_operation": "definir_nombre", "data_value": "100"})
|
|
assert ok
|
|
assert db.get_score(game)["score"] == 100
|
|
|
|
|
|
def test_apply_status_action_writes_status(game):
|
|
ok = screens.apply_status_action(game, {"data_value": "termine"})
|
|
assert ok
|
|
assert db.get_score(game)["status"] == "termine"
|
|
|
|
|
|
def test_apply_status_action_rejects_missing_value(game):
|
|
assert screens.apply_status_action(game, {}) is False
|
|
|
|
|
|
def test_flow_node_run_score_route(client, game):
|
|
screen_id = screens.create_screen(game, "Accueil")
|
|
resp = client.post(
|
|
f"/game/{game}/screens/{screen_id}/flow/nodes/add",
|
|
data=json.dumps({"node_type": "action", "action_type": "modifier_score", "data_operation": "incrementer", "data_value": "7"}),
|
|
content_type="application/json",
|
|
)
|
|
node_id = resp.get_json()["id"]
|
|
run_resp = client.post(f"/game/{game}/flow/nodes/{node_id}/run-score")
|
|
assert run_resp.get_json() == {"ok": True}
|
|
assert db.get_score(game)["score"] == 7
|
|
|
|
|
|
def test_flow_node_run_score_route_rejects_wrong_action_type(client, game):
|
|
screen_id = screens.create_screen(game, "Accueil")
|
|
resp = client.post(
|
|
f"/game/{game}/screens/{screen_id}/flow/nodes/add",
|
|
data=json.dumps({"node_type": "action", "action_type": "attendre", "data_value": "1"}),
|
|
content_type="application/json",
|
|
)
|
|
node_id = resp.get_json()["id"]
|
|
run_resp = client.post(f"/game/{game}/flow/nodes/{node_id}/run-score")
|
|
assert run_resp.status_code == 400
|
|
|
|
|
|
def test_flow_node_run_status_route(client, game):
|
|
screen_id = screens.create_screen(game, "Accueil")
|
|
resp = client.post(
|
|
f"/game/{game}/screens/{screen_id}/flow/nodes/add",
|
|
data=json.dumps({"node_type": "action", "action_type": "definir_statut_partie", "data_value": "echoue"}),
|
|
content_type="application/json",
|
|
)
|
|
node_id = resp.get_json()["id"]
|
|
run_resp = client.post(f"/game/{game}/flow/nodes/{node_id}/run-status")
|
|
assert run_resp.get_json() == {"ok": True}
|
|
assert db.get_score(game)["status"] == "echoue"
|
|
|
|
|
|
def test_game_scoring_view_route_reads_player_score(client, game):
|
|
db.set_score_value(game, 33, player_id="joueur-x")
|
|
db.set_status(game, "reussi", player_id="joueur-x")
|
|
resp = client.get(f"/game/{game}/scoring/joueur-x")
|
|
assert resp.get_json() == {
|
|
"player_id": "joueur-x", "score": 33, "status": "reussi",
|
|
"updated_at": resp.get_json()["updated_at"],
|
|
}
|
|
|
|
|
|
def test_two_players_get_independent_scores(game):
|
|
"""Le score est TOUJOURS par joueur (voir db/scoring/), jamais partagé
|
|
— même garantie que db/global_vars (voir tests/test_player_state.py),
|
|
vérifiée ici directement au niveau db/ (routes publiques retirées)."""
|
|
db.set_score_value(game, 10, player_id="alice")
|
|
db.set_status(game, "reussi", player_id="alice")
|
|
db.set_score_value(game, 20, player_id="bob")
|
|
|
|
assert db.get_score(game, "alice") == {
|
|
"player_id": "alice", "score": 10, "status": "reussi",
|
|
"updated_at": db.get_score(game, "alice")["updated_at"],
|
|
}
|
|
assert db.get_score(game, "bob")["score"] == 20
|
|
assert db.get_score(game, "bob")["status"] == "non_commence"
|
|
assert db.get_score(game)["score"] == 0 # aperçu créateur (PLAYER_SHARED) inchangé
|
|
|
|
|
|
def test_editor_exposes_score_and_status_action_fields(client, game):
|
|
screen_id = screens.create_screen(game, "Accueil")
|
|
html = client.get(f"/game/{game}/screens/{screen_id}/edit").get_data(as_text=True)
|
|
assert "nf-action-score-fields" in html
|
|
assert "nf-action-status-fields" in html
|
|
assert "Modifier le score" in html
|
|
assert "Définir le statut de la partie" in html
|