39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from pathlib import Path
|
|
|
|
from netatmo_service import create_app
|
|
from netatmo_service.data import extract_samples
|
|
|
|
|
|
class FakeClient:
|
|
configured = False
|
|
|
|
|
|
class FakeStore:
|
|
def ensure_all(self): pass
|
|
def last(self, name, field): return {"rrd": name, "data_point": field, "timestamp": 1, "value": 2.0}
|
|
def graph(self, name, period):
|
|
if name == "missing": raise KeyError(name)
|
|
return b"\x89PNG\r\n"
|
|
|
|
|
|
def app():
|
|
return create_app({"TESTING": True, "START_COLLECTOR": False, "RRD_STORE": FakeStore(), "NETATMO_CLIENT": FakeClient()})
|
|
|
|
|
|
def test_routes():
|
|
client = app().test_client()
|
|
assert client.get("/").status_code == 200
|
|
assert client.get("/last/outdoor/humidity").json["value"] == 2.0
|
|
assert client.get("/graph/wind/2weeks").mimetype == "image/png"
|
|
assert client.get("/graph/windyear").status_code == 200
|
|
|
|
|
|
def test_extract_sample_payload():
|
|
namespace = {}
|
|
exec(Path("payload_dict.py").read_text(), namespace)
|
|
names = {name: name.title() for name in ("outdoor", "wind", "bedroom", "study", "living")}
|
|
samples = extract_samples(namespace["payload"], names)
|
|
assert samples["outdoor"].values["pressure"] == 1004.8
|
|
assert samples["wind"].values["angle"] == 236.0
|
|
assert "bedroom" not in samples # unreachable module has no dashboard_data
|