62 lignes
1,6 Kio
Python
62 lignes
1,6 Kio
Python
#!/usr/bin/env python3
|
|
import pytest
|
|
from starlette.testclient import TestClient
|
|
import json
|
|
|
|
from pyheatpump.heatpump import app
|
|
|
|
|
|
def test_get_(set_test_db):
|
|
c = TestClient(app)
|
|
r = c.get('/')
|
|
assert r.status_code == 200
|
|
|
|
resp = r.content.decode()
|
|
assert isinstance(resp, str)
|
|
|
|
d_resp = json.loads(resp)
|
|
assert isinstance(d_resp, dict)
|
|
|
|
|
|
def test_dict(set_test_db):
|
|
c = TestClient(app)
|
|
r = c.get('/')
|
|
assert r.status_code == 200
|
|
|
|
resp = r.content.decode()
|
|
assert isinstance(resp, str)
|
|
|
|
print(resp)
|
|
d_resp = json.loads(resp)
|
|
assert isinstance(d_resp, dict)
|
|
print(d_resp)
|
|
|
|
assert 'macAddress' in d_resp.keys()
|
|
assert isinstance(d_resp['macAddress'], str)
|
|
assert 'Analog' in d_resp.keys()
|
|
assert isinstance(d_resp['Analog'], dict)
|
|
int_keys = list(map(int, d_resp['Analog'].keys()))
|
|
assert min(int_keys) == 10
|
|
assert max(int_keys) == 17
|
|
assert d_resp['Analog']['10'] == 4.2
|
|
assert d_resp['Analog']['17'] == -2953.6
|
|
|
|
assert 'Digital' in d_resp.keys()
|
|
assert isinstance(d_resp['Digital'], dict)
|
|
int_keys = list(map(int, d_resp['Digital'].keys()))
|
|
assert min(int_keys) == 10
|
|
assert max(int_keys) == 14
|
|
|
|
assert d_resp['Digital']['10'] == False
|
|
assert d_resp['Digital']['14'] == True
|
|
|
|
assert 'Integer' in d_resp.keys()
|
|
assert isinstance(d_resp['Integer'], dict)
|
|
int_keys = list(map(int, d_resp['Integer'].keys()))
|
|
print(int_keys)
|
|
assert min(int_keys) == 1
|
|
assert max(int_keys) == 10
|
|
|
|
assert d_resp['Integer']['1'] == 101
|
|
assert d_resp['Integer']['10'] == 24
|
|
|