Skip to content

Commit 4176e3b

Browse files
committed
check code update
1 parent fe282d9 commit 4176e3b

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

services/staging/rs_server_staging/main.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@
2424
from dask.distributed import LocalCluster
2525
from fastapi import APIRouter, FastAPI, HTTPException, Path
2626
from pygeoapi.api import API
27+
from pygeoapi.process.base import JobNotFoundError
2728
from pygeoapi.process.manager.postgresql import PostgreSQLManager
28-
from pygeoapi.process.base import (
29-
JobNotFoundError,
30-
JobResultNotFoundError,
31-
ProcessorGenericError
32-
)
3329
from pygeoapi.provider.postgresql import get_engine
3430
from rs_server_common.authentication.authentication_to_external import (
3531
init_rs_server_config_yaml,
@@ -48,8 +44,8 @@
4844
from starlette.status import (
4945
HTTP_200_OK,
5046
HTTP_404_NOT_FOUND,
51-
HTTP_503_SERVICE_UNAVAILABLE,
5247
HTTP_500_INTERNAL_SERVER_ERROR,
48+
HTTP_503_SERVICE_UNAVAILABLE,
5349
)
5450

5551
# flake8: noqa: F401
@@ -328,16 +324,13 @@ async def get_specific_job_result_endpoint(job_id: str = Path(..., title="The ID
328324
# Handle case when job_id is not found
329325
return JSONResponse(
330326
status_code=HTTP_404_NOT_FOUND,
331-
content={
332-
"title": "No Such Job",
333-
"detail": f"Job with ID {job_id} not found."
334-
}
327+
content={"title": "No Such Job", "detail": f"Job with ID {job_id} not found."},
335328
)
336-
except Exception as e:
329+
except Exception as e: # pylint: disable=broad-exception-caught
337330
# Catch any other unexpected exceptions
338331
return JSONResponse(
339332
status_code=HTTP_500_INTERNAL_SERVER_ERROR,
340-
content={"title": "Internal Server Error", "detail": str(e)}
333+
content={"title": "Internal Server Error", "detail": str(e)},
341334
)
342335

343336

services/staging/tests/test_staging.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import pytest
2020
from fastapi import FastAPI
21+
from pygeoapi.process.base import JobNotFoundError
2122
from rs_server_staging.main import (
2223
app_lifespan,
2324
get_config_contents,
@@ -28,14 +29,8 @@
2829
from starlette.status import (
2930
HTTP_200_OK,
3031
HTTP_404_NOT_FOUND,
31-
HTTP_503_SERVICE_UNAVAILABLE,
3232
HTTP_500_INTERNAL_SERVER_ERROR,
33-
)
34-
35-
from pygeoapi.process.base import (
36-
JobNotFoundError,
37-
JobResultNotFoundError,
38-
ProcessorGenericError
33+
HTTP_503_SERVICE_UNAVAILABLE,
3934
)
4035

4136
expected_jobs_test = [
@@ -321,7 +316,7 @@ async def test_get_job_result(
321316
"""
322317
# Mock app.extra to ensure 'db_table' exists
323318
mock_db_table = mocker.MagicMock()
324-
319+
325320
if expected_job["identifier"] == "non_existing":
326321
# Simulate JobNotFoundError for non-existing jobs (HTTP 404)
327322
mock_db_table.get_job.side_effect = JobNotFoundError
@@ -340,20 +335,18 @@ async def test_get_job_result(
340335
}
341336
else:
342337
# Return an existing job normally (HTTP 200)
343-
job_index = next(
344-
i for i, job in enumerate(mock_jobs) if job["identifier"] == expected_job["identifier"]
345-
)
338+
job_index = next(i for i, job in enumerate(mock_jobs) if job["identifier"] == expected_job["identifier"])
346339
mock_db_table.get_job.return_value = mock_jobs[job_index]
347340
expected_status = HTTP_200_OK
348341
expected_response = expected_job["status"]
349-
342+
350343
# Patch app.extra with the mock db_table
351344
mocker.patch.object(staging_client.app, "extra", {"process_manager": mock_db_table})
352345

353346
# Call the API
354-
job_id = expected_job.get("identifier")
347+
job_id = expected_job.get("identifier")
355348
response = staging_client.get(f"/jobs/{job_id}/results")
356-
349+
357350
# Assert response status code and content
358351
assert response.status_code == expected_status
359352
assert response.json() == expected_response

0 commit comments

Comments
 (0)