Skip to content

Commit 392bc06

Browse files
authored
feat: adds table args (#5)
* feat: adds table args * fix docstring * addresses comments * linters
1 parent 89eb052 commit 392bc06

3 files changed

Lines changed: 53 additions & 11 deletions

File tree

aind-dataverse-service-server/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ readme = "README.md"
1717
dynamic = ["version"]
1818

1919
dependencies = [
20-
'allen-powerplatform-client>=0.1.0',
20+
'allen-powerplatform-client>=0.1.4',
2121
'aind-settings-utils>=0.0.3',
2222
'httpx',
2323
'pydantic>=2.0',

aind-dataverse-service-server/src/aind_dataverse_service_server/route.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import List
44

5-
from fastapi import APIRouter, HTTPException, Path, status
5+
from fastapi import APIRouter, HTTPException, Path, Query, status
66
from aind_dataverse_service_server.models import HealthCheck, EntityTableRow
77
from fastapi_cache.decorator import cache
88
from azure.core.credentials import AccessToken
@@ -66,7 +66,17 @@ async def get_table(
6666
"value": "cr138_projects",
6767
}
6868
},
69-
)
69+
),
70+
columns: str = Query(
71+
default=None,
72+
description="Comma-separated column names to select from the table",
73+
example="modifiedon,statecode,cr138_projectname",
74+
),
75+
filter: str = Query(
76+
default=None,
77+
description="OData-style filter expression",
78+
example="cr138_projectname eq 'Barseq_GeneticTools'",
79+
),
7080
):
7181
"""
7282
## Table Data
@@ -83,11 +93,13 @@ async def get_table(
8393
configuration.access_token = bearer_token
8494
with allen_powerplatform_client.ApiClient(configuration) as api_client:
8595
api_instance = allen_powerplatform_client.DefaultApi(api_client)
86-
api_version = settings.api_version
87-
body = allen_powerplatform_client.GetTableRequest(
88-
table_name=entity_set_table_name
89-
)
9096
try:
97+
api_version = settings.api_version
98+
body = allen_powerplatform_client.GetTableRequest(
99+
table_name=entity_set_table_name,
100+
columns=columns,
101+
filter=filter,
102+
)
91103
api_response = api_instance.get_table(
92104
api_version=api_version, body=body, _request_timeout=10
93105
)

aind-dataverse-service-server/tests/test_route.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ def test_get_table_exception_response(
109109

110110
response = client.get("/tables/non_existent_table")
111111
assert 404 == response.status_code
112-
assert (
113-
"Error fetching non_existent_table"
114-
in response.json()["detail"]
115-
)
112+
assert "Error fetching non_existent_table" in response.json()["detail"]
116113

117114
@patch(
118115
"aind_dataverse_service_server.route."
@@ -145,6 +142,39 @@ def test_get_table_info_200_response(
145142
assert len(response.json()) == 3
146143
assert response.json()[0]["entitysetname"] == "cr138_projects"
147144

145+
@patch(
146+
"aind_dataverse_service_server.route."
147+
"allen_powerplatform_client.DefaultApi"
148+
)
149+
@patch(
150+
"aind_dataverse_service_server.route."
151+
"allen_powerplatform_client.ApiClient"
152+
)
153+
@patch("aind_dataverse_service_server.route.get_access_token")
154+
def test_get_table_with_query_params(
155+
self,
156+
mock_get_token: MagicMock,
157+
mock_api_client: MagicMock,
158+
mock_default_api: MagicMock,
159+
client: TestClient,
160+
mock_table_data,
161+
):
162+
"""Tests table data retrieval with all optional query parameters"""
163+
mock_get_token.return_value = "mock_token"
164+
mock_instance = MagicMock()
165+
mock_instance.get_table.return_value = mock_table_data
166+
mock_default_api.return_value = mock_instance
167+
mock_api_client.return_value.__enter__.return_value = MagicMock()
168+
169+
params = {
170+
"columns": "name,createdon",
171+
"filter": "status eq 'Active'",
172+
}
173+
response = client.get("/tables/cr138_projects", params=params)
174+
assert response.status_code == 200
175+
assert isinstance(response.json(), list)
176+
assert len(response.json()) == 2
177+
148178

149179
if __name__ == "__main__":
150180
pytest.main([__file__])

0 commit comments

Comments
 (0)