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.Client instance that will be used to send requests.

  • provider – The ScimProvider describing the server. If a request payload describe a resource it does not know, an exception will be raised. The ScimPolicy it carries rules how much the payloads exchanged with the server may depart from the specification.

  • resource_models – Deprecated, pass a provider instead.

  • check_request_payload – If False, resource is 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 True and the server returned an Error object during a request, a SCIMException exception will be raised. If False the 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:
  • method – The HTTP method.

  • url – The URL, relative to the SCIM server base URL.

  • kwargs – Additional parameters passed to the underlying HTTP request library.

Returns:

The response of the underlying HTTP request library.

Raises:

RequestNetworkException – When the request cannot be sent.

Usage:

Checking that the /Schemas endpoint refuses DELETE#
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.AsyncClient instance that will be used to send requests.

  • provider – The ScimProvider describing the server. If a request payload describe a resource it does not know, an exception will be raised. The ScimPolicy it carries rules how much the payloads exchanged with the server may depart from the specification.

  • resource_models – Deprecated, pass a provider instead.

  • check_request_payload – If False, resource is 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 True and the server returned an Error object during a request, a SCIMException exception will be raised. If False the 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:
  • method – The HTTP method.

  • url – The URL, relative to the SCIM server base URL.

  • kwargs – Additional parameters passed to the underlying HTTP request library.

Returns:

The response of the underlying HTTP request library.

Raises:

RequestNetworkException – When the request cannot be sent.

Usage:

Checking that the /Schemas endpoint refuses DELETE#
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 500 response. It only needs the standard library.

Parameters:
  • app – The WSGI application (PEP 3333).

  • base_url – The absolute URL of the SCIM endpoints, such as http://localhost/scim/v2. Its path is passed in PATH_INFO, and SCRIPT_NAME is 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 ScimProvider describing the server. If a request payload describe a resource it does not know, an exception will be raised. The ScimPolicy it carries rules how much the payloads exchanged with the server may depart from the specification.

  • check_request_payload – If False, resource is 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 True and the server returned an Error object during a request, a SCIMException exception will be raised. If False the 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:
  • method – The HTTP method.

  • url – The URL, relative to the SCIM server base URL.

  • kwargs – Additional parameters passed to the underlying HTTP request library.

Returns:

The response of the underlying HTTP request library.

Raises:

RequestNetworkException – When the request cannot be sent.

Usage:

Checking that the /Schemas endpoint refuses DELETE#
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 500 response. It only needs the standard library, and runs with asyncio.

The lifespan messages 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 the path of the scope, and root_path is 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 state or user.

  • provider – The ScimProvider describing the server. If a request payload describe a resource it does not know, an exception will be raised. The ScimPolicy it carries rules how much the payloads exchanged with the server may depart from the specification.

  • check_request_payload – If False, resource is 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 True and the server returned an Error object during a request, a SCIMException exception will be raised. If False the 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:
  • method – The HTTP method.

  • url – The URL, relative to the SCIM server base URL.

  • kwargs – Additional parameters passed to the underlying HTTP request library.

Returns:

The response of the underlying HTTP request library.

Raises:

RequestNetworkException – When the request cannot be sent.

Usage:

Checking that the /Schemas endpoint refuses DELETE#
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.

status_code: int#

The HTTP status code.

headers: Headers#

The HTTP headers. Their names are case insensitive.

content: bytes = b''#

The raw body.

property text: str#

The body, decoded as UTF-8 (RFC 8259 Section 8.1).

json() → Any[source]#

Return the body, decoded as JSON.

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 Client for 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. If None a 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 ScimProvider describing the server. If a request payload describe a resource it does not know, an exception will be raised. The ScimPolicy it carries rules how much the payloads exchanged with the server may depart from the specification.

  • resource_models – Deprecated, pass a provider instead.

  • check_request_payload – If False, resource is 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 True and the server returned an Error object during a request, a SCIMException exception will be raised. If False the 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:
  • method – The HTTP method.

  • url – The URL, relative to the SCIM server base URL.

  • kwargs – Additional parameters passed to the underlying HTTP request library.

Returns:

The response of the underlying HTTP request library.

Raises:

RequestNetworkException – When the request cannot be sent.

Usage:

Checking that the /Schemas endpoint refuses DELETE#
response = scim.request("DELETE", "/Schemas")
assert response.status_code == 405