Skip to content

Commit 476eee5

Browse files
author
Alex Grosu
committed
Set back the starlette changes, going to bring them from the develop branch
1 parent a3f8215 commit 476eee5

File tree

8 files changed

+43
-43
lines changed

8 files changed

+43
-43
lines changed

services/cadip/rs_server_cadip/api/cadip_search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def process_session_search( # type: ignore # pylint: disable=too-many-arguments
561561
except ValueError as exception:
562562
logger.error(exception)
563563
raise HTTPException(
564-
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
564+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
565565
detail=str(exception),
566566
) from exception
567567
except Exception as exception: # pylint: disable=broad-exception-caught
@@ -611,7 +611,7 @@ def process_files_search( # pylint: disable=too-many-locals
611611
queryables["SessionId"] = split_multiple_values(session_id)
612612

613613
if limit < 1: # type: ignore
614-
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail="Pagination cannot be less 0")
614+
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="Pagination cannot be less 0")
615615
# Init dataretriever / get products / return
616616
try:
617617
products = cadip_retriever.init_cadip_provider(station).search(

services/cadip/rs_server_cadip/cadip_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ def cadip_map_mission(platform: str, constellation: str) -> str | None:
198198
)
199199
if satellite and satellite not in satellites:
200200
raise HTTPException(
201-
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
201+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
202202
detail="Invalid combination of platform-constellation",
203203
)
204204
except (KeyError, IndexError, StopIteration) as exc:
205205
raise HTTPException(
206-
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
206+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
207207
detail="Cannot map platform/constellation",
208208
) from exc
209209
return satellite or satellites

services/catalog/tests/test_authentication_catalog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
HTTP_401_UNAUTHORIZED,
4343
HTTP_403_FORBIDDEN,
4444
HTTP_404_NOT_FOUND,
45-
HTTP_422_UNPROCESSABLE_CONTENT,
45+
HTTP_422_UNPROCESSABLE_ENTITY,
4646
HTTP_500_INTERNAL_SERVER_ERROR,
4747
)
4848

@@ -1572,7 +1572,7 @@ async def test_error_when_not_authenticated(mocker, client, httpx_mock: HTTPXMoc
15721572
assert response.status_code not in (
15731573
HTTP_401_UNAUTHORIZED,
15741574
HTTP_403_FORBIDDEN,
1575-
HTTP_422_UNPROCESSABLE_CONTENT, # with 422, the authentication is not called and not tested
1575+
HTTP_422_UNPROCESSABLE_ENTITY, # with 422, the authentication is not called and not tested
15761576
)
15771577

15781578
# With a wrong apikey, we should have a 403 error

services/common/rs_server_common/stac_api_common.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def format_dict(field: dict):
393393
raise ValueError
394394
except ValueError as exc:
395395
raise log_http_exception(
396-
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
396+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
397397
detail=f"Invalid page value: {page!r}",
398398
) from exc
399399

@@ -406,7 +406,7 @@ def format_dict(field: dict):
406406
raise ValueError
407407
except ValueError as exc:
408408
raise log_http_exception(
409-
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
409+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
410410
detail=f"Invalid limit value: {limit!r}",
411411
) from exc
412412

@@ -421,7 +421,7 @@ def format_dict(field: dict):
421421
elif isinstance(sortby_param, list):
422422
if len(sortby_param) > 1:
423423
raise log_http_exception(
424-
status.HTTP_422_UNPROCESSABLE_CONTENT,
424+
status.HTTP_422_UNPROCESSABLE_ENTITY,
425425
f"Only one 'sortby' search parameter is allowed: {sortby_param!r}",
426426
)
427427
if sortby_param:
@@ -440,7 +440,7 @@ def format_dict(field: dict):
440440
stac_params["published"] = datetime
441441
except HTTPException as exception:
442442
raise log_http_exception(
443-
status.HTTP_422_UNPROCESSABLE_CONTENT,
443+
status.HTTP_422_UNPROCESSABLE_ENTITY,
444444
f"Invalid datetime interval: {datetime!r}. "
445445
"Expected format is either: 'YYYY-MM-DDThh:mm:ssZ', 'YYYY-MM-DDThh:mm:ssZ/YYYY-MM-DDThh:mm:ssZ', "
446446
"'YYYY-MM-DDThh:mm:ssZ/..' or '../YYYY-MM-DDThh:mm:ssZ'",
@@ -457,7 +457,7 @@ def read_property(prop: str, value: Any):
457457
nonlocal stac_params # noqa: F824
458458
if prop not in allowed_properties:
459459
raise log_http_exception(
460-
status.HTTP_422_UNPROCESSABLE_CONTENT,
460+
status.HTTP_422_UNPROCESSABLE_ENTITY,
461461
f"Invalid query or CQL property: {prop!r}, " f"allowed properties are: {allowed_properties}",
462462
)
463463
if isinstance(value, dict):
@@ -488,7 +488,7 @@ def read_cql(filt: dict):
488488
if op and op.lower() == "intersects":
489489
if len(args) != 2:
490490
raise log_http_exception(
491-
status.HTTP_422_UNPROCESSABLE_CONTENT,
491+
status.HTTP_422_UNPROCESSABLE_ENTITY,
492492
f"Invalid intersects: {format_dict(filt)}",
493493
)
494494
geom = args[1]
@@ -504,7 +504,7 @@ def read_cql(filt: dict):
504504
if op == "=":
505505
if (len(args) != 2) or not (prop := args[0].get("property")):
506506
raise log_http_exception(
507-
status.HTTP_422_UNPROCESSABLE_CONTENT,
507+
status.HTTP_422_UNPROCESSABLE_ENTITY,
508508
f"Invalid CQL2 filter: {format_dict(filt)}",
509509
)
510510
value = args[1]
@@ -521,7 +521,7 @@ def read_cql(filt: dict):
521521
# Else we are reading several properties
522522
if op != "and":
523523
raise log_http_exception(
524-
status.HTTP_422_UNPROCESSABLE_CONTENT,
524+
status.HTTP_422_UNPROCESSABLE_ENTITY,
525525
f"Invalid CQL2 filter, only '=', 'and' and temporal operators are allowed, got '{op}': {format_dict(filt)}", # noqa: E501 # pylint: disable=line-too-long
526526
)
527527
for sub_filter in args:
@@ -544,7 +544,7 @@ def read_query(query_arg: str | None):
544544
# Extract prop and check if it's in the queryables.
545545
if (prop := kv[0].strip()) not in allowed_properties:
546546
raise log_http_exception(
547-
status.HTTP_422_UNPROCESSABLE_CONTENT,
547+
status.HTTP_422_UNPROCESSABLE_ENTITY,
548548
f"Invalid query filter property: {prop!r}, allowed properties are: {allowed_properties}",
549549
)
550550
value = str(kv[1]).strip("'\"")
@@ -561,7 +561,7 @@ def read_query(query_arg: str | None):
561561
logger.debug(f"Temporal operator detected: {op} -> {stac_params[op]}")
562562
else:
563563
raise log_http_exception(
564-
status.HTTP_422_UNPROCESSABLE_CONTENT,
564+
status.HTTP_422_UNPROCESSABLE_ENTITY,
565565
"Invalid query filter, only '=' and temporal operators are allowed, got: " + query_arg,
566566
)
567567

@@ -572,7 +572,7 @@ def read_query(query_arg: str | None):
572572
for prop, operator in query.items():
573573
if (len(operator) != 1) or not (value := operator.get("eq")):
574574
raise log_http_exception(
575-
status.HTTP_422_UNPROCESSABLE_CONTENT,
575+
status.HTTP_422_UNPROCESSABLE_ENTITY,
576576
f"Invalid query: {{{prop!r}: {format_dict(operator)}}}"
577577
", only {'<property>': {'eq': <value>}} is allowed",
578578
)
@@ -599,7 +599,7 @@ def read_query(query_arg: str | None):
599599
# If search parameters remain, they are not implemented
600600
if params:
601601
raise log_http_exception(
602-
status.HTTP_422_UNPROCESSABLE_CONTENT,
602+
status.HTTP_422_UNPROCESSABLE_ENTITY,
603603
f"Unimplemented search parameters: {format_dict(params)}",
604604
)
605605

@@ -1056,7 +1056,7 @@ def create_collection(collection: dict) -> stac_pydantic.Collection:
10561056
except ValidationError as exc:
10571057
raise log_http_exception(
10581058
detail=f"Unable to create stac_pydantic.Collection, {repr(exc.errors())}",
1059-
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
1059+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
10601060
) from exc
10611061

10621062

@@ -1073,13 +1073,13 @@ def wrapping_logic(*_args, **_kwargs):
10731073
except KeyError as exc:
10741074
logger.error(f"KeyError caught in {func.__name__}")
10751075
raise log_http_exception(
1076-
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
1076+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
10771077
detail=f"Cannot create STAC Collection -> Missing {exc}",
10781078
) from exc
10791079
except ValidationError as exc:
10801080
logger.error(f"ValidationError caught in {func.__name__}")
10811081
raise log_http_exception(
1082-
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
1082+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
10831083
detail=f"Parameters validation error: {exc}",
10841084
) from exc
10851085

@@ -1149,7 +1149,7 @@ def filter_allowed_collections(all_collections: list[dict], role: ServiceRole |
11491149

11501150
# If a collection is incomplete in the configuration file, log the error and proceed
11511151
except HTTPException as exception:
1152-
if exception.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT:
1152+
if exception.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY:
11531153
logger.error(exception)
11541154
else:
11551155
raise
@@ -1251,7 +1251,7 @@ def get_sort_key(item):
12511251
sorted_items = sorted(item_collection.features, key=get_sort_key, reverse=direction == "-")
12521252
except AttributeError as e:
12531253
raise log_http_exception(
1254-
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
1254+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
12551255
detail=f"Invalid attribute '{attribute}' for sorting: {str(e)},",
12561256
) from e
12571257
return ItemCollection(features=sorted_items, type=item_collection.type)
@@ -1271,7 +1271,7 @@ def check_input_type(field_info, key, input_value):
12711271

12721272
if not type_mapping.get(expected_type)(input_value): # type: ignore
12731273
raise log_http_exception(
1274-
status.HTTP_422_UNPROCESSABLE_CONTENT,
1274+
status.HTTP_422_UNPROCESSABLE_ENTITY,
12751275
"Invalid CQL2 filter value",
12761276
)
12771277

services/common/rs_server_common/utils/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def validate_inputs_format(
117117
fixed_date = date_time
118118
except ValueError as exc:
119119
logger.error("Missing start or stop in endpoint call!")
120-
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail="Missing start/stop") from exc
120+
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="Missing start/stop") from exc
121121

122122
def is_valid_date(date: str) -> bool:
123123
"""Check if the string can be converted to a valid datetime."""
@@ -184,7 +184,7 @@ def map_auxip_prip_mission(platform: str, constellation: str) -> tuple[str | Non
184184
if platform_short_name and platform_short_name != constellation:
185185
# Inconsistent combination of platform / constellation case
186186
raise HTTPException(
187-
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
187+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
188188
detail="Invalid combination of platform-constellation",
189189
)
190190
if any(
@@ -197,7 +197,7 @@ def map_auxip_prip_mission(platform: str, constellation: str) -> tuple[str | Non
197197
raise KeyError
198198
except (KeyError, IndexError, StopIteration) as exc:
199199
raise HTTPException(
200-
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
200+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
201201
detail="Cannot map platform/constellation",
202202
) from exc
203203
return platform_short_name, platform_serial_identifier

services/staging/tests/test_authentication_staging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from starlette.status import (
2929
HTTP_401_UNAUTHORIZED,
3030
HTTP_403_FORBIDDEN,
31-
HTTP_422_UNPROCESSABLE_CONTENT,
31+
HTTP_422_UNPROCESSABLE_ENTITY,
3232
)
3333

3434
from .resources.sample_data import sample_process_metadata_model
@@ -93,7 +93,7 @@ async def test_error_when_not_authenticated( # pylint: disable=too-many-locals
9393
assert response.status_code not in (
9494
HTTP_401_UNAUTHORIZED,
9595
HTTP_403_FORBIDDEN,
96-
HTTP_422_UNPROCESSABLE_CONTENT, # with 422, the authentication is not called and not tested
96+
HTTP_422_UNPROCESSABLE_ENTITY, # with 422, the authentication is not called and not tested
9797
)
9898
# With a wrong apikey, we should have a 403 error
9999
if test_apikey:

services/staging/tests/test_staging_endpoints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
HTTP_200_OK,
3131
HTTP_201_CREATED,
3232
HTTP_404_NOT_FOUND,
33-
HTTP_422_UNPROCESSABLE_CONTENT,
33+
HTTP_422_UNPROCESSABLE_ENTITY,
3434
HTTP_500_INTERNAL_SERVER_ERROR,
3535
)
3636

@@ -547,7 +547,7 @@ async def test_execute_staging(
547547
resource_name = "staging"
548548
# ----- Test case where we have a staging body uncompliant with ogc
549549
response = staging_client.post(f"/processes/{resource_name}/execution", json=wrong_staging_body)
550-
assert response.status_code == HTTP_422_UNPROCESSABLE_CONTENT
550+
assert response.status_code == HTTP_422_UNPROCESSABLE_ENTITY
551551

552552
mock_db_table = mocker.MagicMock()
553553
mocker.patch(

tests/test_search_endpoint.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class TestOperatorDefinedCollections:
4747
@pytest.mark.parametrize(
4848
"endpoint, code",
4949
[
50-
("/cadip/collections/cadip_session_incomplete/items", status.HTTP_422_UNPROCESSABLE_CONTENT),
50+
("/cadip/collections/cadip_session_incomplete/items", status.HTTP_422_UNPROCESSABLE_ENTITY),
5151
("/cadip/collections/cadip_session_incomplete_no_stop/items", status.HTTP_400_BAD_REQUEST),
5252
("/cadip/collections/cadip_session_incomplete_no_start/items", status.HTTP_400_BAD_REQUEST),
5353
("/auxip/collections/adgs_invalid_no_start/items", status.HTTP_400_BAD_REQUEST),
@@ -346,7 +346,7 @@ def test_cadip_validation_errors(self, client, mocker, endpoint):
346346
"rs_server_cadip.api.cadip_search.process_session_search",
347347
side_effect=ValidationError.from_exception_data("Invalid data", line_errors=[]),
348348
)
349-
assert client.get(endpoint).status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
349+
assert client.get(endpoint).status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
350350

351351
@pytest.mark.unit
352352
@pytest.mark.parametrize(
@@ -363,7 +363,7 @@ def test_adgs_validation_errors(self, client, mocker, endpoint):
363363
"rs_server_adgs.api.adgs_search.process_product_search",
364364
side_effect=ValidationError.from_exception_data("Invalid data", line_errors=[]),
365365
)
366-
assert client.get(endpoint).status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
366+
assert client.get(endpoint).status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
367367

368368
@pytest.mark.unit
369369
@pytest.mark.parametrize(
@@ -380,7 +380,7 @@ def test_prip_validation_errors(self, client, mocker, endpoint):
380380
"rs_server_prip.api.prip_search.process_product_search",
381381
side_effect=ValidationError.from_exception_data("Invalid data", line_errors=[]),
382382
)
383-
assert client.get(endpoint).status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
383+
assert client.get(endpoint).status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
384384

385385
@pytest.mark.unit
386386
def test_adgs_search_error(self, client, mocker):
@@ -442,7 +442,7 @@ class TestErrorWhileBuildUpCollection:
442442
def test_cadip_collection_creation_failure(self, client, mocker, endpoint):
443443
"""Test used to generate a KeyError while Collection is created, should return HTTP 422."""
444444
mocker.patch("rs_server_cadip.api.cadip_search.process_session_search", side_effect=KeyError)
445-
assert client.get(endpoint).status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
445+
assert client.get(endpoint).status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
446446

447447
@pytest.mark.unit
448448
@pytest.mark.parametrize(
@@ -453,7 +453,7 @@ def test_cadip_collection_creation_failure(self, client, mocker, endpoint):
453453
def test_adgs_collection_creation_failure(self, client, mocker, endpoint):
454454
"""Test used to generate a KeyError while Collection is created, should return HTTP 422."""
455455
mocker.patch("rs_server_adgs.api.adgs_search.process_product_search", side_effect=KeyError)
456-
assert client.get(endpoint).status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
456+
assert client.get(endpoint).status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
457457

458458
@pytest.mark.unit
459459
@pytest.mark.parametrize(
@@ -466,7 +466,7 @@ def test_adgs_collection_creation_failure(self, client, mocker, endpoint):
466466
def test_prip_collection_creation_failure(self, client, mocker, endpoint):
467467
"""Test used to generate a KeyError while Collection is created, should return HTTP 422."""
468468
mocker.patch("rs_server_prip.api.prip_search.process_product_search", side_effect=KeyError)
469-
assert client.get(endpoint).status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
469+
assert client.get(endpoint).status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
470470

471471

472472
class TestFeatureOdataStacMapping:
@@ -859,7 +859,7 @@ def test_prip_feature_collection_mapping(
859859
ROUTER_PREFIX_CADIP,
860860
"/cadip/collections/cadip_session_by_satellite/items?filter=cadip:retransfer=should_be_bool",
861861
"no_odata",
862-
status.HTTP_422_UNPROCESSABLE_CONTENT,
862+
status.HTTP_422_UNPROCESSABLE_ENTITY,
863863
),
864864
(
865865
ROUTER_PREFIX_CADIP,
@@ -873,7 +873,7 @@ def test_prip_feature_collection_mapping(
873873
ROUTER_PREFIX_CADIP,
874874
"/cadip/collections/cadip_session_by_satellite/items?filter=invalid='x'",
875875
"No odata for this",
876-
status.HTTP_422_UNPROCESSABLE_CONTENT,
876+
status.HTTP_422_UNPROCESSABLE_ENTITY,
877877
),
878878
(
879879
ROUTER_PREFIX_AUXIP,
@@ -915,13 +915,13 @@ def test_prip_feature_collection_mapping(
915915
ROUTER_PREFIX_AUXIP,
916916
"/auxip/collections/adgs_by_platform/items?filter=invalid='x'",
917917
"No odata",
918-
status.HTTP_422_UNPROCESSABLE_CONTENT,
918+
status.HTTP_422_UNPROCESSABLE_ENTITY,
919919
),
920920
(
921921
ROUTER_PREFIX_AUXIP,
922922
"/auxip/collections/adgs_by_platform/items?filter=published=invalid_date_format2020",
923923
"No odata",
924-
status.HTTP_422_UNPROCESSABLE_CONTENT,
924+
status.HTTP_422_UNPROCESSABLE_ENTITY,
925925
),
926926
],
927927
indirect=["fastapi_app"],
@@ -1167,7 +1167,7 @@ def test_bigger_limit_than_allowed(self, client, endpoint, odata):
11671167
def test_invalid_page_values(self, client, endpoint):
11681168
"""Test endpoint call with invalid pages (str, negative, 0)"""
11691169
response = client.get(endpoint)
1170-
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
1170+
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
11711171
assert "Invalid page value" in response.json()["description"]
11721172

11731173
@pytest.mark.unit

0 commit comments

Comments
 (0)