Add testecase and rename
This commit is contained in:
parent
59aae08188
commit
dce90e6621
33
papi/main.py
33
papi/main.py
|
@ -195,3 +195,36 @@ def historique(idsonde, db: Session = Depends(get_db)):
|
|||
for d in diff["changements"]:
|
||||
line = date, *utils.clean_state(d)
|
||||
yield " ".join(line)
|
||||
|
||||
|
||||
@app.get("/sonde/{idsonde}/historique/text")
|
||||
def list_notification_as_text(
|
||||
request: Request, idsonde: str, db: Session = Depends(get_db)
|
||||
):
|
||||
def coloriser(message):
|
||||
d = {"error": "red", "warning": "orange", "pending": "yellow", "ok": "green"}
|
||||
for k, v in d.items():
|
||||
if message.endswith(k):
|
||||
return "color: %s;" % v
|
||||
return ""
|
||||
|
||||
if not (sonde := crud.get_sonde(db, idsonde)):
|
||||
return
|
||||
mesures = sonde.mesures
|
||||
|
||||
for previous, present in zip(mesures, mesures[1:]):
|
||||
date = present.content["date"]
|
||||
previous = utils.prepare(previous.content)
|
||||
present = utils.prepare(present.content)
|
||||
all_channels = sorted(set((*previous["channels"], *present["channels"])))
|
||||
|
||||
diff = utils.compare(all_channels, previous, present)
|
||||
res = []
|
||||
if diff:
|
||||
for d in diff["changements"]:
|
||||
line = date, *utils.clean_state(d)
|
||||
res.append(" ".join(line))
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"historique.html", context={"request": request, "lines": res}
|
||||
)
|
||||
|
|
|
@ -112,6 +112,14 @@ def test_historique():
|
|||
assert perte_supervision[-1] == f"{data['date']} test_historique error absent"
|
||||
|
||||
|
||||
def test_historique_rendering():
|
||||
idsonde = "masonde_001"
|
||||
notifs_text = client.get(f"/sonde/{idsonde}/historique/text")
|
||||
assert notifs_text.ok
|
||||
content = notifs_text
|
||||
assert f"absent" in content.text.lower()
|
||||
|
||||
|
||||
def test_onchange_notification():
|
||||
id_sonde = "masonde_notif"
|
||||
histo = {"identifiant": id_sonde, "nom": "Test notification"}
|
||||
|
@ -148,7 +156,7 @@ def test_onchange_notification():
|
|||
assert len(notifs.json()) == 1
|
||||
|
||||
|
||||
def test_template_rendering():
|
||||
def test_notif_rendering():
|
||||
idsonde = "masonde_001"
|
||||
notifs_text = client.get(f"/notifications/{idsonde}/text")
|
||||
assert notifs_text.ok
|
||||
|
|
Loading…
Reference in New Issue