From f05808b226bd69401932e771aa2ef1276a20b439 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Fri, 1 Oct 2021 11:32:35 +0200 Subject: [PATCH] Fix report output formating --- papi/main.py | 7 +++++-- tests/test_papi.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/papi/main.py b/papi/main.py index 230fc1e..0e4a6cc 100644 --- a/papi/main.py +++ b/papi/main.py @@ -79,7 +79,9 @@ def list_notification(idsonde: str): @app.get("/notifications/{idsonde}/text") def list_notification_as_text(idsonde: str): - return "Contenu" + content = notifications[idsonde][-1] + + return @app.post("/sonde/{idsonde}/") @@ -127,10 +129,11 @@ def get_rapport(idsonde): else: last = last.content last = utils.prepare(last) + for name, data in sorted( last["channels"].items(), key=lambda text: float(text[0].split("#")[0]) ): - yield f'{name} {data["status"]}' + yield f'{name.split("#", 1)[1]} {data["status"]}' @app.get("/sonde/{idsonde}/historique") diff --git a/tests/test_papi.py b/tests/test_papi.py index da2e6a3..206ea0b 100644 --- a/tests/test_papi.py +++ b/tests/test_papi.py @@ -62,7 +62,7 @@ def test_sample_report(): report = client.get(f"/sonde/{id_}/rapport") rjson = report.json() assert len(rjson) == 1 - assert rjson[0] == "-1#Test channel ok" + assert rjson[0] == "Test channel ok" data["channels"][0]["status"] = "error" response = client.post(f"/sonde/{id_}/", json=data) @@ -70,7 +70,7 @@ def test_sample_report(): report = client.get(f"/sonde/{id_}/rapport") rjson = report.json() assert len(rjson) == 1 - assert rjson[0] == "-1#Test channel error" + assert rjson[0] == "Test channel error" def test_historique():