From 7962fc7f7dadefbfe1664605067098dc7df5188b Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Fri, 24 Sep 2021 13:08:40 +0200 Subject: [PATCH] Fix types --- papi/main.py | 18 +++++++++++++----- tests/test_papi.py | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/papi/main.py b/papi/main.py index 15acf59..d96f7bf 100644 --- a/papi/main.py +++ b/papi/main.py @@ -1,11 +1,14 @@ from typing import Optional from pydantic import BaseModel -from fastapi import FastAPI +from fastapi import FastAPI, Request, Body + +from collections import defaultdict app = FastAPI() -sondes = [] + +mesures = defaultdict(list) class Sonde(BaseModel): @@ -13,6 +16,9 @@ class Sonde(BaseModel): nom: str +sondes = {"test": Sonde(identifiant="test", nom="Testlocal")} + + @app.get("/") def read_root(): return {"msg": "Hello World"} @@ -26,10 +32,12 @@ def read_item(item_id: int, q: Optional[str] = None): @app.post("/sonde/") def post_sonde(sonde: Sonde): print(sonde) - sondes.append(sonde) - return + sondes[sonde.identifiant] = sonde + return list(sondes.values()) @app.get("/sonde/") def list_sonde(): - return [x for x in sondes] + return [x for x in sondes.values()] + + diff --git a/tests/test_papi.py b/tests/test_papi.py index 3a6d7c3..5288b36 100644 --- a/tests/test_papi.py +++ b/tests/test_papi.py @@ -24,7 +24,7 @@ def test_creer_sonde(): sonde1 = {"identifiant": "masonde_001", "nom": "client1"} response = client.post("/sonde/", json=sonde1) assert response.status_code == 200 - assert sonde1 in sondes + assert sonde1 in sondes.values() def test_lister_sondes():