|
9 | 9 | from scim2_tester.schemas import check_schemas_endpoint |
10 | 10 | from scim2_tester.service_provider_config import check_service_provider_config_endpoint |
11 | 11 | from scim2_tester.utils import CheckConfig |
| 12 | +from scim2_tester.utils import CheckContext |
12 | 13 | from scim2_tester.utils import CheckResult |
13 | 14 | from scim2_tester.utils import Status |
14 | 15 | from scim2_tester.utils import checker |
15 | 16 |
|
16 | 17 |
|
17 | 18 | @checker("misc") |
18 | | -def check_random_url(conf: CheckConfig) -> CheckResult: |
| 19 | +def check_random_url(context: CheckContext) -> CheckResult: |
19 | 20 | """Check that a request to a random URL returns a 404 Error object.""" |
20 | 21 | probably_invalid_url = f"/{str(uuid.uuid4())}" |
21 | | - response = conf.client.query(url=probably_invalid_url, raise_scim_errors=False) |
| 22 | + response = context.client.query(url=probably_invalid_url, raise_scim_errors=False) |
22 | 23 |
|
23 | 24 | if not isinstance(response, Error): |
24 | 25 | return CheckResult( |
25 | | - conf, |
| 26 | + context.conf, |
26 | 27 | status=Status.ERROR, |
27 | 28 | reason=f"{probably_invalid_url} did not return an Error object", |
28 | 29 | data=response, |
29 | 30 | ) |
30 | 31 |
|
31 | 32 | if response.status != 404: |
32 | 33 | return CheckResult( |
33 | | - conf, |
| 34 | + context.conf, |
34 | 35 | status=Status.ERROR, |
35 | 36 | reason=f"{probably_invalid_url} did return an object, but the status code is {response.status}", |
36 | 37 | data=response, |
37 | 38 | ) |
38 | 39 |
|
39 | 40 | return CheckResult( |
40 | | - conf, |
| 41 | + context.conf, |
41 | 42 | status=Status.SUCCESS, |
42 | 43 | reason=f"{probably_invalid_url} correctly returned a 404 error", |
43 | 44 | data=response, |
@@ -97,58 +98,58 @@ def check_server( |
97 | 98 | ) |
98 | 99 | """ |
99 | 100 | conf = CheckConfig( |
100 | | - client=client, |
101 | 101 | raise_exceptions=raise_exceptions, |
102 | 102 | include_tags=include_tags, |
103 | 103 | exclude_tags=exclude_tags, |
104 | 104 | resource_types=resource_types, |
105 | 105 | ) |
| 106 | + context = CheckContext(client, conf) |
106 | 107 | results = [] |
107 | 108 |
|
108 | 109 | # Get the initial basic objects |
109 | | - result_spc = check_service_provider_config_endpoint(conf) |
| 110 | + result_spc = check_service_provider_config_endpoint(client, conf) |
110 | 111 | results.append(result_spc) |
111 | | - if result_spc.status != Status.SKIPPED and not conf.client.service_provider_config: |
112 | | - conf.client.service_provider_config = result_spc.data |
| 112 | + if result_spc.status != Status.SKIPPED and not client.service_provider_config: |
| 113 | + client.service_provider_config = result_spc.data |
113 | 114 |
|
114 | | - results_resource_types = check_resource_types_endpoint(conf) |
| 115 | + results_resource_types = check_resource_types_endpoint(context) |
115 | 116 | results.extend(results_resource_types) |
116 | | - if not conf.client.resource_types: |
| 117 | + if not client.resource_types: |
117 | 118 | # Find first non-skipped result with data |
118 | 119 | for rt_result in results_resource_types: |
119 | 120 | if rt_result.status != Status.SKIPPED and rt_result.data: |
120 | | - conf.client.resource_types = rt_result.data |
| 121 | + client.resource_types = rt_result.data |
121 | 122 | break |
122 | 123 |
|
123 | | - results_schemas = check_schemas_endpoint(conf) |
| 124 | + results_schemas = check_schemas_endpoint(context) |
124 | 125 | results.extend(results_schemas) |
125 | | - if not conf.client.resource_models: |
| 126 | + if not client.resource_models: |
126 | 127 | # Find first non-skipped result with data |
127 | 128 | for schema_result in results_schemas: |
128 | 129 | if schema_result.status != Status.SKIPPED and schema_result.data: |
129 | | - conf.client.resource_models = conf.client.build_resource_models( |
130 | | - conf.client.resource_types or [], schema_result.data or [] |
| 130 | + client.resource_models = client.build_resource_models( |
| 131 | + client.resource_types or [], schema_result.data or [] |
131 | 132 | ) |
132 | 133 | break |
133 | 134 |
|
134 | 135 | if ( |
135 | | - not conf.client.service_provider_config |
136 | | - or not conf.client.resource_types |
137 | | - or not conf.client.resource_models |
| 136 | + not client.service_provider_config |
| 137 | + or not client.resource_types |
| 138 | + or not client.resource_models |
138 | 139 | ): |
139 | 140 | return results |
140 | 141 |
|
141 | 142 | # Miscelleaneous checks |
142 | | - result_random = check_random_url(conf) |
| 143 | + result_random = check_random_url(client, conf) |
143 | 144 | results.append(result_random) |
144 | 145 |
|
145 | 146 | # Resource checks |
146 | | - for resource_type in conf.client.resource_types or []: |
| 147 | + for resource_type in client.resource_types or []: |
147 | 148 | # Filter by resource type if specified |
148 | 149 | if conf.resource_types and resource_type.name not in conf.resource_types: |
149 | 150 | continue |
150 | 151 |
|
151 | | - resource_results = check_resource_type(conf, resource_type) |
| 152 | + resource_results = check_resource_type(context, resource_type) |
152 | 153 | # Add resource type to each result for better tracking |
153 | 154 | for result in resource_results: |
154 | 155 | result.resource_type = resource_type.name |
|
0 commit comments