Skip to content

Commit a432e9d

Browse files
committed
Add error handling for evaluation content retrieval and update provider method signature
1 parent e2ea493 commit a432e9d

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

data_hub_api/docmaps/v2/api_router.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ def get_enhanced_preprints_docmaps_by_manuscript_id_by_publisher_elife(manuscrip
3434

3535
@router.get("/v2/evaluation/get-by-evaluation-id", response_class=HTMLResponse)
3636
def get_evaluation_text_by_evaluation_id(evaluation_id: str):
37-
return docmaps_provider.get_evaluation_content_by_id(evaluation_id)
37+
evaluation_content = docmaps_provider.get_evaluation_content_by_id(evaluation_id)
38+
if not evaluation_content:
39+
raise HTTPException(
40+
status_code=404,
41+
detail=f"No evaluation content available for evaluation_id: {evaluation_id}"
42+
)
43+
return evaluation_content
3844

3945
return router

data_hub_api/docmaps/v2/provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ def iter_docmaps_index_json_stream(self):
8888
raise
8989
LOGGER.info('Finished streaming docmaps index as JSON.')
9090

91-
def get_evaluation_content_by_id(self, evaluation_id: str) -> str:
91+
def get_evaluation_content_by_id(self, evaluation_id: str) -> Optional[str]:
9292
return 'dummy evaluation content for evaluation_id: ' + evaluation_id

tests/unit_tests/docmaps/v2/api_router_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ def test_should_return_docmap_from_provider_by_publisher_for_individual_manuscri
7272
assert response.status_code == 200
7373
assert response.json() == article_docmap_list[0]
7474

75+
def test_should_return_not_found_status_code_for_invalid_evaluation_id(
76+
self,
77+
docmaps_provider_mock: MagicMock
78+
):
79+
docmaps_provider_mock.get_evaluation_content_by_id.return_value = None
80+
client = create_test_client(docmaps_provider_mock)
81+
response = client.get(
82+
'/v2/evaluation/get-by-evaluation-id',
83+
params={'evaluation_id': 'non_existent_evaluation_id_1'}
84+
)
85+
assert response.status_code == 404
86+
7587
def test_should_return_evaluation_content_from_provider(
7688
self,
7789
docmaps_provider_mock: MagicMock

0 commit comments

Comments
 (0)