diff --git a/app/platforms/implementations/openeo.py b/app/platforms/implementations/openeo.py index fa8d25b..2d35e8d 100644 --- a/app/platforms/implementations/openeo.py +++ b/app/platforms/implementations/openeo.py @@ -3,6 +3,7 @@ from typing import List from fastapi import Response +from fastapi.responses import JSONResponse import jwt import openeo import requests @@ -169,6 +170,8 @@ async def _execute_synchronous_job_once( service = await self._build_datacube(user_token, title, details, parameters) logger.info("Executing synchronous OpenEO job") response = service.execute(auto_decode=False) + if isinstance(response, dict): + return JSONResponse(content=response) return Response( content=response.content, status_code=response.status_code, diff --git a/app/schemas/statistics.py b/app/schemas/statistics.py index c12f60c..5ec02c1 100644 --- a/app/schemas/statistics.py +++ b/app/schemas/statistics.py @@ -7,8 +7,8 @@ class EntityStatistics(BaseModel): total: int = Field(..., description="Total amount of records") by_status: Dict[str, int] = Field(..., description="Totals grouped by status") - by_platform: Dict[str, int] = Field( - ..., description="Totals grouped by platform label" + by_interface: Dict[str, int] = Field( + ..., description="Totals grouped by interface label" ) by_service: Dict[str, int] = Field( ..., diff --git a/app/services/statistics.py b/app/services/statistics.py index ade38bc..ad07a0a 100644 --- a/app/services/statistics.py +++ b/app/services/statistics.py @@ -161,7 +161,7 @@ def get_public_statistics( .group_by(ProcessingJobRecord.status) .all() ) - processing_jobs_by_platform = _normalize_grouped_counts( + processing_jobs_by_interface = _normalize_grouped_counts( processing_jobs_query.with_entities( ProcessingJobRecord.label, func.count(ProcessingJobRecord.id) ) @@ -178,7 +178,7 @@ def get_public_statistics( .group_by(UpscalingTaskRecord.status) .all() ) - upscaling_tasks_by_platform = _normalize_grouped_counts( + upscaling_tasks_by_interface = _normalize_grouped_counts( upscaling_tasks_query.with_entities( UpscalingTaskRecord.label, func.count(UpscalingTaskRecord.id) ) @@ -207,13 +207,13 @@ def get_public_statistics( processing_jobs=EntityStatistics( total=processing_jobs_total, by_status=processing_jobs_by_status, - by_platform=processing_jobs_by_platform, + by_interface=processing_jobs_by_interface, by_service=processing_jobs_by_service, ), upscaling_tasks=UpscalingStatistics( total=upscaling_tasks_total, by_status=upscaling_tasks_by_status, - by_platform=upscaling_tasks_by_platform, + by_interface=upscaling_tasks_by_interface, by_service=upscaling_tasks_by_service, average_processing_jobs_per_upscaling_task=average_jobs_per_upscaling_task, ), diff --git a/requirements.txt b/requirements.txt index f76f501..ef520c2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,8 +10,8 @@ mkdocs mkdocs-jupyter mkdocs-material mkdocs-material[diagrams] -mypy -mypy_extensions +mypy==1.16.0 +mypy_extensions==1.0.0 typing_extensions>=4.12.2 openeo psycopg2-binary diff --git a/tests/platforms/test_openeo_platform.py b/tests/platforms/test_openeo_platform.py index 9fc9f31..a63202a 100644 --- a/tests/platforms/test_openeo_platform.py +++ b/tests/platforms/test_openeo_platform.py @@ -705,9 +705,10 @@ async def test_setup_connection_propagates_auth_error( async def test_execute_sync_job_success( mock_pid, mock_connect, platform, service_details ): - mock_response = MagicMock() - mock_response.content = '{"id": "foobar"}' + mock_response = requests.Response() + mock_response._content = b'{"id": "foobar"}' mock_response.status_code = 200 + mock_response.headers["Content-Type"] = "application/json" mock_connection = MagicMock() mock_connect.return_value = mock_connection mock_connection.datacube_from_process.return_value.execute.return_value = ( @@ -726,6 +727,31 @@ async def test_execute_sync_job_success( mock_connect.assert_called_once_with("fake_token", service_details.endpoint) +@pytest.mark.asyncio +@patch.object(OpenEOPlatform, "_setup_connection") +@patch.object(OpenEOPlatform, "_get_process_id", return_value="process123") +async def test_execute_sync_job_dict_response( + mock_pid, mock_connect, platform, service_details +): + mock_connection = MagicMock() + mock_connect.return_value = mock_connection + mock_connection.datacube_from_process.return_value.execute.return_value = { + "id": "foobar" + } + + response = await platform.execute_synchronous_job( + user_token="fake_token", + title="Test Job", + details=service_details, + parameters={"param1": "value1"}, + format=OutputFormatEnum.GEOTIFF, + ) + + assert response.status_code == 200 + assert json.loads(response.body) == {"id": "foobar"} + assert response.media_type == "application/json" + + @pytest.mark.asyncio @patch.object(OpenEOPlatform, "_transform_parameters", return_value={}) @patch.object(OpenEOPlatform, "_build_datacube", new_callable=AsyncMock) diff --git a/tests/routers/test_statistics.py b/tests/routers/test_statistics.py index 9f4dc70..5ed8aac 100644 --- a/tests/routers/test_statistics.py +++ b/tests/routers/test_statistics.py @@ -17,7 +17,7 @@ def test_statistics_get_200(mock_get_public_statistics, client): processing_jobs=EntityStatistics( total=42, by_status={"finished": 30, "failed": 12}, - by_platform={"openeo": 40, "ogc_api_process": 2}, + by_interface={"openeo": 40, "ogc_api_process": 2}, by_service={ "variabilitymap": 40, "land-cover": 2, @@ -26,7 +26,7 @@ def test_statistics_get_200(mock_get_public_statistics, client): upscaling_tasks=UpscalingStatistics( total=10, by_status={"finished": 9, "failed": 1}, - by_platform={"openeo": 10}, + by_interface={"openeo": 10}, by_service={"variabilitymap": 10}, average_processing_jobs_per_upscaling_task=4.2, ), @@ -62,13 +62,13 @@ def test_statistics_get_200_with_date_filter(mock_get_public_statistics, client) processing_jobs=EntityStatistics( total=0, by_status={}, - by_platform={}, + by_interface={}, by_service={}, ), upscaling_tasks=UpscalingStatistics( total=0, by_status={}, - by_platform={}, + by_interface={}, by_service={}, average_processing_jobs_per_upscaling_task=0.0, ),