Fix test
This commit is contained in:
parent
8cb11722f4
commit
c801f1d771
15
papi/main.py
15
papi/main.py
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue