Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion dataconnect/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Study:

@dataclass(frozen=True)
class StudiesResult:
total: int
total_records: int
studies: list[Study]
Comment thread
afieraru-mdsol marked this conversation as resolved.


Expand Down
9 changes: 4 additions & 5 deletions dataconnect/service/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,18 @@ def get_studies(self, search_study_name: str | None = None) -> StudiesResult:

Returns:
A :class:`StudiesResult` containing:
- ``total``: total number of studies accessible to the authenticated user.
- ``total_records``: total number of studies accessible to the authenticated user.
- ``studies``: list of :class:`Study` objects matching the criteria.
"""

request = ResourceQuery(action=_ACTION_LIST_STUDIES)
if search_study_name and search_study_name.strip() != "":
request = request.append_body({"search_study_name": search_study_name})
request = request.append_body({"search_study_name": search_study_name})

try:
resources = self._transport.list_resources(request)
total = resources[0].total_records if resources else 0
total_records = resources[0].total_records if resources else 0
studies = [resource_to_study(r) for r in resources]
return StudiesResult(total=total, studies=studies)
return StudiesResult(total_records=total_records, studies=studies)
Comment thread
afieraru-mdsol marked this conversation as resolved.
except Exception as ex:
raise translate_error(ex) from ex

Expand Down
8 changes: 4 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# # import pytest

# from dataconnect.client import DataConnectClient
# from dataconnect.models import Dataset, DatasetVersion, Study, StudiesResult
# from dataconnect.models import StudiesResult


# def _make_dataframe() -> pd.DataFrame:
Expand Down Expand Up @@ -162,7 +162,7 @@

# def get_studies(self, search_study_name: str | None = None) -> StudiesResult:
# self.search_study_name = search_study_name
# return StudiesResult(total=0, studies=[])
# return StudiesResult(total_records=0, studies=[])

# def close(self) -> None:
# self.was_closed = True
Expand All @@ -175,7 +175,7 @@
# result = client.get_studies()

# assert isinstance(result, StudiesResult)
# assert result.total == 0
# assert result.total_records == 0
# assert result.studies == []
# assert service.search_study_name is None

Expand All @@ -187,7 +187,7 @@
# result = client.get_studies(search_study_name="cardio")

# assert isinstance(result, StudiesResult)
# assert result.total == 0
# assert result.total_records == 0
# assert result.studies == []
# assert service.search_study_name == "cardio"

Expand Down
18 changes: 9 additions & 9 deletions tests/test_service_default.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# from __future__ import annotations

# import pytest

# from dataconnect.exceptions import ValidationError
# from dataconnect.models import StudiesResult
# from dataconnect.service.default import DefaultDataConnectService
# from dataconnect.transport.models import DataRef, ResourceInfo, ResourceQuery
Expand Down Expand Up @@ -32,19 +29,21 @@
# )


# def test_get_studies_without_search_name_uses_empty_request_body() -> None:
# def test_get_studies_without_search_name_uses_none_in_body() -> None:
# # When called without a filter, search_study_name defaults to None and is
# # included in the JSON body as null.
# transport = StubTransport(resources=[_study_resource()])
# service = DefaultDataConnectService(transport)

# result = service.get_studies()

# assert isinstance(result, StudiesResult)
# assert result.total == 1
# assert result.total_records == 1
# assert len(result.studies) == 1
# assert result.studies[0].name == "Study A"
# assert transport.last_request is not None
# assert transport.last_request.action == "studies.list"
# assert transport.last_request.body == ""
# assert transport.last_request.body == '{"search_study_name":null}'


# def test_get_studies_with_search_name_sets_request_body() -> None:
Expand All @@ -54,7 +53,7 @@
# result = service.get_studies(search_study_name="Cardio")

# assert isinstance(result, StudiesResult)
# assert result.total == 5
# assert result.total_records == 5
# assert len(result.studies) == 1
# assert result.studies[0].name == "Cardio Study"
# assert transport.last_request is not None
Expand All @@ -68,11 +67,12 @@
# result = service.get_studies()

# assert isinstance(result, StudiesResult)
# assert result.total == 0
# assert result.total_records == 0
# assert result.studies == []


# def test_get_studies_accepts_none_search_name() -> None:
# # Passing None explicitly is the same as the default — body contains null.
# transport = StubTransport(resources=[_study_resource()])
# service = DefaultDataConnectService(transport)

Expand All @@ -81,4 +81,4 @@
# assert isinstance(result, StudiesResult)
# assert len(result.studies) == 1
# assert transport.last_request is not None
# assert transport.last_request.body == ""
# assert transport.last_request.body == '{"search_study_name":null}'
Loading