11import json
22import os
33
4+ import pytest
45from scim2_models import AuthenticationScheme
56from scim2_models import Bulk
67from scim2_models import ChangePassword
78from scim2_models import ETag
89from scim2_models import Filter
10+ from scim2_models import ListResponse
911from scim2_models import Patch
1012from scim2_models import ResourceType
13+ from scim2_models import Schema
1114from scim2_models import ServiceProviderConfig
1215from scim2_models import Sort
1316from scim2_models import User
@@ -112,11 +115,9 @@ def test_env_vars(runner, httpserver, simple_user_payload):
112115 del os .environ ["SCIM_CLI_HEADERS" ]
113116
114117
115- def test_custom_configuration_by_parameter (
116- runner , httpserver , simple_user_payload , tmp_path
117- ):
118- """Test passing custom .JSON configuration files to the command."""
119- spc = ServiceProviderConfig (
118+ @pytest .fixture
119+ def service_provider_configuration ():
120+ return ServiceProviderConfig (
120121 documentation_uri = "https://scim.test" ,
121122 patch = Patch (supported = False ),
122123 bulk = Bulk (supported = False , max_operations = 0 , max_payload_size = 0 ),
@@ -134,29 +135,48 @@ def test_custom_configuration_by_parameter(
134135 primary = True ,
135136 ),
136137 ],
137- ). model_dump ()
138+ )
138139
139- spc_path = tmp_path / "service_provider_configuration.json"
140- with open (spc_path , "w" ) as fd :
141- json .dump (spc , fd )
142140
143- schemas = [ User . to_schema (). model_dump ()]
144- schemas_path = tmp_path / " schemas.json"
145- with open ( schemas_path , "w" ) as fd :
146- json . dump ( schemas , fd )
141+ @ pytest . fixture
142+ def schemas ():
143+ return [ User . to_schema ()]
144+
147145
148- resource_types = [
146+ @pytest .fixture
147+ def resource_types ():
148+ return [
149149 ResourceType (
150150 id = "User" ,
151151 name = "User" ,
152152 endpoint = "/somewhere-different" ,
153153 description = "User accounts" ,
154154 schema_ = "urn:ietf:params:scim:schemas:core:2.0:User" ,
155- ). model_dump ()
155+ )
156156 ]
157+
158+
159+ def test_custom_configuration_by_parameter (
160+ runner ,
161+ httpserver ,
162+ simple_user_payload ,
163+ tmp_path ,
164+ service_provider_configuration ,
165+ schemas ,
166+ resource_types ,
167+ ):
168+ """Test passing custom .JSON configuration files to the command."""
169+ spc_path = tmp_path / "service_provider_configuration.json"
170+ with open (spc_path , "w" ) as fd :
171+ json .dump (service_provider_configuration .model_dump (), fd )
172+
173+ schemas_path = tmp_path / "schemas.json"
174+ with open (schemas_path , "w" ) as fd :
175+ json .dump ([schema .model_dump () for schema in schemas ], fd )
176+
157177 resource_types_path = tmp_path / "resource_types.json"
158178 with open (resource_types_path , "w" ) as fd :
159- json .dump (resource_types , fd )
179+ json .dump ([ resource_type . model_dump () for resource_type in resource_types ] , fd )
160180
161181 httpserver .expect_request (
162182 "/somewhere-different/foobar" ,
@@ -187,49 +207,94 @@ def test_custom_configuration_by_parameter(
187207 assert result .exit_code == 0
188208
189209
190- def test_custom_configuration_by_env (runner , httpserver , simple_user_payload , tmp_path ):
191- """Test passing custom .JSON configuration files to the command."""
192- spc = ServiceProviderConfig (
193- documentation_uri = "https://scim.test" ,
194- patch = Patch (supported = False ),
195- bulk = Bulk (supported = False , max_operations = 0 , max_payload_size = 0 ),
196- change_password = ChangePassword (supported = True ),
197- filter = Filter (supported = False , max_results = 0 ),
198- sort = Sort (supported = False ),
199- etag = ETag (supported = False ),
200- authentication_schemes = [
201- AuthenticationScheme (
202- name = "OAuth Bearer Token" ,
203- description = "Authentication scheme using the OAuth Bearer Token Standard" ,
204- spec_uri = "http://www.rfc-editor.org/info/rfc6750" ,
205- documentation_uri = "https://scim.test" ,
206- type = "oauthbearertoken" ,
207- primary = True ,
208- ),
210+ def test_custom_configuration_in_list_response (
211+ runner ,
212+ httpserver ,
213+ simple_user_payload ,
214+ tmp_path ,
215+ service_provider_configuration ,
216+ schemas ,
217+ resource_types ,
218+ ):
219+ """Test that ListResponse format is supported."""
220+ spc_path = tmp_path / "service_provider_configuration.json"
221+ with open (spc_path , "w" ) as fd :
222+ json .dump (service_provider_configuration .model_dump (), fd )
223+
224+ schemas_path = tmp_path / "schemas.json"
225+ with open (schemas_path , "w" ) as fd :
226+ json .dump (
227+ ListResponse [Schema ](
228+ total_results = len (schemas ),
229+ start_index = 1 ,
230+ items_per_page = len (schemas ),
231+ resources = schemas ,
232+ ).model_dump (),
233+ fd ,
234+ )
235+
236+ resource_types_path = tmp_path / "resource_types.json"
237+ with open (resource_types_path , "w" ) as fd :
238+ json .dump (
239+ ListResponse [ResourceType ](
240+ total_results = len (resource_types ),
241+ start_index = 1 ,
242+ items_per_page = len (resource_types ),
243+ resources = resource_types ,
244+ ).model_dump (),
245+ fd ,
246+ )
247+
248+ httpserver .expect_request (
249+ "/somewhere-different/foobar" ,
250+ method = "GET" ,
251+ ).respond_with_json (
252+ simple_user_payload ("foobar" ),
253+ status = 200 ,
254+ content_type = "application/scim+json" ,
255+ )
256+
257+ result = runner .invoke (
258+ cli ,
259+ [
260+ "--url" ,
261+ httpserver .url_for ("/" ),
262+ "--service-provider-config" ,
263+ spc_path ,
264+ "--schemas" ,
265+ schemas_path ,
266+ "--resource-types" ,
267+ resource_types_path ,
268+ "query" ,
269+ "user" ,
270+ "foobar" ,
209271 ],
210- ).model_dump ()
272+ catch_exceptions = False ,
273+ )
274+ assert result .exit_code == 0
211275
276+
277+ def test_custom_configuration_by_env (
278+ runner ,
279+ httpserver ,
280+ simple_user_payload ,
281+ tmp_path ,
282+ service_provider_configuration ,
283+ schemas ,
284+ resource_types ,
285+ ):
286+ """Test passing custom .JSON configuration files to the command."""
212287 spc_path = tmp_path / "service_provider_configuration.json"
213288 with open (spc_path , "w" ) as fd :
214- json .dump (spc , fd )
289+ json .dump (service_provider_configuration . model_dump () , fd )
215290
216- schemas = [User .to_schema ().model_dump ()]
217291 schemas_path = tmp_path / "schemas.json"
218292 with open (schemas_path , "w" ) as fd :
219- json .dump (schemas , fd )
293+ json .dump ([ schema . model_dump () for schema in schemas ] , fd )
220294
221- resource_types = [
222- ResourceType (
223- id = "User" ,
224- name = "User" ,
225- endpoint = "/somewhere-different" ,
226- description = "User accounts" ,
227- schema_ = "urn:ietf:params:scim:schemas:core:2.0:User" ,
228- ).model_dump ()
229- ]
230295 resource_types_path = tmp_path / "resource_types.json"
231296 with open (resource_types_path , "w" ) as fd :
232- json .dump (resource_types , fd )
297+ json .dump ([ resource_type . model_dump () for resource_type in resource_types ] , fd )
233298
234299 httpserver .expect_request (
235300 "/somewhere-different/foobar" ,
0 commit comments