Skip to content

Commit fc5e2c9

Browse files
committed
feat: replace check_status_code parameter by expected_status_codes.
1 parent a5d0024 commit fc5e2c9

File tree

5 files changed

+34
-30
lines changed

5 files changed

+34
-30
lines changed

doc/changelog.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
Changelog
22
=========
33

4+
[0.2.0] - Unreleased
5+
---------------------
6+
7+
Added
8+
^^^^^
9+
- Replace :code:`check_status_code` parameter by :code:`expected_status_codes`.
10+
411
[0.1.11] - 2024-08-31
512
---------------------
613

714
Fixed
8-
^^^^^^^
15+
^^^^^
916
- Support for content-types with charset information. #18 #19
1017

1118
[0.1.10] - 2024-08-18

doc/tutorial.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ To achieve this, all the methods provide the following parameters, all are :data
6868
- :code:`check_response_payload`:
6969
If :data:`True` a :class:`~pydantic.ValidationError` will be raised if the server response does not respect the SCIM standard.
7070
If :data:`False` the server response is returned as-is.
71-
- :code:`check_status_code`: Whether to validate that the response status code is valid.
72-
If :data:`True` and an unexpected status code is returned, a :class:`~scim2_client.errors.UnexpectedStatusCode` exception is raised.
71+
- :code:`expected_status_codes`: The list of expected status codes in the response.
72+
If :data:`None` any status code is accepted.
73+
If an unexpected status code is returned, a :class:`~scim2_client.errors.UnexpectedStatusCode` exception is raised.
7374
- :code:`raise_scim_errors`: If :data:`True` and the server returned an :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject` exception will be raised.
7475
If :data:`False` the error object is returned.
7576

scim2_client/client.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def create(
240240
resource: Union[AnyResource, Dict],
241241
check_request_payload: bool = True,
242242
check_response_payload: bool = True,
243-
check_status_code: bool = True,
243+
expected_status_codes: Optional[List[int]] = CREATION_RESPONSE_STATUS_CODES,
244244
raise_scim_errors: bool = False,
245245
**kwargs,
246246
) -> Union[AnyResource, Error, Dict]:
@@ -253,7 +253,8 @@ def create(
253253
:code:`resource` is expected to be a dict that will be passed as-is in the request.
254254
:param check_response_payload: Whether to validate that the response payload is valid.
255255
If set, the raw payload will be returned.
256-
:param check_status_code: Whether to validate that the response status code is valid.
256+
:param expected_status_codes: The list of expected status codes form the response.
257+
If :data:`None` any status code is accepted.
257258
:param raise_scim_errors: If :data:`True` and the server returned an
258259
:class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
259260
exception will be raised. If :data:`False` the error object is returned.
@@ -318,9 +319,7 @@ def create(
318319

319320
return self.check_response(
320321
response=response,
321-
expected_status_codes=(
322-
self.CREATION_RESPONSE_STATUS_CODES if check_status_code else None
323-
),
322+
expected_status_codes=expected_status_codes,
324323
expected_types=([resource.__class__] if check_request_payload else None),
325324
check_response_payload=check_response_payload,
326325
raise_scim_errors=raise_scim_errors,
@@ -334,7 +333,7 @@ def query(
334333
search_request: Optional[Union[SearchRequest, Dict]] = None,
335334
check_request_payload: bool = True,
336335
check_response_payload: bool = True,
337-
check_status_code: bool = True,
336+
expected_status_codes: Optional[List[int]] = QUERY_RESPONSE_STATUS_CODES,
338337
raise_scim_errors: bool = False,
339338
**kwargs,
340339
) -> Union[AnyResource, ListResponse[AnyResource], Error, Dict]:
@@ -351,7 +350,8 @@ def query(
351350
:code:`search_request` is expected to be a dict that will be passed as-is in the request.
352351
:param check_response_payload: Whether to validate that the response payload is valid.
353352
If set, the raw payload will be returned.
354-
:param check_status_code: Whether to validate that the response status code is valid.
353+
:param expected_status_codes: The list of expected status codes form the response.
354+
If :data:`None` any status code is accepted.
355355
:param raise_scim_errors: If :data:`True` and the server returned an
356356
:class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
357357
exception will be raised. If :data:`False` the error object is returned.
@@ -447,9 +447,7 @@ def query(
447447

448448
return self.check_response(
449449
response=response,
450-
expected_status_codes=(
451-
self.QUERY_RESPONSE_STATUS_CODES if check_status_code else None
452-
),
450+
expected_status_codes=expected_status_codes,
453451
expected_types=expected_types,
454452
check_response_payload=check_response_payload,
455453
raise_scim_errors=raise_scim_errors,
@@ -461,7 +459,7 @@ def search(
461459
search_request: Optional[SearchRequest] = None,
462460
check_request_payload: bool = True,
463461
check_response_payload: bool = True,
464-
check_status_code: bool = True,
462+
expected_status_codes: Optional[List[int]] = SEARCH_RESPONSE_STATUS_CODES,
465463
raise_scim_errors: bool = False,
466464
**kwargs,
467465
) -> Union[AnyResource, ListResponse[AnyResource], Error, Dict]:
@@ -475,7 +473,8 @@ def search(
475473
:code:`search_request` is expected to be a dict that will be passed as-is in the request.
476474
:param check_response_payload: Whether to validate that the response payload is valid.
477475
If set, the raw payload will be returned.
478-
:param check_status_code: Whether to validate that the response status code is valid.
476+
:param expected_status_codes: The list of expected status codes form the response.
477+
If :data:`None` any status code is accepted.
479478
:param raise_scim_errors: If :data:`True` and the server returned an
480479
:class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
481480
exception will be raised. If :data:`False` the error object is returned.
@@ -528,9 +527,7 @@ def search(
528527

529528
return self.check_response(
530529
response=response,
531-
expected_status_codes=(
532-
self.SEARCH_RESPONSE_STATUS_CODES if check_status_code else None
533-
),
530+
expected_status_codes=expected_status_codes,
534531
expected_types=[ListResponse[Union[self.resource_types]]],
535532
check_response_payload=check_response_payload,
536533
raise_scim_errors=raise_scim_errors,
@@ -542,7 +539,7 @@ def delete(
542539
resource_type: Type,
543540
id: str,
544541
check_response_payload: bool = True,
545-
check_status_code: bool = True,
542+
expected_status_codes: Optional[List[int]] = DELETION_RESPONSE_STATUS_CODES,
546543
raise_scim_errors: bool = False,
547544
**kwargs,
548545
) -> Optional[Union[Error, Dict]]:
@@ -553,7 +550,8 @@ def delete(
553550
:param id: The type id the resource to delete.
554551
:param check_response_payload: Whether to validate that the response payload is valid.
555552
If set, the raw payload will be returned.
556-
:param check_status_code: Whether to validate that the response status code is valid.
553+
:param expected_status_codes: The list of expected status codes form the response.
554+
If :data:`None` any status code is accepted.
557555
:param raise_scim_errors: If :data:`True` and the server returned an
558556
:class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
559557
exception will be raised. If :data:`False` the error object is returned.
@@ -588,9 +586,7 @@ def delete(
588586

589587
return self.check_response(
590588
response=response,
591-
expected_status_codes=(
592-
self.DELETION_RESPONSE_STATUS_CODES if check_status_code else None
593-
),
589+
expected_status_codes=expected_status_codes,
594590
check_response_payload=check_response_payload,
595591
raise_scim_errors=raise_scim_errors,
596592
)
@@ -600,7 +596,7 @@ def replace(
600596
resource: Union[AnyResource, Dict],
601597
check_request_payload: bool = True,
602598
check_response_payload: bool = True,
603-
check_status_code: bool = True,
599+
expected_status_codes: Optional[List[int]] = REPLACEMENT_RESPONSE_STATUS_CODES,
604600
raise_scim_errors: bool = False,
605601
**kwargs,
606602
) -> Union[AnyResource, Error, Dict]:
@@ -613,7 +609,8 @@ def replace(
613609
:code:`resource` is expected to be a dict that will be passed as-is in the request.
614610
:param check_response_payload: Whether to validate that the response payload is valid.
615611
If set, the raw payload will be returned.
616-
:param check_status_code: Whether to validate that the response status code is valid.
612+
:param expected_status_codes: The list of expected status codes form the response.
613+
If :data:`None` any status code is accepted.
617614
:param raise_scim_errors: If :data:`True` and the server returned an
618615
:class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
619616
exception will be raised. If :data:`False` the error object is returned.
@@ -687,9 +684,7 @@ def replace(
687684

688685
return self.check_response(
689686
response=response,
690-
expected_status_codes=(
691-
self.REPLACEMENT_RESPONSE_STATUS_CODES if check_status_code else None
692-
),
687+
expected_status_codes=expected_status_codes,
693688
expected_types=([resource.__class__] if check_request_payload else None),
694689
check_response_payload=check_response_payload,
695690
raise_scim_errors=raise_scim_errors,

tests/test_create.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ def test_no_200(httpserver):
244244
scim_client = SCIMClient(client, resource_types=(User,))
245245
with pytest.raises(UnexpectedStatusCode):
246246
scim_client.create(user_request)
247-
scim_client.create(user_request, check_status_code=False)
247+
scim_client.create(user_request, expected_status_codes=None)
248+
scim_client.create(user_request, expected_status_codes=[200, 201])
248249

249250

250251
@pytest.mark.parametrize("code", [400, 401, 403, 404, 500])

tests/test_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def test_response_bad_status_code(client):
532532
)
533533
with pytest.raises(UnexpectedStatusCode):
534534
scim_client.query(User, "status-201")
535-
scim_client.query(User, "status-201", check_status_code=False)
535+
scim_client.query(User, "status-201", expected_status_codes=None)
536536

537537

538538
def test_response_content_type_with_charset(client):

0 commit comments

Comments
 (0)