This commit is contained in:
Colin Goutte 2021-09-27 17:24:54 +02:00
parent 8cb11722f4
commit c801f1d771
2 changed files with 19 additions and 2 deletions

View File

@ -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()

View File

@ -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