Fix types

This commit is contained in:
Colin Goutte 2021-09-24 13:08:40 +02:00
parent 0aeeaf2e6a
commit 7962fc7f7d
2 changed files with 14 additions and 6 deletions

View File

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

View File

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