Add test for notification

This commit is contained in:
Colin Goutte 2021-09-27 16:40:45 +02:00
parent e421f644f4
commit 80cc692f22
2 changed files with 26 additions and 13 deletions

View File

@ -45,18 +45,31 @@ def default_sample():
@app.post("/sonde/{idsonde}/")
def post_sonde_data(idsonde: str, body: dict = Body(...)):
if idsonde in sondes:
mesures_ = mesures[idsonde]
if not mesures_:
mesures_.append(default_sample())
mesures_.append(body)
if idsonde not in sondes:
return
print(len(mesures_))
return {
"count": len(mesures_)
if mesures_[0] != default_sample()
else len(mesures_) - 1
}
mesures_ = mesures[idsonde]
if not mesures_:
mesures_.append(default_sample())
mesures_.append(body)
date = body["date"]
previous = utils.prepare(mesures_[-2])
present = utils.prepare(mesures_[-1])
all_channels = sorted(set((*previous["channels"], *present["channels"])))
diff, notify = utils.compare(all_channels, previous, present), {}
if diff:
content = [" ".join((date, *utils.clean_state(d))) for d in diff["changements"]]
notify["changes"] = content
return {
"count": len(mesures_)
if mesures_[0] != default_sample()
else len(mesures_) - 1,
"notify": notify,
}
@app.get("/sonde/{idsonde}/rapport")

View File

@ -126,9 +126,9 @@ def test_onchange_notification():
jresp = response.json()
assert jresp["notify"]
assert jresp["notify"]["targets"]
# assert jresp["notify"]["targets"]
assert jresp["notify"]["changes"]
assert jresp["notify"]["status"]
# assert jresp["notify"]["status"]
assert len(jresp["notify"]) == 1