From 8cb11722f4064dc9d59a3c588935e462d29d7217 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Mon, 27 Sep 2021 17:06:59 +0200 Subject: [PATCH] Refactor --- papi/main.py | 12 +++++++----- tests/test_papi.py | 6 +----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/papi/main.py b/papi/main.py index a647e07..2d032ec 100644 --- a/papi/main.py +++ b/papi/main.py @@ -64,17 +64,19 @@ def post_sonde_data(idsonde: str, body: dict = Body(...)): present = utils.prepare(mesures_[-1]) all_channels = sorted(set((*previous["channels"], *present["channels"]))) - diff, notify = utils.compare(all_channels, previous, present), {} - if diff: + diff = utils.compare(all_channels, previous, present) - content = [" ".join((date, *utils.clean_state(d))) for d in diff["changements"]] - notify["changes"] = content + content = ( + [" ".join((date, *utils.clean_state(d))) for d in diff["changements"]] + if diff + else "" + ) return { "count": len(mesures_) if mesures_[0] != default_sample() else len(mesures_) - 1, - "notify": notify, + "notify": content, } diff --git a/tests/test_papi.py b/tests/test_papi.py index 767dd55..418957b 100644 --- a/tests/test_papi.py +++ b/tests/test_papi.py @@ -126,11 +126,7 @@ def test_onchange_notification(): jresp = response.json() assert jresp["notify"] - # assert jresp["notify"]["targets"] - assert jresp["notify"]["changes"] - # assert jresp["notify"]["status"] - - assert len(jresp["notify"]) == 1 + assert jresp["notify"][0].split(" ", 1)[1] == "test_historique absent ok" data = testutils.probe_sample_body( channel_name="test_historique", channel_id=0, status="ok"