@@ -37,10 +37,10 @@ class TestSCIMClient(BaseSyncSCIMClient):
3737 This client avoids to perform real HTTP requests and directly execute the server code instead.
3838 This allows to dynamically catch the exceptions if something gets wrong.
3939
40- :param app: A WSGI application instance that will be used to send requests.
4140 :param client: An optional custom :class:`Werkzeug test Client <werkzeug.test.Client>`.
4241 If :data:`None` a default client is initialized.
4342 :param scim_prefix: The scim root endpoint in the application.
43+ :param environ: Additional parameters that will be passed to every request.
4444 :param resource_models: A tuple of :class:`~scim2_models.Resource` types expected to be handled by the SCIM client.
4545 If a request payload describe a resource that is not in this list, an exception will be raised.
4646 :param check_request_payload: If :data:`False`,
@@ -56,9 +56,14 @@ class TestSCIMClient(BaseSyncSCIMClient):
5656
5757 from scim2_client.engines.werkzeug import TestSCIMClient
5858 from scim2_models import User, Group
59+ from werkzeug.test import Client
5960
6061 scim_provider = myapp.create_app()
61- testclient = TestSCIMClient(app=scim_provider, resource_models=(User, Group))
62+ testclient = TestSCIMClient(
63+ app=Client(scim_provider),
64+ environ={"base_url": "/scim/v2"},
65+ resource_models=(User, Group),
66+ )
6267
6368 request_user = User(user_name="foo", display_name="bar")
6469 response_user = scim_client.create(request_user)
@@ -70,15 +75,16 @@ class TestSCIMClient(BaseSyncSCIMClient):
7075
7176 def __init__ (
7277 self ,
73- app ,
74- client : Optional [Client ] = None ,
75- * args ,
78+ client : Client ,
79+ environ : Optional [dict ] = None ,
7680 scim_prefix : str = "" ,
81+ * args ,
7782 ** kwargs ,
7883 ):
7984 super ().__init__ (* args , ** kwargs )
80- self .client = client or Client ( app )
85+ self .client = client
8186 self .scim_prefix = scim_prefix
87+ self .environ = environ or {}
8288
8389 def make_url (self , url : Optional [str ]) -> str :
8490 url = url or ""
@@ -112,9 +118,8 @@ def create(
112118 ** kwargs ,
113119 )
114120
115- response = self .client .post (
116- self .make_url (req .url ), json = req .payload , ** req .request_kwargs
117- )
121+ environ = {** self .environ , ** req .request_kwargs }
122+ response = self .client .post (self .make_url (req .url ), json = req .payload , ** environ )
118123
119124 with handle_response_error (req .payload ):
120125 return self .check_response (
@@ -152,8 +157,9 @@ def query(
152157 )
153158
154159 query_string = urlencode (req .payload , doseq = False ) if req .payload else None
160+ environ = {** self .environ , ** req .request_kwargs }
155161 response = self .client .get (
156- self .make_url (req .url ), query_string = query_string , ** req . request_kwargs
162+ self .make_url (req .url ), query_string = query_string , ** environ
157163 )
158164
159165 with handle_response_error (req .payload ):
@@ -187,9 +193,8 @@ def search(
187193 ** kwargs ,
188194 )
189195
190- response = self .client .post (
191- self .make_url (req .url ), json = req .payload , ** req .request_kwargs
192- )
196+ environ = {** self .environ , ** req .request_kwargs }
197+ response = self .client .post (self .make_url (req .url ), json = req .payload , ** environ )
193198
194199 with handle_response_error (response ):
195200 return self .check_response (
@@ -222,7 +227,8 @@ def delete(
222227 ** kwargs ,
223228 )
224229
225- response = self .client .delete (self .make_url (req .url ), ** req .request_kwargs )
230+ environ = {** self .environ , ** req .request_kwargs }
231+ response = self .client .delete (self .make_url (req .url ), ** environ )
226232
227233 with handle_response_error (response ):
228234 return self .check_response (
@@ -253,9 +259,8 @@ def replace(
253259 ** kwargs ,
254260 )
255261
256- response = self .client .put (
257- self .make_url (req .url ), json = req .payload , ** req .request_kwargs
258- )
262+ environ = {** self .environ , ** req .request_kwargs }
263+ response = self .client .put (self .make_url (req .url ), json = req .payload , ** environ )
259264
260265 with handle_response_error (response ):
261266 return self .check_response (
0 commit comments