Engines#
The classes an application instantiates. Each one performs the requests with one HTTP library, and inherits the payload handling from the base client.
- class scim2_client.engines.httpx2.SyncSCIMClient(client: Client, *args: Any, **kwargs: Any)[source]#
Perform SCIM requests over the network and validate responses.
- Parameters:
client¶ – A
httpx2.Clientinstance that will be used to send requests.provider¶ – The
ScimProviderdescribing the server. If a request payload describe a resource it does not know, an exception will be raised. TheScimPolicyit carries rules how much the payloads exchanged with the server may depart from the specification.check_request_payload¶ – If
False,resourceis expected to be a dict that will be passed as-is in the request. This value can be overwritten in methods.check_response_payload¶ – Whether to validate that the response payloads are valid. If set, the raw payload will be returned. This value can be overwritten in methods.
raise_scim_errors¶ – If
Trueand the server returned anErrorobject during a request, aSCIMExceptionexception will be raised. IfFalsethe error object is returned. This value can be overwritten in methods.
- request(method: str, url: str, **kwargs: Any) Response[source]#
Send a request to the server, without any SCIM processing.
Neither the request nor the response is checked, so this is fitted to observe how the server behaves, for instance with an unsupported HTTP method.
- Parameters:
- Returns:
The response of the underlying HTTP request library.
- Raises:
RequestNetworkException – When the request cannot be sent.
- Usage:
Checking that the/Schemasendpoint refusesDELETE#response = scim.request("DELETE", "/Schemas") assert response.status_code == 405
- class scim2_client.engines.httpx2.AsyncSCIMClient(client: AsyncClient, *args: Any, **kwargs: Any)[source]#
Perform SCIM requests over the network and validate responses.
- Parameters:
client¶ – A
httpx2.AsyncClientinstance that will be used to send requests.provider¶ – The
ScimProviderdescribing the server. If a request payload describe a resource it does not know, an exception will be raised. TheScimPolicyit carries rules how much the payloads exchanged with the server may depart from the specification.check_request_payload¶ – If
False,resourceis expected to be a dict that will be passed as-is in the request. This value can be overwritten in methods.check_response_payload¶ – Whether to validate that the response payloads are valid. If set, the raw payload will be returned. This value can be overwritten in methods.
raise_scim_errors¶ – If
Trueand the server returned anErrorobject during a request, aSCIMExceptionexception will be raised. IfFalsethe error object is returned. This value can be overwritten in methods.
- async request(method: str, url: str, **kwargs: Any) Response[source]#
Send a request to the server, without any SCIM processing.
Neither the request nor the response is checked, so this is fitted to observe how the server behaves, for instance with an unsupported HTTP method.
- Parameters:
- Returns:
The response of the underlying HTTP request library.
- Raises:
RequestNetworkException – When the request cannot be sent.
- Usage:
Checking that the/Schemasendpoint refusesDELETE#response = await scim.request("DELETE", "/Schemas") assert response.status_code == 405
- class scim2_client.engines.wsgi.WSGISCIMClient(app: WSGIApplication, base_url: str = 'http://localhost', headers: Mapping[str, str] | Iterable[tuple[str, str]] | None = None, environ: WSGIEnvironment | None = None, *args: Any, **kwargs: Any)[source]#
Call a WSGI application directly, without a network.
This is helpful for developers of SCIM servers. The server code runs in the test process, so an exception it raises reaches the test instead of turning into a
500response. It only needs the standard library.- Parameters:
base_url¶ – The absolute URL of the SCIM endpoints, such as
http://localhost/scim/v2. Its path is passed inPATH_INFO, andSCRIPT_NAMEis empty.headers¶ – Headers sent with every request. The headers passed to a request replace those of the same name.
environ¶ – Keys added to the WSGI environment of every request, such as
REMOTE_USER.provider¶ – The
ScimProviderdescribing the server. If a request payload describe a resource it does not know, an exception will be raised. TheScimPolicyit carries rules how much the payloads exchanged with the server may depart from the specification.check_request_payload¶ – If
False,resourceis expected to be a dict that will be passed as-is in the request. This value can be overwritten in methods.check_response_payload¶ – Whether to validate that the response payloads are valid. If set, the raw payload will be returned. This value can be overwritten in methods.
raise_scim_errors¶ – If
Trueand the server returned anErrorobject during a request, aSCIMExceptionexception will be raised. IfFalsethe error object is returned. This value can be overwritten in methods.
from scim2_client.engines.wsgi import WSGISCIMClient from scim2_models import Group, ScimProvider, User scim = WSGISCIMClient( myapp.create_app(), base_url="http://localhost/scim/v2", provider=ScimProvider(models=[User, Group]), ) user = scim.create(User(user_name="bjensen@example.com")) assert user.id
- request(method: str, url: str, **kwargs: Any) InProcessResponse[source]#
Send a request to the server, without any SCIM processing.
Neither the request nor the response is checked, so this is fitted to observe how the server behaves, for instance with an unsupported HTTP method.
- Parameters:
- Returns:
The response of the underlying HTTP request library.
- Raises:
RequestNetworkException – When the request cannot be sent.
- Usage:
Checking that the/Schemasendpoint refusesDELETE#response = scim.request("DELETE", "/Schemas") assert response.status_code == 405
- class scim2_client.engines.asgi.ASGISCIMClient(app: Callable[[MutableMapping[str, Any], Callable[[], Awaitable[MutableMapping[str, Any]]], Callable[[MutableMapping[str, Any]], Awaitable[None]]], Awaitable[None]], base_url: str = 'http://localhost', headers: Mapping[str, str] | Iterable[tuple[str, str]] | None = None, scope: MutableMapping[str, Any] | None = None, *args: Any, **kwargs: Any)[source]#
Call an ASGI application directly, without a network.
This is helpful for developers of asynchronous SCIM servers. The server code runs in the test event loop, so an exception it raises reaches the test instead of turning into a
500response. It only needs the standard library, and runs withasyncio.The
lifespanmessages are not sent: an application that needs them must be started apart.- Parameters:
app¶ – The ASGI 3 application.
base_url¶ – The absolute URL of the SCIM endpoints, such as
http://localhost/scim/v2. Its path is passed in thepathof the scope, androot_pathis empty.headers¶ – Headers sent with every request. The headers passed to a request replace those of the same name.
scope¶ – Keys added to the ASGI scope of every request, such as
stateoruser.provider¶ – The
ScimProviderdescribing the server. If a request payload describe a resource it does not know, an exception will be raised. TheScimPolicyit carries rules how much the payloads exchanged with the server may depart from the specification.check_request_payload¶ – If
False,resourceis expected to be a dict that will be passed as-is in the request. This value can be overwritten in methods.check_response_payload¶ – Whether to validate that the response payloads are valid. If set, the raw payload will be returned. This value can be overwritten in methods.
raise_scim_errors¶ – If
Trueand the server returned anErrorobject during a request, aSCIMExceptionexception will be raised. IfFalsethe error object is returned. This value can be overwritten in methods.
from scim2_client.engines.asgi import ASGISCIMClient from scim2_models import Group, ScimProvider, User scim = ASGISCIMClient( myapp.create_app(), base_url="http://localhost/scim/v2", provider=ScimProvider(models=[User, Group]), ) user = await scim.create(User(user_name="bjensen@example.com")) assert user.id
- async request(method: str, url: str, **kwargs: Any) InProcessResponse[source]#
Send a request to the server, without any SCIM processing.
Neither the request nor the response is checked, so this is fitted to observe how the server behaves, for instance with an unsupported HTTP method.
- Parameters:
- Returns:
The response of the underlying HTTP request library.
- Raises:
RequestNetworkException – When the request cannot be sent.
- Usage:
Checking that the/Schemasendpoint refusesDELETE#response = await scim.request("DELETE", "/Schemas") assert response.status_code == 405
- class scim2_client.engines.inprocess.InProcessResponse(status_code: int, headers: Headers = <factory>, content: bytes = b'')[source]#
The response of an application called by an in-process engine.
It has the attributes of
RawResponse.- property text: str#
The body, decoded as UTF-8 (RFC 8259 Section 8.1).
- class scim2_client.engines.werkzeug.TestSCIMClient(client: Client, environ: dict[str, Any] | None = None, scim_prefix: str = '', *args: Any, **kwargs: Any)[source]#
A client based on
Werkzeug test Clientfor application development purposes.This is helpful for developers of SCIM servers. This client avoids to perform real HTTP requests and directly execute the server code instead. This allows to dynamically catch the exceptions if something gets wrong.
Deprecated since version 0.12: Use
WSGISCIMClient, which needs no dependency. Will be removed in 1.0.- Parameters:
client¶ – An optional custom
Werkzeug test Client. IfNonea default client is initialized.scim_prefix¶ – The scim root endpoint in the application.
environ¶ – Additional parameters that will be passed to every request.
provider¶ – The
ScimProviderdescribing the server. If a request payload describe a resource it does not know, an exception will be raised. TheScimPolicyit carries rules how much the payloads exchanged with the server may depart from the specification.check_request_payload¶ – If
False,resourceis expected to be a dict that will be passed as-is in the request. This value can be overwritten in methods.check_response_payload¶ – Whether to validate that the response payloads are valid. If set, the raw payload will be returned. This value can be overwritten in methods.
raise_scim_errors¶ – If
Trueand the server returned anErrorobject during a request, aSCIMExceptionexception will be raised. IfFalsethe error object is returned. This value can be overwritten in methods.
from scim2_client.engines.werkzeug import TestSCIMClient from scim2_models import User, Group from werkzeug.test import Client scim_provider = myapp.create_app() testclient = TestSCIMClient( app=Client(scim_provider), environ={"base_url": "/scim/v2"}, resource_models=(User, Group), ) request_user = User(user_name="foo", display_name="bar") response_user = scim_client.create(request_user) assert response_user.user_name == "foo"
- request(method: str, url: str, **kwargs: Any) TestResponse[source]#
Send a request to the server, without any SCIM processing.
Neither the request nor the response is checked, so this is fitted to observe how the server behaves, for instance with an unsupported HTTP method.
- Parameters:
- Returns:
The response of the underlying HTTP request library.
- Raises:
RequestNetworkException – When the request cannot be sent.
- Usage:
Checking that the/Schemasendpoint refusesDELETE#response = scim.request("DELETE", "/Schemas") assert response.status_code == 405