scim2-client 0.3.0__py3-none-any.whl → 0.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
scim2_client/client.py CHANGED
@@ -48,6 +48,14 @@ class BaseSCIMClient:
48
48
 
49
49
  :param resource_models: A tuple of :class:`~scim2_models.Resource` types expected to be handled by the SCIM client.
50
50
  If a request payload describe a resource that is not in this list, an exception will be raised.
51
+ :param check_request_payload: If :data:`False`,
52
+ :code:`resource` is expected to be a dict that will be passed as-is in the request.
53
+ This value can be overwritten in methods.
54
+ :param check_response_payload: Whether to validate that the response payloads are valid.
55
+ If set, the raw payload will be returned. This value can be overwritten in methods.
56
+ :param raise_scim_errors: If :data:`True` and the server returned an
57
+ :class:`~scim2_models.Error` object during a request, a :class:`~scim2_client.SCIMResponseErrorObject`
58
+ exception will be raised. If :data:`False` the error object is returned. This value can be overwritten in methods.
51
59
 
52
60
  .. note::
53
61
 
@@ -134,10 +142,19 @@ class BaseSCIMClient:
134
142
  :rfc:`RFC7644 §3.12 <7644#section-3.12>`.
135
143
  """
136
144
 
137
- def __init__(self, resource_models: Optional[tuple[type[Resource]]] = None):
145
+ def __init__(
146
+ self,
147
+ resource_models: Optional[tuple[type[Resource]]] = None,
148
+ check_request_payload: bool = True,
149
+ check_response_payload: bool = True,
150
+ raise_scim_errors: bool = True,
151
+ ):
138
152
  self.resource_models = tuple(
139
153
  set(resource_models or []) | {ResourceType, Schema, ServiceProviderConfig}
140
154
  )
155
+ self.check_request_payload = True
156
+ self.check_response_payload = True
157
+ self.raise_scim_errors = True
141
158
 
142
159
  def check_resource_model(
143
160
  self, resource_model: type[Resource], payload=None
@@ -169,12 +186,15 @@ class BaseSCIMClient:
169
186
  headers: dict,
170
187
  expected_status_codes: Optional[list[int]] = None,
171
188
  expected_types: Optional[list[type[Resource]]] = None,
172
- check_response_payload: bool = True,
173
- raise_scim_errors: bool = True,
189
+ check_response_payload: Optional[bool] = None,
190
+ raise_scim_errors: Optional[bool] = None,
174
191
  scim_ctx: Optional[Context] = None,
175
192
  ) -> Union[Error, None, dict, type[Resource]]:
193
+ if raise_scim_errors is None:
194
+ raise_scim_errors = self.raise_scim_errors
195
+
176
196
  if expected_status_codes and status_code not in expected_status_codes:
177
- raise UnexpectedStatusCode()
197
+ raise UnexpectedStatusCode(status_code)
178
198
 
179
199
  # Interoperability considerations: The "application/scim+json" media
180
200
  # type is intended to identify JSON structure data that conforms to
@@ -198,6 +218,9 @@ class BaseSCIMClient:
198
218
  else:
199
219
  response_payload = payload
200
220
 
221
+ if check_response_payload is None:
222
+ check_response_payload = self.check_response_payload
223
+
201
224
  if not check_response_payload:
202
225
  return response_payload
203
226
 
@@ -207,7 +230,7 @@ class BaseSCIMClient:
207
230
  ):
208
231
  error = Error.model_validate(response_payload)
209
232
  if raise_scim_errors:
210
- raise SCIMResponseErrorObject(source=error)
233
+ raise SCIMResponseErrorObject(obj=error.detail, source=error)
211
234
  return error
212
235
 
213
236
  if not expected_types:
@@ -240,15 +263,17 @@ class BaseSCIMClient:
240
263
  def prepare_create_request(
241
264
  self,
242
265
  resource: Union[AnyResource, dict],
243
- check_request_payload: bool = True,
266
+ check_request_payload: Optional[bool] = None,
244
267
  expected_status_codes: Optional[list[int]] = None,
245
- raise_scim_errors: bool = True,
268
+ raise_scim_errors: Optional[bool] = None,
246
269
  **kwargs,
247
270
  ) -> RequestPayload:
248
271
  req = RequestPayload(
249
272
  expected_status_codes=expected_status_codes,
250
273
  request_kwargs=kwargs,
251
274
  )
275
+ if check_request_payload is None:
276
+ check_request_payload = self.check_request_payload
252
277
 
253
278
  if not check_request_payload:
254
279
  req.payload = resource
@@ -289,9 +314,9 @@ class BaseSCIMClient:
289
314
  resource_model: Optional[type[Resource]] = None,
290
315
  id: Optional[str] = None,
291
316
  search_request: Optional[Union[SearchRequest, dict]] = None,
292
- check_request_payload: bool = True,
317
+ check_request_payload: Optional[bool] = None,
293
318
  expected_status_codes: Optional[list[int]] = None,
294
- raise_scim_errors: bool = True,
319
+ raise_scim_errors: Optional[bool] = None,
295
320
  **kwargs,
296
321
  ) -> RequestPayload:
297
322
  req = RequestPayload(
@@ -299,6 +324,9 @@ class BaseSCIMClient:
299
324
  request_kwargs=kwargs,
300
325
  )
301
326
 
327
+ if check_request_payload is None:
328
+ check_request_payload = self.check_request_payload
329
+
302
330
  if resource_model and check_request_payload:
303
331
  self.check_resource_model(resource_model)
304
332
 
@@ -341,9 +369,9 @@ class BaseSCIMClient:
341
369
  def prepare_search_request(
342
370
  self,
343
371
  search_request: Optional[SearchRequest] = None,
344
- check_request_payload: bool = True,
372
+ check_request_payload: Optional[bool] = None,
345
373
  expected_status_codes: Optional[list[int]] = None,
346
- raise_scim_errors: bool = True,
374
+ raise_scim_errors: Optional[bool] = None,
347
375
  **kwargs,
348
376
  ) -> RequestPayload:
349
377
  req = RequestPayload(
@@ -351,6 +379,9 @@ class BaseSCIMClient:
351
379
  request_kwargs=kwargs,
352
380
  )
353
381
 
382
+ if check_request_payload is None:
383
+ check_request_payload = self.check_request_payload
384
+
354
385
  if not check_request_payload:
355
386
  req.payload = search_request
356
387
 
@@ -372,7 +403,7 @@ class BaseSCIMClient:
372
403
  resource_model: type,
373
404
  id: str,
374
405
  expected_status_codes: Optional[list[int]] = None,
375
- raise_scim_errors: bool = True,
406
+ raise_scim_errors: Optional[bool] = None,
376
407
  **kwargs,
377
408
  ) -> RequestPayload:
378
409
  req = RequestPayload(
@@ -388,9 +419,9 @@ class BaseSCIMClient:
388
419
  def prepare_replace_request(
389
420
  self,
390
421
  resource: Union[AnyResource, dict],
391
- check_request_payload: bool = True,
422
+ check_request_payload: Optional[bool] = None,
392
423
  expected_status_codes: Optional[list[int]] = None,
393
- raise_scim_errors: bool = True,
424
+ raise_scim_errors: Optional[bool] = None,
394
425
  **kwargs,
395
426
  ) -> RequestPayload:
396
427
  req = RequestPayload(
@@ -398,6 +429,9 @@ class BaseSCIMClient:
398
429
  request_kwargs=kwargs,
399
430
  )
400
431
 
432
+ if check_request_payload is None:
433
+ check_request_payload = self.check_request_payload
434
+
401
435
  if not check_request_payload:
402
436
  req.payload = resource
403
437
  req.url = kwargs.pop("url", None)
@@ -449,27 +483,23 @@ class BaseSyncSCIMClient(BaseSCIMClient):
449
483
  def create(
450
484
  self,
451
485
  resource: Union[AnyResource, dict],
452
- check_request_payload: bool = True,
453
- check_response_payload: bool = True,
486
+ check_request_payload: Optional[bool] = None,
487
+ check_response_payload: Optional[bool] = None,
454
488
  expected_status_codes: Optional[
455
489
  list[int]
456
490
  ] = BaseSCIMClient.CREATION_RESPONSE_STATUS_CODES,
457
- raise_scim_errors: bool = True,
491
+ raise_scim_errors: Optional[bool] = None,
458
492
  **kwargs,
459
493
  ) -> Union[AnyResource, Error, dict]:
460
494
  """Perform a POST request to create, as defined in :rfc:`RFC7644 §3.3 <7644#section-3.3>`.
461
495
 
462
496
  :param resource: The resource to create
463
497
  If is a :data:`dict`, the resource type will be guessed from the schema.
464
- :param check_request_payload: If :data:`False`,
465
- :code:`resource` is expected to be a dict that will be passed as-is in the request.
466
- :param check_response_payload: Whether to validate that the response payload is valid.
467
- If set, the raw payload will be returned.
498
+ :param check_request_payload: If set, overwrites :paramref:`BaseSCIMClient.check_request_payload`.
499
+ :param check_response_payload: If set, overwrites :paramref:`BaseSCIMClient.check_response_payload`.
468
500
  :param expected_status_codes: The list of expected status codes form the response.
469
501
  If :data:`None` any status code is accepted.
470
- :param raise_scim_errors: If :data:`True` and the server returned an
471
- :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
472
- exception will be raised. If :data:`False` the error object is returned.
502
+ :param raise_scim_errors: If set, overwrites :paramref:`BaseSCIMClient.raise_scim_errors`.
473
503
  :param kwargs: Additional parameters passed to the underlying HTTP request
474
504
  library.
475
505
 
@@ -501,12 +531,12 @@ class BaseSyncSCIMClient(BaseSCIMClient):
501
531
  resource_model: Optional[type[Resource]] = None,
502
532
  id: Optional[str] = None,
503
533
  search_request: Optional[Union[SearchRequest, dict]] = None,
504
- check_request_payload: bool = True,
505
- check_response_payload: bool = True,
534
+ check_request_payload: Optional[bool] = None,
535
+ check_response_payload: Optional[bool] = None,
506
536
  expected_status_codes: Optional[
507
537
  list[int]
508
538
  ] = BaseSCIMClient.QUERY_RESPONSE_STATUS_CODES,
509
- raise_scim_errors: bool = True,
539
+ raise_scim_errors: Optional[bool] = None,
510
540
  **kwargs,
511
541
  ) -> Union[AnyResource, ListResponse[AnyResource], Error, dict]:
512
542
  """Perform a GET request to read resources, as defined in :rfc:`RFC7644 §3.4.2 <7644#section-3.4.2>`.
@@ -517,15 +547,11 @@ class BaseSyncSCIMClient(BaseSCIMClient):
517
547
  :param resource_model: A :class:`~scim2_models.Resource` subtype or :data:`None`
518
548
  :param id: The SCIM id of an object to get, or :data:`None`
519
549
  :param search_request: An object detailing the search query parameters.
520
- :param check_request_payload: If :data:`False`,
521
- :code:`search_request` is expected to be a dict that will be passed as-is in the request.
522
- :param check_response_payload: Whether to validate that the response payload is valid.
523
- If set, the raw payload will be returned.
550
+ :param check_request_payload: If set, overwrites :paramref:`BaseSCIMClient.check_request_payload`.
551
+ :param check_response_payload: If set, overwrites :paramref:`BaseSCIMClient.check_response_payload`.
524
552
  :param expected_status_codes: The list of expected status codes form the response.
525
553
  If :data:`None` any status code is accepted.
526
- :param raise_scim_errors: If :data:`True` and the server returned an
527
- :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
528
- exception will be raised. If :data:`False` the error object is returned.
554
+ :param raise_scim_errors: If set, overwrites :paramref:`BaseSCIMClient.raise_scim_errors`.
529
555
  :param kwargs: Additional parameters passed to the underlying HTTP request library.
530
556
 
531
557
  :return:
@@ -577,12 +603,12 @@ class BaseSyncSCIMClient(BaseSCIMClient):
577
603
  def search(
578
604
  self,
579
605
  search_request: Optional[SearchRequest] = None,
580
- check_request_payload: bool = True,
581
- check_response_payload: bool = True,
606
+ check_request_payload: Optional[bool] = None,
607
+ check_response_payload: Optional[bool] = None,
582
608
  expected_status_codes: Optional[
583
609
  list[int]
584
610
  ] = BaseSCIMClient.SEARCH_RESPONSE_STATUS_CODES,
585
- raise_scim_errors: bool = True,
611
+ raise_scim_errors: Optional[bool] = None,
586
612
  **kwargs,
587
613
  ) -> Union[AnyResource, ListResponse[AnyResource], Error, dict]:
588
614
  """Perform a POST search request to read all available resources, as defined in :rfc:`RFC7644 §3.4.3 <7644#section-3.4.3>`.
@@ -590,15 +616,11 @@ class BaseSyncSCIMClient(BaseSCIMClient):
590
616
  :param resource_models: Resource type or union of types expected
591
617
  to be read from the response.
592
618
  :param search_request: An object detailing the search query parameters.
593
- :param check_request_payload: If :data:`False`,
594
- :code:`search_request` is expected to be a dict that will be passed as-is in the request.
595
- :param check_response_payload: Whether to validate that the response payload is valid.
596
- If set, the raw payload will be returned.
619
+ :param check_request_payload: If set, overwrites :paramref:`BaseSCIMClient.check_request_payload`.
620
+ :param check_response_payload: If set, overwrites :paramref:`BaseSCIMClient.check_response_payload`.
597
621
  :param expected_status_codes: The list of expected status codes form the response.
598
622
  If :data:`None` any status code is accepted.
599
- :param raise_scim_errors: If :data:`True` and the server returned an
600
- :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
601
- exception will be raised. If :data:`False` the error object is returned.
623
+ :param raise_scim_errors: If set, overwrites :paramref:`BaseSCIMClient.raise_scim_errors`.
602
624
  :param kwargs: Additional parameters passed to the underlying
603
625
  HTTP request library.
604
626
 
@@ -630,24 +652,21 @@ class BaseSyncSCIMClient(BaseSCIMClient):
630
652
  self,
631
653
  resource_model: type,
632
654
  id: str,
633
- check_response_payload: bool = True,
655
+ check_response_payload: Optional[bool] = None,
634
656
  expected_status_codes: Optional[
635
657
  list[int]
636
658
  ] = BaseSCIMClient.DELETION_RESPONSE_STATUS_CODES,
637
- raise_scim_errors: bool = True,
659
+ raise_scim_errors: Optional[bool] = None,
638
660
  **kwargs,
639
661
  ) -> Optional[Union[Error, dict]]:
640
662
  """Perform a DELETE request to create, as defined in :rfc:`RFC7644 §3.6 <7644#section-3.6>`.
641
663
 
642
664
  :param resource_model: The type of the resource to delete.
643
665
  :param id: The type id the resource to delete.
644
- :param check_response_payload: Whether to validate that the response payload is valid.
645
- If set, the raw payload will be returned.
666
+ :param check_response_payload: If set, overwrites :paramref:`BaseSCIMClient.check_response_payload`.
646
667
  :param expected_status_codes: The list of expected status codes form the response.
647
668
  If :data:`None` any status code is accepted.
648
- :param raise_scim_errors: If :data:`True` and the server returned an
649
- :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
650
- exception will be raised. If :data:`False` the error object is returned.
669
+ :param raise_scim_errors: If set, overwrites :paramref:`BaseSCIMClient.raise_scim_errors`.
651
670
  :param kwargs: Additional parameters passed to the underlying
652
671
  HTTP request library.
653
672
 
@@ -670,27 +689,23 @@ class BaseSyncSCIMClient(BaseSCIMClient):
670
689
  def replace(
671
690
  self,
672
691
  resource: Union[AnyResource, dict],
673
- check_request_payload: bool = True,
674
- check_response_payload: bool = True,
692
+ check_request_payload: Optional[bool] = None,
693
+ check_response_payload: Optional[bool] = None,
675
694
  expected_status_codes: Optional[
676
695
  list[int]
677
696
  ] = BaseSCIMClient.REPLACEMENT_RESPONSE_STATUS_CODES,
678
- raise_scim_errors: bool = True,
697
+ raise_scim_errors: Optional[bool] = None,
679
698
  **kwargs,
680
699
  ) -> Union[AnyResource, Error, dict]:
681
700
  """Perform a PUT request to replace a resource, as defined in :rfc:`RFC7644 §3.5.1 <7644#section-3.5.1>`.
682
701
 
683
702
  :param resource: The new resource to replace.
684
703
  If is a :data:`dict`, the resource type will be guessed from the schema.
685
- :param check_request_payload: If :data:`False`,
686
- :code:`resource` is expected to be a dict that will be passed as-is in the request.
687
- :param check_response_payload: Whether to validate that the response payload is valid.
688
- If set, the raw payload will be returned.
704
+ :param check_request_payload: If set, overwrites :paramref:`BaseSCIMClient.check_request_payload`.
705
+ :param check_response_payload: If set, overwrites :paramref:`BaseSCIMClient.check_response_payload`.
689
706
  :param expected_status_codes: The list of expected status codes form the response.
690
707
  If :data:`None` any status code is accepted.
691
- :param raise_scim_errors: If :data:`True` and the server returned an
692
- :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
693
- exception will be raised. If :data:`False` the error object is returned.
708
+ :param raise_scim_errors: If set, overwrites :paramref:`BaseSCIMClient.raise_scim_errors`.
694
709
  :param kwargs: Additional parameters passed to the underlying
695
710
  HTTP request library.
696
711
 
@@ -725,27 +740,23 @@ class BaseAsyncSCIMClient(BaseSCIMClient):
725
740
  async def create(
726
741
  self,
727
742
  resource: Union[AnyResource, dict],
728
- check_request_payload: bool = True,
729
- check_response_payload: bool = True,
743
+ check_request_payload: Optional[bool] = None,
744
+ check_response_payload: Optional[bool] = None,
730
745
  expected_status_codes: Optional[
731
746
  list[int]
732
747
  ] = BaseSCIMClient.CREATION_RESPONSE_STATUS_CODES,
733
- raise_scim_errors: bool = True,
748
+ raise_scim_errors: Optional[bool] = None,
734
749
  **kwargs,
735
750
  ) -> Union[AnyResource, Error, dict]:
736
751
  """Perform a POST request to create, as defined in :rfc:`RFC7644 §3.3 <7644#section-3.3>`.
737
752
 
738
753
  :param resource: The resource to create
739
754
  If is a :data:`dict`, the resource type will be guessed from the schema.
740
- :param check_request_payload: If :data:`False`,
741
- :code:`resource` is expected to be a dict that will be passed as-is in the request.
742
- :param check_response_payload: Whether to validate that the response payload is valid.
743
- If set, the raw payload will be returned.
755
+ :param check_request_payload: If set, overwrites :paramref:`BaseSCIMClient.check_request_payload`.
756
+ :param check_response_payload: If set, overwrites :paramref:`BaseSCIMClient.check_response_payload`.
744
757
  :param expected_status_codes: The list of expected status codes form the response.
745
758
  If :data:`None` any status code is accepted.
746
- :param raise_scim_errors: If :data:`True` and the server returned an
747
- :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
748
- exception will be raised. If :data:`False` the error object is returned.
759
+ :param raise_scim_errors: If set, overwrites :paramref:`BaseSCIMClient.raise_scim_errors`.
749
760
  :param kwargs: Additional parameters passed to the underlying HTTP request
750
761
  library.
751
762
 
@@ -777,12 +788,12 @@ class BaseAsyncSCIMClient(BaseSCIMClient):
777
788
  resource_model: Optional[type[Resource]] = None,
778
789
  id: Optional[str] = None,
779
790
  search_request: Optional[Union[SearchRequest, dict]] = None,
780
- check_request_payload: bool = True,
781
- check_response_payload: bool = True,
791
+ check_request_payload: Optional[bool] = None,
792
+ check_response_payload: Optional[bool] = None,
782
793
  expected_status_codes: Optional[
783
794
  list[int]
784
795
  ] = BaseSCIMClient.QUERY_RESPONSE_STATUS_CODES,
785
- raise_scim_errors: bool = True,
796
+ raise_scim_errors: Optional[bool] = None,
786
797
  **kwargs,
787
798
  ) -> Union[AnyResource, ListResponse[AnyResource], Error, dict]:
788
799
  """Perform a GET request to read resources, as defined in :rfc:`RFC7644 §3.4.2 <7644#section-3.4.2>`.
@@ -793,15 +804,11 @@ class BaseAsyncSCIMClient(BaseSCIMClient):
793
804
  :param resource_model: A :class:`~scim2_models.Resource` subtype or :data:`None`
794
805
  :param id: The SCIM id of an object to get, or :data:`None`
795
806
  :param search_request: An object detailing the search query parameters.
796
- :param check_request_payload: If :data:`False`,
797
- :code:`search_request` is expected to be a dict that will be passed as-is in the request.
798
- :param check_response_payload: Whether to validate that the response payload is valid.
799
- If set, the raw payload will be returned.
807
+ :param check_request_payload: If set, overwrites :paramref:`BaseSCIMClient.check_request_payload`.
808
+ :param check_response_payload: If set, overwrites :paramref:`BaseSCIMClient.check_response_payload`.
800
809
  :param expected_status_codes: The list of expected status codes form the response.
801
810
  If :data:`None` any status code is accepted.
802
- :param raise_scim_errors: If :data:`True` and the server returned an
803
- :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
804
- exception will be raised. If :data:`False` the error object is returned.
811
+ :param raise_scim_errors: If set, overwrites :paramref:`BaseSCIMClient.raise_scim_errors`.
805
812
  :param kwargs: Additional parameters passed to the underlying HTTP request library.
806
813
 
807
814
  :return:
@@ -853,12 +860,12 @@ class BaseAsyncSCIMClient(BaseSCIMClient):
853
860
  async def search(
854
861
  self,
855
862
  search_request: Optional[SearchRequest] = None,
856
- check_request_payload: bool = True,
857
- check_response_payload: bool = True,
863
+ check_request_payload: Optional[bool] = None,
864
+ check_response_payload: Optional[bool] = None,
858
865
  expected_status_codes: Optional[
859
866
  list[int]
860
867
  ] = BaseSCIMClient.SEARCH_RESPONSE_STATUS_CODES,
861
- raise_scim_errors: bool = True,
868
+ raise_scim_errors: Optional[bool] = None,
862
869
  **kwargs,
863
870
  ) -> Union[AnyResource, ListResponse[AnyResource], Error, dict]:
864
871
  """Perform a POST search request to read all available resources, as defined in :rfc:`RFC7644 §3.4.3 <7644#section-3.4.3>`.
@@ -866,15 +873,11 @@ class BaseAsyncSCIMClient(BaseSCIMClient):
866
873
  :param resource_models: Resource type or union of types expected
867
874
  to be read from the response.
868
875
  :param search_request: An object detailing the search query parameters.
869
- :param check_request_payload: If :data:`False`,
870
- :code:`search_request` is expected to be a dict that will be passed as-is in the request.
871
- :param check_response_payload: Whether to validate that the response payload is valid.
872
- If set, the raw payload will be returned.
876
+ :param check_request_payload: If set, overwrites :paramref:`BaseSCIMClient.check_request_payload`.
877
+ :param check_response_payload: If set, overwrites :paramref:`BaseSCIMClient.check_response_payload`.
873
878
  :param expected_status_codes: The list of expected status codes form the response.
874
879
  If :data:`None` any status code is accepted.
875
- :param raise_scim_errors: If :data:`True` and the server returned an
876
- :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
877
- exception will be raised. If :data:`False` the error object is returned.
880
+ :param raise_scim_errors: If set, overwrites :paramref:`BaseSCIMClient.raise_scim_errors`.
878
881
  :param kwargs: Additional parameters passed to the underlying
879
882
  HTTP request library.
880
883
 
@@ -906,24 +909,21 @@ class BaseAsyncSCIMClient(BaseSCIMClient):
906
909
  self,
907
910
  resource_model: type,
908
911
  id: str,
909
- check_response_payload: bool = True,
912
+ check_response_payload: Optional[bool] = None,
910
913
  expected_status_codes: Optional[
911
914
  list[int]
912
915
  ] = BaseSCIMClient.DELETION_RESPONSE_STATUS_CODES,
913
- raise_scim_errors: bool = True,
916
+ raise_scim_errors: Optional[bool] = None,
914
917
  **kwargs,
915
918
  ) -> Optional[Union[Error, dict]]:
916
919
  """Perform a DELETE request to create, as defined in :rfc:`RFC7644 §3.6 <7644#section-3.6>`.
917
920
 
918
921
  :param resource_model: The type of the resource to delete.
919
922
  :param id: The type id the resource to delete.
920
- :param check_response_payload: Whether to validate that the response payload is valid.
921
- If set, the raw payload will be returned.
923
+ :param check_response_payload: If set, overwrites :paramref:`BaseSCIMClient.check_response_payload`.
922
924
  :param expected_status_codes: The list of expected status codes form the response.
923
925
  If :data:`None` any status code is accepted.
924
- :param raise_scim_errors: If :data:`True` and the server returned an
925
- :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
926
- exception will be raised. If :data:`False` the error object is returned.
926
+ :param raise_scim_errors: If set, overwrites :paramref:`BaseSCIMClient.raise_scim_errors`.
927
927
  :param kwargs: Additional parameters passed to the underlying
928
928
  HTTP request library.
929
929
 
@@ -946,27 +946,23 @@ class BaseAsyncSCIMClient(BaseSCIMClient):
946
946
  async def replace(
947
947
  self,
948
948
  resource: Union[AnyResource, dict],
949
- check_request_payload: bool = True,
950
- check_response_payload: bool = True,
949
+ check_request_payload: Optional[bool] = None,
950
+ check_response_payload: Optional[bool] = None,
951
951
  expected_status_codes: Optional[
952
952
  list[int]
953
953
  ] = BaseSCIMClient.REPLACEMENT_RESPONSE_STATUS_CODES,
954
- raise_scim_errors: bool = True,
954
+ raise_scim_errors: Optional[bool] = None,
955
955
  **kwargs,
956
956
  ) -> Union[AnyResource, Error, dict]:
957
957
  """Perform a PUT request to replace a resource, as defined in :rfc:`RFC7644 §3.5.1 <7644#section-3.5.1>`.
958
958
 
959
959
  :param resource: The new resource to replace.
960
960
  If is a :data:`dict`, the resource type will be guessed from the schema.
961
- :param check_request_payload: If :data:`False`,
962
- :code:`resource` is expected to be a dict that will be passed as-is in the request.
963
- :param check_response_payload: Whether to validate that the response payload is valid.
964
- If set, the raw payload will be returned.
961
+ :param check_request_payload: If set, overwrites :paramref:`BaseSCIMClient.check_request_payload`.
962
+ :param check_response_payload: If set, overwrites :paramref:`BaseSCIMClient.check_response_payload`.
965
963
  :param expected_status_codes: The list of expected status codes form the response.
966
964
  If :data:`None` any status code is accepted.
967
- :param raise_scim_errors: If :data:`True` and the server returned an
968
- :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
969
- exception will be raised. If :data:`False` the error object is returned.
965
+ :param raise_scim_errors: If set, overwrites :paramref:`BaseSCIMClient.raise_scim_errors`.
970
966
  :param kwargs: Additional parameters passed to the underlying
971
967
  HTTP request library.
972
968
 
@@ -52,23 +52,29 @@ class SyncSCIMClient(BaseSyncSCIMClient):
52
52
  :param client: A :class:`httpx.Client` instance that will be used to send requests.
53
53
  :param resource_models: A tuple of :class:`~scim2_models.Resource` types expected to be handled by the SCIM client.
54
54
  If a request payload describe a resource that is not in this list, an exception will be raised.
55
+ :param check_request_payload: If :data:`False`,
56
+ :code:`resource` is expected to be a dict that will be passed as-is in the request.
57
+ This value can be overwritten in methods.
58
+ :param check_response_payload: Whether to validate that the response payloads are valid.
59
+ If set, the raw payload will be returned. This value can be overwritten in methods.
60
+ :param raise_scim_errors: If :data:`True` and the server returned an
61
+ :class:`~scim2_models.Error` object during a request, a :class:`~scim2_client.SCIMResponseErrorObject`
62
+ exception will be raised. If :data:`False` the error object is returned. This value can be overwritten in methods.
55
63
  """
56
64
 
57
- def __init__(
58
- self, client: Client, resource_models: Optional[tuple[type[Resource]]] = None
59
- ):
60
- super().__init__(resource_models=resource_models)
65
+ def __init__(self, client: Client, *args, **kwargs):
66
+ super().__init__(*args, **kwargs)
61
67
  self.client = client
62
68
 
63
69
  def create(
64
70
  self,
65
71
  resource: Union[AnyResource, dict],
66
- check_request_payload: bool = True,
67
- check_response_payload: bool = True,
72
+ check_request_payload: Optional[bool] = None,
73
+ check_response_payload: Optional[bool] = None,
68
74
  expected_status_codes: Optional[
69
75
  list[int]
70
76
  ] = BaseSyncSCIMClient.CREATION_RESPONSE_STATUS_CODES,
71
- raise_scim_errors: bool = True,
77
+ raise_scim_errors: Optional[bool] = None,
72
78
  **kwargs,
73
79
  ) -> Union[AnyResource, Error, dict]:
74
80
  req = self.prepare_create_request(
@@ -99,12 +105,12 @@ class SyncSCIMClient(BaseSyncSCIMClient):
99
105
  resource_model: Optional[type[Resource]] = None,
100
106
  id: Optional[str] = None,
101
107
  search_request: Optional[Union[SearchRequest, dict]] = None,
102
- check_request_payload: bool = True,
103
- check_response_payload: bool = True,
108
+ check_request_payload: Optional[bool] = None,
109
+ check_response_payload: Optional[bool] = None,
104
110
  expected_status_codes: Optional[
105
111
  list[int]
106
112
  ] = BaseSyncSCIMClient.QUERY_RESPONSE_STATUS_CODES,
107
- raise_scim_errors: bool = True,
113
+ raise_scim_errors: Optional[bool] = None,
108
114
  **kwargs,
109
115
  ):
110
116
  req = self.prepare_query_request(
@@ -137,12 +143,12 @@ class SyncSCIMClient(BaseSyncSCIMClient):
137
143
  def search(
138
144
  self,
139
145
  search_request: Optional[SearchRequest] = None,
140
- check_request_payload: bool = True,
141
- check_response_payload: bool = True,
146
+ check_request_payload: Optional[bool] = None,
147
+ check_response_payload: Optional[bool] = None,
142
148
  expected_status_codes: Optional[
143
149
  list[int]
144
150
  ] = BaseSyncSCIMClient.SEARCH_RESPONSE_STATUS_CODES,
145
- raise_scim_errors: bool = True,
151
+ raise_scim_errors: Optional[bool] = None,
146
152
  **kwargs,
147
153
  ) -> Union[AnyResource, ListResponse[AnyResource], Error, dict]:
148
154
  req = self.prepare_search_request(
@@ -172,11 +178,11 @@ class SyncSCIMClient(BaseSyncSCIMClient):
172
178
  self,
173
179
  resource_model: type,
174
180
  id: str,
175
- check_response_payload: bool = True,
181
+ check_response_payload: Optional[bool] = None,
176
182
  expected_status_codes: Optional[
177
183
  list[int]
178
184
  ] = BaseSyncSCIMClient.DELETION_RESPONSE_STATUS_CODES,
179
- raise_scim_errors: bool = True,
185
+ raise_scim_errors: Optional[bool] = None,
180
186
  **kwargs,
181
187
  ) -> Optional[Union[Error, dict]]:
182
188
  req = self.prepare_delete_request(
@@ -203,12 +209,12 @@ class SyncSCIMClient(BaseSyncSCIMClient):
203
209
  def replace(
204
210
  self,
205
211
  resource: Union[AnyResource, dict],
206
- check_request_payload: bool = True,
207
- check_response_payload: bool = True,
212
+ check_request_payload: Optional[bool] = None,
213
+ check_response_payload: Optional[bool] = None,
208
214
  expected_status_codes: Optional[
209
215
  list[int]
210
216
  ] = BaseSyncSCIMClient.REPLACEMENT_RESPONSE_STATUS_CODES,
211
- raise_scim_errors: bool = True,
217
+ raise_scim_errors: Optional[bool] = None,
212
218
  **kwargs,
213
219
  ) -> Union[AnyResource, Error, dict]:
214
220
  req = self.prepare_replace_request(
@@ -241,23 +247,30 @@ class AsyncSCIMClient(BaseAsyncSCIMClient):
241
247
  :param client: A :class:`httpx.AsyncClient` instance that will be used to send requests.
242
248
  :param resource_models: A tuple of :class:`~scim2_models.Resource` types expected to be handled by the SCIM client.
243
249
  If a request payload describe a resource that is not in this list, an exception will be raised.
250
+ :param check_request_payload: If :data:`False`,
251
+ :code:`resource` is expected to be a dict that will be passed as-is in the request.
252
+ This value can be overwritten in methods.
253
+ :param check_response_payload: Whether to validate that the response payloads are valid.
254
+ If set, the raw payload will be returned. This value can be overwritten in methods.
255
+ :param raise_scim_errors: If :data:`True` and the server returned an
256
+ :class:`~scim2_models.Error` object during a request, a :class:`~scim2_client.SCIMResponseErrorObject`
257
+ exception will be raised. If :data:`False` the error object is returned. This value can be overwritten in methods.
258
+
244
259
  """
245
260
 
246
- def __init__(
247
- self, client: Client, resource_models: Optional[tuple[type[Resource]]] = None
248
- ):
249
- super().__init__(resource_models=resource_models)
261
+ def __init__(self, client: Client, *args, **kwargs):
262
+ super().__init__(*args, **kwargs)
250
263
  self.client = client
251
264
 
252
265
  async def create(
253
266
  self,
254
267
  resource: Union[AnyResource, dict],
255
- check_request_payload: bool = True,
256
- check_response_payload: bool = True,
268
+ check_request_payload: Optional[bool] = None,
269
+ check_response_payload: Optional[bool] = None,
257
270
  expected_status_codes: Optional[
258
271
  list[int]
259
272
  ] = BaseAsyncSCIMClient.CREATION_RESPONSE_STATUS_CODES,
260
- raise_scim_errors: bool = True,
273
+ raise_scim_errors: Optional[bool] = None,
261
274
  **kwargs,
262
275
  ) -> Union[AnyResource, Error, dict]:
263
276
  req = self.prepare_create_request(
@@ -290,12 +303,12 @@ class AsyncSCIMClient(BaseAsyncSCIMClient):
290
303
  resource_model: Optional[type[Resource]] = None,
291
304
  id: Optional[str] = None,
292
305
  search_request: Optional[Union[SearchRequest, dict]] = None,
293
- check_request_payload: bool = True,
294
- check_response_payload: bool = True,
306
+ check_request_payload: Optional[bool] = None,
307
+ check_response_payload: Optional[bool] = None,
295
308
  expected_status_codes: Optional[
296
309
  list[int]
297
310
  ] = BaseAsyncSCIMClient.QUERY_RESPONSE_STATUS_CODES,
298
- raise_scim_errors: bool = True,
311
+ raise_scim_errors: Optional[bool] = None,
299
312
  **kwargs,
300
313
  ):
301
314
  req = self.prepare_query_request(
@@ -328,12 +341,12 @@ class AsyncSCIMClient(BaseAsyncSCIMClient):
328
341
  async def search(
329
342
  self,
330
343
  search_request: Optional[SearchRequest] = None,
331
- check_request_payload: bool = True,
332
- check_response_payload: bool = True,
344
+ check_request_payload: Optional[bool] = None,
345
+ check_response_payload: Optional[bool] = None,
333
346
  expected_status_codes: Optional[
334
347
  list[int]
335
348
  ] = BaseAsyncSCIMClient.SEARCH_RESPONSE_STATUS_CODES,
336
- raise_scim_errors: bool = True,
349
+ raise_scim_errors: Optional[bool] = None,
337
350
  **kwargs,
338
351
  ) -> Union[AnyResource, ListResponse[AnyResource], Error, dict]:
339
352
  req = self.prepare_search_request(
@@ -365,11 +378,11 @@ class AsyncSCIMClient(BaseAsyncSCIMClient):
365
378
  self,
366
379
  resource_model: type,
367
380
  id: str,
368
- check_response_payload: bool = True,
381
+ check_response_payload: Optional[bool] = None,
369
382
  expected_status_codes: Optional[
370
383
  list[int]
371
384
  ] = BaseAsyncSCIMClient.DELETION_RESPONSE_STATUS_CODES,
372
- raise_scim_errors: bool = True,
385
+ raise_scim_errors: Optional[bool] = None,
373
386
  **kwargs,
374
387
  ) -> Optional[Union[Error, dict]]:
375
388
  req = self.prepare_delete_request(
@@ -396,12 +409,12 @@ class AsyncSCIMClient(BaseAsyncSCIMClient):
396
409
  async def replace(
397
410
  self,
398
411
  resource: Union[AnyResource, dict],
399
- check_request_payload: bool = True,
400
- check_response_payload: bool = True,
412
+ check_request_payload: Optional[bool] = None,
413
+ check_response_payload: Optional[bool] = None,
401
414
  expected_status_codes: Optional[
402
415
  list[int]
403
416
  ] = BaseAsyncSCIMClient.REPLACEMENT_RESPONSE_STATUS_CODES,
404
- raise_scim_errors: bool = True,
417
+ raise_scim_errors: Optional[bool] = None,
405
418
  **kwargs,
406
419
  ) -> Union[AnyResource, Error, dict]:
407
420
  req = self.prepare_replace_request(
@@ -36,6 +36,14 @@ class TestSCIMClient(BaseSyncSCIMClient):
36
36
  :param scim_prefix: The scim root endpoint in the application.
37
37
  :param resource_models: A tuple of :class:`~scim2_models.Resource` types expected to be handled by the SCIM client.
38
38
  If a request payload describe a resource that is not in this list, an exception will be raised.
39
+ :param check_request_payload: If :data:`False`,
40
+ :code:`resource` is expected to be a dict that will be passed as-is in the request.
41
+ This value can be overwritten in methods.
42
+ :param check_response_payload: Whether to validate that the response payloads are valid.
43
+ If set, the raw payload will be returned. This value can be overwritten in methods.
44
+ :param raise_scim_errors: If :data:`True` and the server returned an
45
+ :class:`~scim2_models.Error` object during a request, a :class:`~scim2_client.SCIMResponseErrorObject`
46
+ exception will be raised. If :data:`False` the error object is returned. This value can be overwritten in methods.
39
47
 
40
48
  .. code-block:: python
41
49
 
@@ -50,13 +58,8 @@ class TestSCIMClient(BaseSyncSCIMClient):
50
58
  assert response_user.user_name == "foo"
51
59
  """
52
60
 
53
- def __init__(
54
- self,
55
- app,
56
- scim_prefix: str = "",
57
- resource_models: Optional[tuple[type[Resource]]] = None,
58
- ):
59
- super().__init__(resource_models=resource_models)
61
+ def __init__(self, app, *args, scim_prefix: str = "", **kwargs):
62
+ super().__init__(*args, **kwargs)
60
63
  self.client = Client(app)
61
64
  self.scim_prefix = scim_prefix
62
65
 
@@ -71,12 +74,12 @@ class TestSCIMClient(BaseSyncSCIMClient):
71
74
  def create(
72
75
  self,
73
76
  resource: Union[AnyResource, dict],
74
- check_request_payload: bool = True,
75
- check_response_payload: bool = True,
77
+ check_request_payload: Optional[bool] = None,
78
+ check_response_payload: Optional[bool] = None,
76
79
  expected_status_codes: Optional[
77
80
  list[int]
78
81
  ] = BaseSyncSCIMClient.CREATION_RESPONSE_STATUS_CODES,
79
- raise_scim_errors: bool = True,
82
+ raise_scim_errors: Optional[bool] = None,
80
83
  **kwargs,
81
84
  ) -> Union[AnyResource, Error, dict]:
82
85
  req = self.prepare_create_request(
@@ -108,12 +111,12 @@ class TestSCIMClient(BaseSyncSCIMClient):
108
111
  resource_model: Optional[type[Resource]] = None,
109
112
  id: Optional[str] = None,
110
113
  search_request: Optional[Union[SearchRequest, dict]] = None,
111
- check_request_payload: bool = True,
112
- check_response_payload: bool = True,
114
+ check_request_payload: Optional[bool] = None,
115
+ check_response_payload: Optional[bool] = None,
113
116
  expected_status_codes: Optional[
114
117
  list[int]
115
118
  ] = BaseSyncSCIMClient.QUERY_RESPONSE_STATUS_CODES,
116
- raise_scim_errors: bool = True,
119
+ raise_scim_errors: Optional[bool] = None,
117
120
  **kwargs,
118
121
  ):
119
122
  req = self.prepare_query_request(
@@ -146,12 +149,12 @@ class TestSCIMClient(BaseSyncSCIMClient):
146
149
  def search(
147
150
  self,
148
151
  search_request: Optional[SearchRequest] = None,
149
- check_request_payload: bool = True,
150
- check_response_payload: bool = True,
152
+ check_request_payload: Optional[bool] = None,
153
+ check_response_payload: Optional[bool] = None,
151
154
  expected_status_codes: Optional[
152
155
  list[int]
153
156
  ] = BaseSyncSCIMClient.SEARCH_RESPONSE_STATUS_CODES,
154
- raise_scim_errors: bool = True,
157
+ raise_scim_errors: Optional[bool] = None,
155
158
  **kwargs,
156
159
  ) -> Union[AnyResource, ListResponse[AnyResource], Error, dict]:
157
160
  req = self.prepare_search_request(
@@ -182,11 +185,11 @@ class TestSCIMClient(BaseSyncSCIMClient):
182
185
  self,
183
186
  resource_model: type,
184
187
  id: str,
185
- check_response_payload: bool = True,
188
+ check_response_payload: Optional[bool] = None,
186
189
  expected_status_codes: Optional[
187
190
  list[int]
188
191
  ] = BaseSyncSCIMClient.DELETION_RESPONSE_STATUS_CODES,
189
- raise_scim_errors: bool = True,
192
+ raise_scim_errors: Optional[bool] = None,
190
193
  **kwargs,
191
194
  ) -> Optional[Union[Error, dict]]:
192
195
  req = self.prepare_delete_request(
@@ -212,12 +215,12 @@ class TestSCIMClient(BaseSyncSCIMClient):
212
215
  def replace(
213
216
  self,
214
217
  resource: Union[AnyResource, dict],
215
- check_request_payload: bool = True,
216
- check_response_payload: bool = True,
218
+ check_request_payload: Optional[bool] = None,
219
+ check_response_payload: Optional[bool] = None,
217
220
  expected_status_codes: Optional[
218
221
  list[int]
219
222
  ] = BaseSyncSCIMClient.REPLACEMENT_RESPONSE_STATUS_CODES,
220
- raise_scim_errors: bool = True,
223
+ raise_scim_errors: Optional[bool] = None,
221
224
  **kwargs,
222
225
  ) -> Union[AnyResource, Error, dict]:
223
226
  req = self.prepare_replace_request(
scim2_client/errors.py CHANGED
@@ -69,12 +69,9 @@ class SCIMResponseErrorObject(SCIMResponseError):
69
69
  Those errors are only raised when the :code:`raise_scim_errors` parameter is :data:`True`.
70
70
  """
71
71
 
72
- def __init__(self, *args, **kwargs):
72
+ def __init__(self, obj, *args, **kwargs):
73
73
  message = kwargs.pop(
74
- "message",
75
- f"The server returned a SCIM Error object: {kwargs['source'].detail}"
76
- if kwargs.get("source")
77
- else "The server returned a SCIM Error object",
74
+ "message", f"The server returned a SCIM Error object: {obj}"
78
75
  )
79
76
  super().__init__(message, *args, **kwargs)
80
77
 
@@ -82,12 +79,9 @@ class SCIMResponseErrorObject(SCIMResponseError):
82
79
  class UnexpectedStatusCode(SCIMResponseError):
83
80
  """Error raised when a server returned an unexpected status code for a given :class:`~scim2_models.Context`."""
84
81
 
85
- def __init__(self, *args, **kwargs):
82
+ def __init__(self, status_code: int, *args, **kwargs):
86
83
  message = kwargs.pop(
87
- "message",
88
- f"Unexpected response status code: {kwargs['source'].status_code}"
89
- if kwargs.get("source")
90
- else "Unexpected response status code",
84
+ "message", f"Unexpected response status code: {status_code}"
91
85
  )
92
86
  super().__init__(message, *args, **kwargs)
93
87
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: scim2-client
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Pythonically build SCIM requests and parse SCIM responses
5
5
  Project-URL: documentation, https://scim2-client.readthedocs.io
6
6
  Project-URL: repository, https://github.com/python-scim/scim2-client
@@ -0,0 +1,11 @@
1
+ scim2_client/__init__.py,sha256=KpNDJW9e2WseqSsQ6FltkQzemHM52NACfpJTd3eSIuY,853
2
+ scim2_client/client.py,sha256=C45mWwWlesXv7zdANmDf9psz3JczV02cI7Pc6becg3M,39742
3
+ scim2_client/errors.py,sha256=mxjUvarjvX3797w2NzdLqc6zxCQZlOga8cYABWpUAXM,4401
4
+ scim2_client/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ scim2_client/engines/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ scim2_client/engines/httpx.py,sha256=L39ZZHjqe43uIQpgh_r_maqM2gkf3_Rk6d8MeNe57gk,17781
7
+ scim2_client/engines/werkzeug.py,sha256=s7BV8CEbLewnkF0EAsF-3J3khOhaT7CkEN9v230ZA8w,9838
8
+ scim2_client-0.3.2.dist-info/METADATA,sha256=Zu2tIFT443yoDOKu2AjAtBSWxRB1x9WXqpf1GM0Af0w,16997
9
+ scim2_client-0.3.2.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
10
+ scim2_client-0.3.2.dist-info/licenses/LICENSE.md,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
11
+ scim2_client-0.3.2.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- scim2_client/__init__.py,sha256=KpNDJW9e2WseqSsQ6FltkQzemHM52NACfpJTd3eSIuY,853
2
- scim2_client/client.py,sha256=CPXPqnmYNcXgn5ViPFpapI-oEg0oX8kXnwdWWmjm4eI,40130
3
- scim2_client/errors.py,sha256=VDomHej2WH07up6a2wr7q0BVdj6RG4MyrM2t9UHx0Iw,4623
4
- scim2_client/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- scim2_client/engines/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- scim2_client/engines/httpx.py,sha256=uqONJhFUdFf8W-GndL-mB_Z33FRuwgXAb2PczTB7wLg,16268
7
- scim2_client/engines/werkzeug.py,sha256=9KcViIJVzSda6cpeiM-_dFjp5HFDBFkfiGRaUx4utrk,9107
8
- scim2_client-0.3.0.dist-info/METADATA,sha256=1aFhLfcE_1TXEI7iMjJUc8G99dmaViqJoN01BM8-_Rk,16997
9
- scim2_client-0.3.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
10
- scim2_client-0.3.0.dist-info/licenses/LICENSE.md,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
11
- scim2_client-0.3.0.dist-info/RECORD,,