Skip to content

Commit 8efd08c

Browse files
committed
refactor: introduce a CheckContext class
1 parent 5cd6f4b commit 8efd08c

7 files changed

Lines changed: 37 additions & 40 deletions

File tree

scim2_tester/checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def check_server(
107107
results = []
108108

109109
# Get the initial basic objects
110-
result_spc = check_service_provider_config_endpoint(client, conf)
110+
result_spc = check_service_provider_config_endpoint(context)
111111
results.append(result_spc)
112112
if result_spc.status != Status.SKIPPED and not client.service_provider_config:
113113
client.service_provider_config = result_spc.data
@@ -140,7 +140,7 @@ def check_server(
140140
return results
141141

142142
# Miscelleaneous checks
143-
result_random = check_random_url(client, conf)
143+
result_random = check_random_url(context)
144144
results.append(result_random)
145145

146146
# Resource checks

scim2_tester/resource.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def check_resource_type(
3737
# These functions have @checker decorators so we call them with client, conf
3838
# The decorator will create a context and call the function appropriately
3939
# For now, call them directly - may need adjustment based on actual function signatures
40-
results.append(check_object_creation(context.client, context.conf, model))
41-
results.append(check_object_query(context.client, context.conf, model))
42-
results.append(check_object_query_without_id(context.client, context.conf, model))
43-
results.append(check_object_replacement(context.client, context.conf, model))
44-
results.append(check_object_deletion(context.client, context.conf, model))
40+
results.append(check_object_creation(context, model))
41+
results.append(check_object_query(context, model))
42+
results.append(check_object_query_without_id(context, model))
43+
results.append(check_object_replacement(context, model))
44+
results.append(check_object_deletion(context, model))
4545

4646
return results

scim2_tester/resource_types.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@ def check_resource_types_endpoint(context: CheckContext) -> list[CheckResult]:
2020
- Check that a 403 response is returned if a filter is passed
2121
- Check that the `schema` attribute exists and is available.
2222
"""
23-
resource_types_result = check_query_all_resource_types(context.client, context.conf)
23+
resource_types_result = check_query_all_resource_types(context)
2424
results = [resource_types_result]
2525

2626
if resource_types_result.status == Status.SUCCESS:
2727
for resource_type in resource_types_result.data:
28-
results.append(
29-
check_query_resource_type_by_id(
30-
context.client, context.conf, resource_type
31-
)
32-
)
28+
results.append(check_query_resource_type_by_id(context, resource_type))
3329

34-
results.append(check_access_invalid_resource_type(context.client, context.conf))
30+
results.append(check_access_invalid_resource_type(context))
3531

3632
return results
3733

scim2_tester/schemas.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ def check_schemas_endpoint(context: CheckContext) -> list[CheckResult]:
2020
- Check that a 403 response is returned if a filter is passed
2121
- Check that the 'ResourceType', 'ServiceProviderConfig' and 'Schema' schemas are provided.
2222
"""
23-
schemas_result = check_query_all_schemas(context.client, context.conf)
23+
schemas_result = check_query_all_schemas(context)
2424
results = [schemas_result]
2525

2626
if schemas_result.status == Status.SUCCESS:
2727
for resource_type in schemas_result.data:
28-
results.append(
29-
check_query_schema_by_id(context.client, context.conf, resource_type)
30-
)
28+
results.append(check_query_schema_by_id(context, resource_type))
3129

32-
results.append(check_access_invalid_schema(context.client, context.conf))
30+
results.append(check_access_invalid_schema(context))
3331

3432
return results
3533

scim2_tester/utils.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,54 +200,52 @@ def check_schemas_endpoint(...):
200200

201201
def decorator(func):
202202
@functools.wraps(func)
203-
def wrapped(client: SCIMClient, conf: CheckConfig, *args, **kwargs):
203+
def wrapped(context: CheckContext, *args, **kwargs):
204204
func_tags = set(tags) if tags else set()
205205

206206
# Check if function should be skipped based on tag filtering
207-
if conf.include_tags and not _matches_hierarchical_tags(
208-
func_tags, conf.include_tags
207+
if context.conf.include_tags and not _matches_hierarchical_tags(
208+
func_tags, context.conf.include_tags
209209
):
210210
return CheckResult(
211-
conf,
211+
context.conf,
212212
status=Status.SKIPPED,
213213
title=func.__name__,
214214
description=func.__doc__,
215215
tags=func_tags,
216216
reason="Skipped due to tag filtering",
217217
)
218218

219-
if conf.exclude_tags and _matches_hierarchical_tags(
220-
func_tags, conf.exclude_tags
219+
if context.conf.exclude_tags and _matches_hierarchical_tags(
220+
func_tags, context.conf.exclude_tags
221221
):
222222
return CheckResult(
223-
conf,
223+
context.conf,
224224
status=Status.SKIPPED,
225225
title=func.__name__,
226226
description=func.__doc__,
227227
tags=func_tags,
228228
reason="Skipped due to tag exclusion",
229229
)
230230

231-
context = CheckContext(client, conf)
232-
233231
try:
234232
result = func(context, *args, **kwargs)
235233

236234
except SCIMClientError as exc:
237-
if conf.raise_exceptions:
235+
if context.conf.raise_exceptions:
238236
raise
239237

240238
reason = f"{exc} {exc.__cause__}" if exc.__cause__ else str(exc)
241239
result = CheckResult(
242-
conf, status=Status.ERROR, reason=reason, data=exc.source
240+
context.conf, status=Status.ERROR, reason=reason, data=exc.source
243241
)
244242

245243
except Exception as exc:
246-
if conf.raise_exceptions:
244+
if context.conf.raise_exceptions:
247245
raise
248246

249247
result = CheckResult(
250-
conf, status=Status.ERROR, reason=str(exc), data=exc
248+
context.conf, status=Status.ERROR, reason=str(exc), data=exc
251249
)
252250

253251
finally:

tests/test_random_url.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_random_url(httpserver, check_config):
1515
content_type="application/scim+json",
1616
)
1717

18-
result = check_random_url(check_config.client, check_config.conf)
18+
result = check_random_url(check_config)
1919

2020
assert result.status == Status.SUCCESS
2121
assert "correctly returned a 404 error" in result.reason
@@ -31,7 +31,7 @@ def test_random_url_valid_object(httpserver, check_config):
3131
content_type="application/scim+json",
3232
)
3333

34-
result = check_random_url(check_config.client, check_config.conf)
34+
result = check_random_url(check_config)
3535

3636
assert result.status == Status.ERROR
3737
assert "did not return an Error object" in result.reason
@@ -45,7 +45,7 @@ def test_random_url_not_404(httpserver, check_config):
4545
content_type="application/scim+json",
4646
)
4747

48-
result = check_random_url(check_config.client, check_config.conf)
48+
result = check_random_url(check_config)
4949

5050
assert result.status == Status.ERROR
5151
assert "did return an object, but the status code is 200" in result.reason

tests/test_utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def check_function(context: CheckContext) -> CheckResult:
2222

2323
# Test that result gets tags
2424
conf = CheckConfig(raise_exceptions=False)
25-
result = check_function(None, conf)
25+
context = CheckContext(client=None, conf=conf)
26+
result = check_function(context)
2627
assert result.tags == {"tag1", "tag2"}
2728
assert result.title == "check_function"
2829
assert result.description == "Test check function."
@@ -42,7 +43,8 @@ def check_function(context: CheckContext) -> CheckResult:
4243

4344
# Test that result gets empty tags
4445
conf = CheckConfig(raise_exceptions=False)
45-
result = check_function(None, conf)
46+
context = CheckContext(client=None, conf=conf)
47+
result = check_function(context)
4648
assert result.tags == set()
4749

4850

@@ -58,7 +60,8 @@ def check_function(context: CheckContext) -> list[CheckResult]:
5860
]
5961

6062
conf = CheckConfig(raise_exceptions=False)
61-
results = check_function(None, conf)
63+
context = CheckContext(client=None, conf=conf)
64+
results = check_function(context)
6265

6366
# All results should have tags
6467
assert all(r.tags == {"tag1"} for r in results)
@@ -141,10 +144,12 @@ def test_func(context):
141144

142145
# Test include tags matching
143146
conf_include = CheckConfig(include_tags={"crud"})
144-
result = test_func(None, conf_include) # Call with decorator signature
147+
context_include = CheckContext(client=None, conf=conf_include)
148+
result = test_func(context_include) # Call with decorator signature
145149
assert result.status.name == "SUCCESS"
146150

147151
# Test exclude tags matching
148152
conf_exclude = CheckConfig(exclude_tags={"crud"})
149-
result = test_func(None, conf_exclude) # Call with decorator signature
153+
context_exclude = CheckContext(client=None, conf=conf_exclude)
154+
result = test_func(context_exclude) # Call with decorator signature
150155
assert result.status.name == "SKIPPED"

0 commit comments

Comments
 (0)