Skip to content

Commit 02dcf33

Browse files
committed
feat: cover sensor data source type filter
Context: - Issue #2045 needs coverage for source type filtering on GET sensor data. - The existing sensor data fixture includes user and demo script sources. Change: - Add matching user and demo script source_type cases. - Add a non-matching scheduler source_type case returning empty values. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
1 parent 886805b commit 02dcf33

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

flexmeasures/api/v3_0/tests/test_sensor_data.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,59 @@ def test_get_sensor_data_filtered_by_source_account(
166166
assert all(a == b for a, b in zip(values, expected))
167167

168168

169+
@pytest.mark.parametrize(
170+
"source_type, expected",
171+
[
172+
(
173+
"user",
174+
[
175+
sum(GAS_MEASUREMENTS_10MIN[0:2]) / 2, # 91.5
176+
GAS_MEASUREMENTS_10MIN[2], # 92.1
177+
None,
178+
None,
179+
],
180+
),
181+
(
182+
"demo script",
183+
[
184+
GAS_MEASUREMENTS_10MIN[0], # 91.3
185+
GAS_MEASUREMENTS_10MIN[2], # 92.1
186+
None,
187+
None,
188+
],
189+
),
190+
("scheduler", [None, None, None, None]),
191+
],
192+
)
193+
@pytest.mark.parametrize(
194+
"requesting_user", ["test_supplier_user_4@seita.nl"], indirect=True
195+
)
196+
def test_get_sensor_data_filtered_by_source_type(
197+
client,
198+
setup_api_test_data: dict[str, Sensor],
199+
requesting_user,
200+
source_type,
201+
expected,
202+
):
203+
"""Check that GET /sensors/<id>/data can filter by source type."""
204+
sensor = setup_api_test_data["some gas sensor"]
205+
message = {
206+
"start": "2021-05-02T00:00:00+02:00",
207+
"duration": "PT1H20M",
208+
"horizon": "PT0H",
209+
"unit": "m³/h",
210+
"source_type": source_type,
211+
"resolution": "PT20M",
212+
}
213+
response = client.get(
214+
url_for("SensorAPI:get_data", id=sensor.id),
215+
query_string=message,
216+
)
217+
print("Server responded with:\n%s" % response.json)
218+
assert response.status_code == 200
219+
assert all(a == b for a, b in zip(response.json["values"], expected))
220+
221+
169222
@pytest.mark.parametrize(
170223
"requesting_user, status_code",
171224
[

0 commit comments

Comments
 (0)