From c801f1d771e584a53599ea59c68457f11332c870 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Mon, 27 Sep 2021 17:24:54 +0200 Subject: [PATCH] Fix test --- papi/main.py | 15 +++++++++++++-- tests/test_papi.py | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/papi/main.py b/papi/main.py index 2d032ec..02d51e0 100644 --- a/papi/main.py +++ b/papi/main.py @@ -14,11 +14,22 @@ mesures = defaultdict(list) notifications = defaultdict(list) +class Notifier: + @staticmethod + def __call__(idsonde, changes): + status = get_rapport(idsonde) + notifications[idsonde].append( + {"changes": changes, "status": [x for x in status]} + ) + + class Sonde(BaseModel): identifiant: str nom: str +Notifier = Notifier() + sondes = {"test": Sonde(identifiant="test", nom="Testlocal")} @@ -34,7 +45,6 @@ def read_root(): @app.post("/sonde/") def post_sonde(sonde: Sonde): - print(sonde) sondes[sonde.identifiant] = sonde return list(sondes.values()) @@ -71,7 +81,8 @@ def post_sonde_data(idsonde: str, body: dict = Body(...)): if diff else "" ) - + if content: + Notifier(idsonde, content) return { "count": len(mesures_) if mesures_[0] != default_sample() diff --git a/tests/test_papi.py b/tests/test_papi.py index 418957b..2d07cab 100644 --- a/tests/test_papi.py +++ b/tests/test_papi.py @@ -116,12 +116,17 @@ def test_onchange_notification(): id_sonde = "masonde_notif" histo = {"identifiant": id_sonde, "nom": "Test notification"} assert client.post("/sonde/", json=histo).ok + from papi.main import notifications + + notiflen = len(notifications[id_sonde]) + assert notiflen == 0 data = testutils.probe_sample_body( channel_name="test_historique", channel_id=0, status="ok" ) response = client.post(f"/sonde/{id_sonde}/", json=data) assert response.ok + assert len(notifications[id_sonde]) == notiflen + 1 jresp = response.json() @@ -131,6 +136,7 @@ def test_onchange_notification(): data = testutils.probe_sample_body( channel_name="test_historique", channel_id=0, status="ok" ) + response = client.post(f"/sonde/{id_sonde}/", json=data) assert response.ok