Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: search filter on sensor API #1191

Merged
merged 30 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4dc4e04
feat: search filter on sensor API
joshuaunity Sep 20, 2024
4ab4263
Merge branch 'main' into feat-sensors-filters
joshuaunity Sep 24, 2024
92c58a0
feat: sensor API pagintion and search
joshuaunity Sep 24, 2024
658b525
refactor: reduce code repitition and code size
joshuaunity Sep 24, 2024
2114eca
refactor: request changes
joshuaunity Sep 25, 2024
1930365
feat: api to fetch all sensors under an asset
joshuaunity Sep 25, 2024
ecd3966
feat: added filter feature for sensor table, both name and unit filte…
joshuaunity Sep 25, 2024
2a37dde
feat: unit filter features on get sensors API
joshuaunity Sep 25, 2024
f8ebe9b
refactor: asset sensor and sensors API changes
joshuaunity Sep 25, 2024
5d9b547
feat: test case for asset_sensors API
joshuaunity Sep 25, 2024
e93b1fb
chore: few changes variable namings and import arrangement
joshuaunity Sep 26, 2024
d80f1ba
refactor: updated testcase with more checks and removed redundant code
joshuaunity Sep 26, 2024
461f1d2
chore: little changes on test(waiting for comment resolution)
joshuaunity Sep 26, 2024
dc3e8df
chore: moved formatResolution func to base.html
joshuaunity Sep 27, 2024
807f0d0
refactor: changes to asset sensors API and ISO formatter logic on for…
joshuaunity Sep 27, 2024
e92a8dd
chore: removed hard coded asset ID in asset sensors test case
joshuaunity Sep 27, 2024
8652c23
feat: test to get all sensors
joshuaunity Sep 30, 2024
ec4938a
Merge branch 'main' into feat-sensors-filters
nhoening Sep 30, 2024
dbd300b
fix: fix wrong imports
joshuaunity Sep 30, 2024
b08901d
refactor: expandd test cases for get sensors
joshuaunity Sep 30, 2024
651006a
refactor: expanded test case
joshuaunity Oct 1, 2024
5c7f797
chore: added to changelog
joshuaunity Oct 2, 2024
e420fa1
chore: updated change log
joshuaunity Oct 3, 2024
646de9c
refactor: dynamic expected results for test case
joshuaunity Oct 3, 2024
f4f5bf6
refactor: dynamic sensor name for test case
joshuaunity Oct 3, 2024
c5fedaf
Merge branch 'main' into feat-sensors-filters
joshuaunity Oct 4, 2024
4f987b2
chore: simplified testcase
joshuaunity Oct 8, 2024
289e78b
Merge branch 'main' into feat-sensors-filters
joshuaunity Oct 8, 2024
e8d4ad8
Merge branch 'main' into feat-sensors-filters
joshuaunity Oct 11, 2024
fe5b6fa
Merge branch 'main' into feat-sensors-filters
nhoening Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions flexmeasures/api/v3_0/tests/test_sensors_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@


@pytest.mark.parametrize(
"requesting_user, use_pagination",
[("test_supplier_user_4@seita.nl", False), ("test_supplier_user_4@seita.nl", True)],
"requesting_user, search_by, search_value, num_sensors, all_accessible, use_pagination",
[
("test_supplier_user_4@seita.nl", "°C", False, 3, True, False),
("test_supplier_user_4@seita.nl", None, True, 2, False, True),
],
indirect=["requesting_user"],
)
def test_fetch_sensors(
client,
setup_api_test_data,
requesting_user,
search_by,
search_value,
num_sensors,
all_accessible,
use_pagination,
):
"""
Expand All @@ -40,18 +47,47 @@ def test_fetch_sensors(
if use_pagination:
query["page"] = 1

if search_by:
joshuaunity marked this conversation as resolved.
Show resolved Hide resolved
query["unit"] = search_by

if all_accessible:
query["all_accessible"] = True

if search_value:
# get sensors from test data
dict_key = list(setup_api_test_data.keys())[1]
sensor = setup_api_test_data[dict_key]
keywords = sensor.name.split(" ")
query["filter"] = keywords # filter expects an array of strings

response = client.get(
url_for("SensorAPI:index"),
query_string=query,
)

print("Server responded with:\n%s" % response.json)
assert response.status_code == 200
joshuaunity marked this conversation as resolved.
Show resolved Hide resolved

joshuaunity marked this conversation as resolved.
Show resolved Hide resolved
if search_by:
assert is_valid_unit(response.json[0]["unit"])
joshuaunity marked this conversation as resolved.
Show resolved Hide resolved
assert response.json[0]["unit"] == "°C"

if use_pagination:
assert isinstance(response.json["data"][0], dict)
assert is_valid_unit(response.json["data"][0]["unit"])
assert response.json["num-records"] == 3
assert response.json["filtered-records"] == 3
print(
"Num records: %s" % response.json["num-records"],
response.json["filtered-records"],
)
if search_value:
# NOTE: Even if the entire sensor name was passed to filter, due to the nature of the filter
# logic, the response will contain all sensors that have most of the keywords in the name
assert response.json["data"][1]["name"] == sensor.name
assert response.json["num-records"] == num_sensors
joshuaunity marked this conversation as resolved.
Show resolved Hide resolved
assert response.json["filtered-records"] == num_sensors
else:
assert response.json["num-records"] == num_sensors
assert response.json["filtered-records"] == num_sensors
else:
assert isinstance(response.json, list)
assert is_valid_unit(response.json[0]["unit"])
Expand Down
Loading