Add test for notification
This commit is contained in:
parent
e421f644f4
commit
80cc692f22
35
papi/main.py
35
papi/main.py
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue