Merge branch 'feature/6/creer_sonde'

This commit is contained in:
Colin Goutte 2021-09-22 12:10:53 +02:00
commit 11ff6f0c52
2 changed files with 36 additions and 0 deletions

View File

@ -1,9 +1,17 @@
from typing import Optional
from pydantic import BaseModel
from fastapi import FastAPI
app = FastAPI()
sondes = []
class Sonde(BaseModel):
identifiant: str
nom: str
@app.get("/")
def read_root():
@ -13,3 +21,15 @@ 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)
sondes.append(sonde)
return
@app.get("/sonde/")
def list_sonde():
return [x for x in sondes]

View File

@ -3,6 +3,8 @@ from fastapi.testclient import TestClient
from papi.main import app
from papi.main import sondes
from papi import __version__
client = TestClient(app)
@ -16,3 +18,17 @@ 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
assert sonde1 in sondes
def test_lister_sondes():
sonde1 = {"identifiant": "masonde_001", "nom": "client1"}
response = client.get("/sonde/")
assert response.status_code == 200
assert sonde1 in response.json()