77 lines
1.8 KiB
Python
77 lines
1.8 KiB
Python
import pytest
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
from papi.main import app
|
|
|
|
from papi.main import sondes
|
|
|
|
from papi import __version__
|
|
from . import utils as testutils
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
def test_version():
|
|
assert __version__ == "0.1.0"
|
|
|
|
|
|
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.values()
|
|
|
|
|
|
def test_lister_sondes():
|
|
sonde1 = {"identifiant": "masonde_001", "nom": "client1"}
|
|
response = client.get("/sonde/")
|
|
assert response.status_code == 200
|
|
assert sonde1 in response.json()
|
|
|
|
|
|
def test_post_data():
|
|
id_ = "masonde_001"
|
|
from papi.main import mesures
|
|
|
|
curlen = len(mesures[id_])
|
|
|
|
data = testutils.probe_sample_body()
|
|
|
|
response = client.post(f"/sonde/{id_}/", json=data)
|
|
assert response.status_code == 200
|
|
assert response.json()["count"] == curlen + 1
|
|
|
|
|
|
def test_sample_report():
|
|
id_ = "masonde_001"
|
|
|
|
data = testutils.probe_sample_body()
|
|
response = client.post(f"/sonde/{id_}/", json=data)
|
|
assert response.status_code == 200
|
|
|
|
report = client.get(f"/sonde/{id_}/rapport")
|
|
rjson = report.json()
|
|
assert len(rjson) == 1
|
|
assert rjson[0] == "-1#Test channel ok"
|
|
|
|
data["channels"][0]["status"] = "error"
|
|
response = client.post(f"/sonde/{id_}/", json=data)
|
|
|
|
report = client.get(f"/sonde/{id_}/rapport")
|
|
rjson = report.json()
|
|
assert len(rjson) == 1
|
|
assert rjson[0] == "-1#Test channel error"
|
|
|
|
|
|
def test_cover():
|
|
with pytest.raises(ValueError):
|
|
testutils.probe_sample_body(status="erruer")
|