Skip to content

Commit 640e859

Browse files
committed
refactor: all checkers return list of CheckResult
1 parent 471cdf7 commit 640e859

19 files changed

+293
-242
lines changed

scim2_tester/checker.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ def check_server(
7272
context = CheckContext(client, conf)
7373
results = []
7474

75-
result_spc = service_provider_config_endpoint(context)
76-
results.append(result_spc)
75+
result_spc_list = service_provider_config_endpoint(context)
76+
results.extend(result_spc_list)
77+
result_spc = result_spc_list[0] # Get the first (and only) result
7778
if result_spc.status != Status.SKIPPED and not client.service_provider_config:
7879
client.service_provider_config = result_spc.data
7980

@@ -103,7 +104,7 @@ def check_server(
103104
return results
104105

105106
result_random = random_url(context)
106-
results.append(result_random)
107+
results.extend(result_random)
107108

108109
for resource_type in client.resource_types or []:
109110
if conf.resource_types and resource_type.name not in conf.resource_types:

scim2_tester/checkers/misc.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
@checker("misc")
13-
def random_url(context: CheckContext) -> CheckResult:
13+
def random_url(context: CheckContext) -> list[CheckResult]:
1414
"""Validate server error handling for non-existent endpoints.
1515
1616
Tests that the server properly returns a :class:`~scim2_models.Error` object with HTTP 404 status
@@ -37,21 +37,27 @@ def random_url(context: CheckContext) -> CheckResult:
3737
)
3838

3939
if not isinstance(response, Error):
40-
return CheckResult(
41-
status=Status.ERROR,
42-
reason=f"{probably_invalid_url} did not return an Error object",
43-
data=response,
44-
)
40+
return [
41+
CheckResult(
42+
status=Status.ERROR,
43+
reason=f"{probably_invalid_url} did not return an Error object",
44+
data=response,
45+
)
46+
]
4547

4648
if response.status != 404:
47-
return CheckResult(
48-
status=Status.ERROR,
49-
reason=f"{probably_invalid_url} did return an object, but the status code is {response.status}",
49+
return [
50+
CheckResult(
51+
status=Status.ERROR,
52+
reason=f"{probably_invalid_url} did return an object, but the status code is {response.status}",
53+
data=response,
54+
)
55+
]
56+
57+
return [
58+
CheckResult(
59+
status=Status.SUCCESS,
60+
reason=f"{probably_invalid_url} correctly returned a 404 error",
5061
data=response,
5162
)
52-
53-
return CheckResult(
54-
status=Status.SUCCESS,
55-
reason=f"{probably_invalid_url} correctly returned a 404 error",
56-
data=response,
57-
)
63+
]

scim2_tester/checkers/resource.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ def resource_type_tests(
4343

4444
results = []
4545

46-
results.append(object_creation(context, model))
47-
results.append(object_query(context, model))
48-
results.append(object_query_without_id(context, model))
49-
results.append(object_replacement(context, model))
50-
results.append(object_deletion(context, model))
46+
results.extend(object_creation(context, model))
47+
results.extend(object_query(context, model))
48+
results.extend(object_query_without_id(context, model))
49+
results.extend(object_replacement(context, model))
50+
results.extend(object_deletion(context, model))
5151

5252
return results

scim2_tester/checkers/resource_delete.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010

1111
@checker("crud:delete")
12-
def object_deletion(context: CheckContext, model: type[Resource[Any]]) -> CheckResult:
12+
def object_deletion(
13+
context: CheckContext, model: type[Resource[Any]]
14+
) -> list[CheckResult]:
1315
"""Validate SCIM resource deletion via DELETE requests.
1416
1517
Tests that resources can be successfully deleted using DELETE method and
@@ -39,14 +41,18 @@ def object_deletion(context: CheckContext, model: type[Resource[Any]]) -> CheckR
3941

4042
try:
4143
context.client.query(model, test_obj.id)
42-
return CheckResult(
43-
status=Status.ERROR,
44-
reason=f"{model.__name__} object with id {test_obj.id} still exists after deletion",
45-
)
44+
return [
45+
CheckResult(
46+
status=Status.ERROR,
47+
reason=f"{model.__name__} object with id {test_obj.id} still exists after deletion",
48+
)
49+
]
4650
except Exception:
4751
pass
4852

49-
return CheckResult(
50-
status=Status.SUCCESS,
51-
reason=f"Successfully deleted {model.__name__} object with id {test_obj.id}",
52-
)
53+
return [
54+
CheckResult(
55+
status=Status.SUCCESS,
56+
reason=f"Successfully deleted {model.__name__} object with id {test_obj.id}",
57+
)
58+
]

scim2_tester/checkers/resource_get.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ def _model_from_resource_type(
2525

2626

2727
@checker("crud:read")
28-
def object_query(context: CheckContext, model: type[Resource[Any]]) -> CheckResult:
28+
def object_query(
29+
context: CheckContext, model: type[Resource[Any]]
30+
) -> list[CheckResult]:
2931
"""Validate SCIM resource retrieval by ID via GET requests.
3032
3133
Tests that individual resources can be successfully retrieved using GET method
@@ -52,17 +54,19 @@ def object_query(context: CheckContext, model: type[Resource[Any]]) -> CheckResu
5254
expected_status_codes=context.conf.expected_status_codes or [200],
5355
)
5456

55-
return CheckResult(
56-
status=Status.SUCCESS,
57-
reason=f"Successfully queried {model.__name__} object with id {test_obj.id}",
58-
data=response,
59-
)
57+
return [
58+
CheckResult(
59+
status=Status.SUCCESS,
60+
reason=f"Successfully queried {model.__name__} object with id {test_obj.id}",
61+
data=response,
62+
)
63+
]
6064

6165

6266
@checker("crud:read")
6367
def object_query_without_id(
6468
context: CheckContext, model: type[Resource[Any]]
65-
) -> CheckResult:
69+
) -> list[CheckResult]:
6670
"""Validate SCIM resource listing via GET requests without ID.
6771
6872
Tests that resources can be successfully listed using GET method on the
@@ -87,14 +91,18 @@ def object_query_without_id(
8791

8892
found = any(test_obj.id == resource.id for resource in response.resources)
8993
if not found:
90-
return CheckResult(
91-
status=Status.ERROR,
92-
reason=f"Could not find {model.__name__} object with id {test_obj.id} in list response",
94+
return [
95+
CheckResult(
96+
status=Status.ERROR,
97+
reason=f"Could not find {model.__name__} object with id {test_obj.id} in list response",
98+
data=response,
99+
)
100+
]
101+
102+
return [
103+
CheckResult(
104+
status=Status.SUCCESS,
105+
reason=f"Successfully found {model.__name__} object with id {test_obj.id} in list response",
93106
data=response,
94107
)
95-
96-
return CheckResult(
97-
status=Status.SUCCESS,
98-
reason=f"Successfully found {model.__name__} object with id {test_obj.id} in list response",
99-
data=response,
100-
)
108+
]

scim2_tester/checkers/resource_post.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010

1111
@checker("crud:create")
12-
def object_creation(context: CheckContext, model: type[Resource[Any]]) -> CheckResult:
12+
def object_creation(
13+
context: CheckContext, model: type[Resource[Any]]
14+
) -> list[CheckResult]:
1315
"""Validate SCIM resource creation via POST requests.
1416
1517
Tests that resources can be successfully created using POST method on the
@@ -31,8 +33,10 @@ def object_creation(context: CheckContext, model: type[Resource[Any]]) -> CheckR
3133
"""
3234
created_obj = context.resource_manager.create_and_register(model)
3335

34-
return CheckResult(
35-
status=Status.SUCCESS,
36-
reason=f"Successfully created {model.__name__} object with id {created_obj.id}",
37-
data=created_obj,
38-
)
36+
return [
37+
CheckResult(
38+
status=Status.SUCCESS,
39+
reason=f"Successfully created {model.__name__} object with id {created_obj.id}",
40+
data=created_obj,
41+
)
42+
]

scim2_tester/checkers/resource_put.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@checker("crud:update")
1414
def object_replacement(
1515
context: CheckContext, model: type[Resource[Any]]
16-
) -> CheckResult:
16+
) -> list[CheckResult]:
1717
"""Validate SCIM resource replacement via PUT requests.
1818
1919
Tests that resources can be successfully replaced using PUT method, modifying
@@ -54,8 +54,10 @@ def object_replacement(
5454
modified_obj, expected_status_codes=context.conf.expected_status_codes or [200]
5555
)
5656

57-
return CheckResult(
58-
status=Status.SUCCESS,
59-
reason=f"Successfully replaced {model.__name__} object with id {test_obj.id}",
60-
data=response,
61-
)
57+
return [
58+
CheckResult(
59+
status=Status.SUCCESS,
60+
reason=f"Successfully replaced {model.__name__} object with id {test_obj.id}",
61+
data=response,
62+
)
63+
]

scim2_tester/checkers/resource_types.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@ def _resource_types_endpoint(context: CheckContext) -> list[CheckResult]:
3232
"Service providers MUST provide this endpoint."
3333
3434
"""
35-
resource_types_result = query_all_resource_types(context)
36-
results = [resource_types_result]
35+
results = []
36+
resource_types_result_list = query_all_resource_types(context)
37+
results.extend(resource_types_result_list)
38+
resource_types_result = resource_types_result_list[
39+
0
40+
] # Get the first (and only) result
3741

3842
if resource_types_result.status == Status.SUCCESS:
3943
for resource_type in resource_types_result.data:
40-
results.append(query_resource_type_by_id(context, resource_type))
44+
results.extend(query_resource_type_by_id(context, resource_type))
4145

4246
results.extend(resource_types_schema_validation(context))
4347

44-
results.append(access_invalid_resource_type(context))
48+
results.extend(access_invalid_resource_type(context))
4549

4650
return results
4751

@@ -122,7 +126,7 @@ def resource_types_schema_validation(
122126

123127

124128
@checker("discovery", "resource-types")
125-
def query_all_resource_types(context: CheckContext) -> CheckResult:
129+
def query_all_resource_types(context: CheckContext) -> list[CheckResult]:
126130
"""Validate retrieval of all available resource types.
127131
128132
Tests that the ``/ResourceTypes`` endpoint returns a list of all supported
@@ -143,13 +147,13 @@ def query_all_resource_types(context: CheckContext) -> CheckResult:
143147
)
144148
available = ", ".join([f"'{resource.name}'" for resource in response.resources])
145149
reason = f"Resource types available are: {available}"
146-
return CheckResult(status=Status.SUCCESS, reason=reason, data=response.resources)
150+
return [CheckResult(status=Status.SUCCESS, reason=reason, data=response.resources)]
147151

148152

149153
@checker("discovery", "resource-types")
150154
def query_resource_type_by_id(
151155
context: CheckContext, resource_type: ResourceType
152-
) -> CheckResult:
156+
) -> list[CheckResult]:
153157
"""Validate individual ResourceType retrieval by ID.
154158
155159
Tests that specific resource types can be retrieved using GET requests
@@ -171,11 +175,11 @@ def query_resource_type_by_id(
171175
expected_status_codes=context.conf.expected_status_codes or [200],
172176
)
173177
reason = f"Successfully accessed the /ResourceTypes/{resource_type.id} endpoint."
174-
return CheckResult(status=Status.SUCCESS, reason=reason, data=response)
178+
return [CheckResult(status=Status.SUCCESS, reason=reason, data=response)]
175179

176180

177181
@checker("discovery", "resource-types")
178-
def access_invalid_resource_type(context: CheckContext) -> CheckResult:
182+
def access_invalid_resource_type(context: CheckContext) -> list[CheckResult]:
179183
"""Validate error handling for non-existent resource type IDs.
180184
181185
Tests that accessing ``/ResourceTypes/{invalid_id}`` with a non-existent resource
@@ -199,21 +203,27 @@ def access_invalid_resource_type(context: CheckContext) -> CheckResult:
199203
)
200204

201205
if not isinstance(response, Error):
202-
return CheckResult(
203-
status=Status.ERROR,
204-
reason=f"/resource_types/{probably_invalid_id} invalid URL did not return an Error object",
205-
data=response,
206-
)
206+
return [
207+
CheckResult(
208+
status=Status.ERROR,
209+
reason=f"/resource_types/{probably_invalid_id} invalid URL did not return an Error object",
210+
data=response,
211+
)
212+
]
207213

208214
if response.status != 404:
209-
return CheckResult(
210-
status=Status.ERROR,
211-
reason=f"/resource_types/{probably_invalid_id} invalid URL did return an object, but the status code is {response.status}",
215+
return [
216+
CheckResult(
217+
status=Status.ERROR,
218+
reason=f"/resource_types/{probably_invalid_id} invalid URL did return an object, but the status code is {response.status}",
219+
data=response,
220+
)
221+
]
222+
223+
return [
224+
CheckResult(
225+
status=Status.SUCCESS,
226+
reason=f"/resource_types/{probably_invalid_id} invalid URL correctly returned a 404 error",
212227
data=response,
213228
)
214-
215-
return CheckResult(
216-
status=Status.SUCCESS,
217-
reason=f"/resource_types/{probably_invalid_id} invalid URL correctly returned a 404 error",
218-
data=response,
219-
)
229+
]

0 commit comments

Comments
 (0)