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
3 changes: 3 additions & 0 deletions app/platforms/implementations/openeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List

from fastapi import Response
from fastapi.responses import JSONResponse
import jwt
import openeo
import requests
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions app/schemas/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
...,
Expand Down
8 changes: 4 additions & 4 deletions app/services/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand All @@ -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)
)
Expand Down Expand Up @@ -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,
),
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 28 additions & 2 deletions tests/platforms/test_openeo_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/routers/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
),
Expand Down Expand Up @@ -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,
),
Expand Down
Loading