-
Notifications
You must be signed in to change notification settings - Fork 30
/
test_sensors_api.py
33 lines (25 loc) · 967 Bytes
/
test_sensors_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from __future__ import annotations
from flask import url_for
from flexmeasures import Sensor
from flexmeasures.api.tests.utils import get_auth_token
def test_fetch_one_sensor(
client,
setup_api_test_data: dict[str, Sensor],
):
sensor_id = 1
headers = make_headers_for("test_supplier_user_4@seita.nl", client)
response = client.get(
url_for("SensorAPI:fetch_one", id=sensor_id),
headers=headers,
)
print("Server responded with:\n%s" % response.json)
assert response.status_code == 200
assert response.json["name"] == "some gas sensor"
assert response.json["unit"] == "m³/h"
assert response.json["generic_asset_id"] == 4
assert response.json["timezone"] == "UTC"
def make_headers_for(user_email: str | None, client) -> dict:
headers = {"content-type": "application/json"}
if user_email:
headers["Authorization"] = get_auth_token(client, user_email, "testtest")
return headers