-
Notifications
You must be signed in to change notification settings - Fork 0
[MCC-1475989] Create-get-studies #19
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b3452e5
feat: added search_study_name parameter and unit tests
nmakarava-mdsol a1bf019
Removed test file with test token
nmakarava-mdsol a7d9c61
fix: Apply ruff lint and format fixes
nmakarava-mdsol 7a5a8c0
fix: tests
nmakarava-mdsol 9d2556e
fix: query param name
nmakarava-mdsol 98a5900
fix: updated validation to allow empty string to be aligned with R
nmakarava-mdsol a1495d2
fix: fixed tests
nmakarava-mdsol f6c07c4
fix: fixes per feedbacks
nmakarava-mdsol c977997
fix: merged main
nmakarava-mdsol 414c037
fix: fixed tests
nmakarava-mdsol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,15 @@ | ||
| """Input validation helpers for service-layer operations.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataconnect.exceptions import ValidationError | ||
|
|
||
|
|
||
| def validate_search_study_name(search_study_name: str | None) -> None: | ||
| """Validate optional study-name filter used by ``get_studies``.""" | ||
|
|
||
| if not search_study_name: | ||
| return | ||
|
|
||
| if not isinstance(search_study_name, str): | ||
| raise ValidationError("search_study_name must be a string") | ||
|
nmakarava-mdsol marked this conversation as resolved.
|
||
This file contains hidden or 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 hidden or 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,77 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from dataconnect.exceptions import ValidationError | ||
| from dataconnect.service.default import DefaultDataConnectService | ||
| from dataconnect.transport.models import DataRef, ResourceInfo, ResourceQuery | ||
|
|
||
|
|
||
| class StubTransport: | ||
| def __init__(self, resources: list[ResourceInfo]) -> None: | ||
| self.resources = resources | ||
| self.last_request: ResourceQuery | None = None | ||
|
|
||
| def list_resources(self, request: ResourceQuery) -> list[ResourceInfo]: | ||
| self.last_request = request | ||
| return self.resources | ||
|
|
||
| def close(self) -> None: | ||
| return None | ||
|
|
||
|
|
||
| def _study_resource(name: str = "Study A") -> ResourceInfo: | ||
| payload = (f'{{"uuid":"12345678-1234-1234-1234-123456789abc","name":"{name}","environments":[]}}').encode() | ||
|
|
||
| return ResourceInfo( | ||
| descriptor=b"", | ||
| endpoints=[DataRef(ticket=payload)], | ||
| total_records=1, | ||
| schema_bytes=b"", | ||
| ) | ||
|
|
||
|
|
||
| def test_get_studies_without_search_name_uses_empty_request_body() -> None: | ||
| transport = StubTransport(resources=[_study_resource()]) | ||
| service = DefaultDataConnectService(transport) | ||
|
|
||
| studies = service.get_studies() | ||
|
|
||
| assert len(studies) == 1 | ||
| assert studies[0].name == "Study A" | ||
| assert transport.last_request is not None | ||
| assert transport.last_request.action == "studies.list" | ||
| assert transport.last_request.body == "" | ||
|
|
||
|
|
||
| def test_get_studies_with_search_name_sets_request_body() -> None: | ||
| transport = StubTransport(resources=[_study_resource("Cardio Study")]) | ||
| service = DefaultDataConnectService(transport) | ||
|
|
||
| studies = service.get_studies(search_study_name="Cardio") | ||
|
|
||
| assert len(studies) == 1 | ||
| assert studies[0].name == "Cardio Study" | ||
| assert transport.last_request is not None | ||
| assert transport.last_request.body == '{"search_study_name":"Cardio"}' | ||
|
|
||
|
|
||
| def test_get_studies_rejects_non_string_search_name() -> None: | ||
| transport = StubTransport(resources=[]) | ||
| service = DefaultDataConnectService(transport) | ||
|
|
||
| with pytest.raises(ValidationError, match="search_study_name must be a string"): | ||
| service.get_studies(search_study_name=123) # type: ignore[arg-type] | ||
|
|
||
| assert transport.last_request is None | ||
|
|
||
|
|
||
| def test_get_studies_accepts_none_search_name() -> None: | ||
| transport = StubTransport(resources=[_study_resource()]) | ||
| service = DefaultDataConnectService(transport) | ||
|
|
||
| studies = service.get_studies(search_study_name=None) | ||
|
|
||
| assert len(studies) == 1 | ||
| assert transport.last_request is not None | ||
| assert transport.last_request.body == "" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.