Skip to content

Commit 8781bf8

Browse files
committed
refactor: raise exceptions from the checker decorator instead of CheckResult
1 parent 8efd08c commit 8781bf8

14 files changed

Lines changed: 198 additions & 65 deletions

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ classifiers = [
2727
requires-python = ">= 3.10"
2828
dependencies = [
2929
"scim2-client>=0.4.0",
30+
"exceptiongroup>=1.0.0 ; python_full_version < '3.11'",
3031
]
3132

3233
[project.urls]

scim2_tester/checker.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,19 @@ def check_random_url(context: CheckContext) -> CheckResult:
2323

2424
if not isinstance(response, Error):
2525
return CheckResult(
26-
context.conf,
2726
status=Status.ERROR,
2827
reason=f"{probably_invalid_url} did not return an Error object",
2928
data=response,
3029
)
3130

3231
if response.status != 404:
3332
return CheckResult(
34-
context.conf,
3533
status=Status.ERROR,
3634
reason=f"{probably_invalid_url} did return an object, but the status code is {response.status}",
3735
data=response,
3836
)
3937

4038
return CheckResult(
41-
context.conf,
4239
status=Status.SUCCESS,
4340
reason=f"{probably_invalid_url} correctly returned a 404 error",
4441
data=response,

scim2_tester/resource.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def check_resource_type(
2525
if not model:
2626
return [
2727
CheckResult(
28-
context.conf,
2928
status=Status.ERROR,
3029
reason=f"No Schema matching the ResourceType {resource_type.id}",
3130
)

scim2_tester/resource_delete.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def check_object_deletion(context: CheckContext, model: type[Resource]) -> Check
3232
try:
3333
context.client.query(model, test_obj.id)
3434
return CheckResult(
35-
context.conf,
3635
status=Status.ERROR,
3736
reason=f"{model.__name__} object with id {test_obj.id} still exists after deletion",
3837
)
@@ -41,7 +40,6 @@ def check_object_deletion(context: CheckContext, model: type[Resource]) -> Check
4140
pass
4241

4342
return CheckResult(
44-
context.conf,
4543
status=Status.SUCCESS,
4644
reason=f"Successfully deleted {model.__name__} object with id {test_obj.id}",
4745
)

scim2_tester/resource_get.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def check_object_query(context: CheckContext, model: type[Resource]) -> CheckRes
4646
)
4747

4848
return CheckResult(
49-
context.conf,
5049
status=Status.SUCCESS,
5150
reason=f"Successfully queried {model.__name__} object with id {test_obj.id}",
5251
data=response,
@@ -75,14 +74,12 @@ def check_object_query_without_id(
7574
found = any(test_obj.id == resource.id for resource in response.resources)
7675
if not found:
7776
return CheckResult(
78-
context.conf,
7977
status=Status.ERROR,
8078
reason=f"Could not find {model.__name__} object with id {test_obj.id} in list response",
8179
data=response,
8280
)
8381

8482
return CheckResult(
85-
context.conf,
8683
status=Status.SUCCESS,
8784
reason=f"Successfully found {model.__name__} object with id {test_obj.id} in list response",
8885
data=response,

scim2_tester/resource_post.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def check_object_creation(context: CheckContext, model: type[Resource]) -> Check
2020
created_obj = context.resource_manager.create_and_register(model)
2121

2222
return CheckResult(
23-
context.conf,
2423
status=Status.SUCCESS,
2524
reason=f"Successfully created {model.__name__} object with id {created_obj.id}",
2625
data=created_obj,

scim2_tester/resource_put.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def check_object_replacement(
4444
)
4545

4646
return CheckResult(
47-
context.conf,
4847
status=Status.SUCCESS,
4948
reason=f"Successfully replaced {model.__name__} object with id {test_obj.id}",
5049
data=response,

scim2_tester/resource_types.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ def check_query_all_resource_types(context: CheckContext) -> CheckResult:
3939
)
4040
available = ", ".join([f"'{resource.name}'" for resource in response.resources])
4141
reason = f"Resource types available are: {available}"
42-
return CheckResult(
43-
context.conf, status=Status.SUCCESS, reason=reason, data=response.resources
44-
)
42+
return CheckResult(status=Status.SUCCESS, reason=reason, data=response.resources)
4543

4644

4745
@checker("discovery", "resource-types")
@@ -54,14 +52,10 @@ def check_query_resource_type_by_id(
5452
expected_status_codes=context.conf.expected_status_codes or [200],
5553
)
5654
if isinstance(response, Error):
57-
return CheckResult(
58-
context.conf, status=Status.ERROR, reason=response.detail, data=response
59-
)
55+
return CheckResult(status=Status.ERROR, reason=response.detail, data=response)
6056

6157
reason = f"Successfully accessed the /ResourceTypes/{resource_type.id} endpoint."
62-
return CheckResult(
63-
context.conf, status=Status.SUCCESS, reason=reason, data=response
64-
)
58+
return CheckResult(status=Status.SUCCESS, reason=reason, data=response)
6559

6660

6761
@checker("discovery", "resource-types")
@@ -76,22 +70,19 @@ def check_access_invalid_resource_type(context: CheckContext) -> CheckResult:
7670

7771
if not isinstance(response, Error):
7872
return CheckResult(
79-
context.conf,
8073
status=Status.ERROR,
8174
reason=f"/resource_types/{probably_invalid_id} invalid URL did not return an Error object",
8275
data=response,
8376
)
8477

8578
if response.status != 404:
8679
return CheckResult(
87-
context.conf,
8880
status=Status.ERROR,
8981
reason=f"/resource_types/{probably_invalid_id} invalid URL did return an object, but the status code is {response.status}",
9082
data=response,
9183
)
9284

9385
return CheckResult(
94-
context.conf,
9586
status=Status.SUCCESS,
9687
reason=f"/resource_types/{probably_invalid_id} invalid URL correctly returned a 404 error",
9788
data=response,

scim2_tester/schemas.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def check_query_all_schemas(context: CheckContext) -> CheckResult:
3939
)
4040
available = ", ".join([f"'{resource.name}'" for resource in response.resources])
4141
return CheckResult(
42-
context.conf,
4342
status=Status.SUCCESS,
4443
reason=f"Schemas available are: {available}",
4544
data=response.resources,
@@ -54,14 +53,10 @@ def check_query_schema_by_id(context: CheckContext, schema: Schema) -> CheckResu
5453
expected_status_codes=context.conf.expected_status_codes or [200],
5554
)
5655
if isinstance(response, Error):
57-
return CheckResult(
58-
context.conf, status=Status.ERROR, reason=response.detail, data=response
59-
)
56+
return CheckResult(status=Status.ERROR, reason=response.detail, data=response)
6057

6158
reason = f"Successfully accessed the /Schemas/{schema.id} endpoint."
62-
return CheckResult(
63-
context.conf, status=Status.SUCCESS, reason=reason, data=response
64-
)
59+
return CheckResult(status=Status.SUCCESS, reason=reason, data=response)
6560

6661

6762
@checker("discovery", "schemas")
@@ -76,22 +71,19 @@ def check_access_invalid_schema(context: CheckContext) -> CheckResult:
7671

7772
if not isinstance(response, Error):
7873
return CheckResult(
79-
context.conf,
8074
status=Status.ERROR,
8175
reason=f"/Schemas/{probably_invalid_id} invalid URL did not return an Error object",
8276
data=response,
8377
)
8478

8579
if response.status != 404:
8680
return CheckResult(
87-
context.conf,
8881
status=Status.ERROR,
8982
reason=f"/Schemas/{probably_invalid_id} invalid URL did return an Error object, but the status code is {response.status}",
9083
data=response,
9184
)
9285

9386
return CheckResult(
94-
context.conf,
9587
status=Status.SUCCESS,
9688
reason=f"/Schemas/{probably_invalid_id} invalid URL correctly returned a 404 error",
9789
data=response,

scim2_tester/service_provider_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ def check_service_provider_config_endpoint(
2020
ServiceProviderConfig,
2121
expected_status_codes=context.conf.expected_status_codes or [200],
2222
)
23-
return CheckResult(context.conf, status=Status.SUCCESS, data=response)
23+
return CheckResult(status=Status.SUCCESS, data=response)

0 commit comments

Comments
 (0)