Test and implementation of sonde post

This commit is contained in:
Colin Goutte 2021-09-22 11:27:39 +02:00
parent 4c64cc8529
commit ab5d69e44d
2 changed files with 18 additions and 0 deletions

View File

@ -1,10 +1,16 @@
from typing import Optional
from pydantic import BaseModel
from fastapi import FastAPI
app = FastAPI()
class Sonde(BaseModel):
identifiant: str
nom: str
@app.get("/")
def read_root():
return {"msg": "Hello World"}
@ -13,3 +19,9 @@ def read_root():
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
return {"item_id": item_id, "q": q}
@app.post("/sonde/")
def post_sonde(sonde: Sonde):
print(sonde)
return

View File

@ -16,3 +16,9 @@ def test_read_main():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"msg": "Hello World"}
def test_creer_sonde():
sonde1 = {"identifiant": "masonde_001", "nom": "client1"}
response = client.post("/sonde/", json=sonde1)
assert response.status_code == 200