Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sensors): adds fetch_one sensor endpoint to API (#759)
* feat(sensors): adds fetch_one sensor endpoint to API Signed-off-by: GustaafL <guus@seita.nl> * refactor: review suggestions, changed test asserts Signed-off-by: GustaafL <guus@seita.nl> * docs(sensor): API changelog and FM changelog update Signed-off-by: GustaafL <guus@seita.nl> * docs(sensor): API changelog correct date Signed-off-by: GustaafL <guus@seita.nl> --------- Signed-off-by: GustaafL <guus@seita.nl> Signed-off-by: Nicolas Höning <nicolas@seita.nl> Co-authored-by: Nicolas Höning <nicolas@seita.nl>
- Loading branch information
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |