Skip to content

Commit 471cdf7

Browse files
committed
chore: rename check_config in testing_context
1 parent a9a4e6a commit 471cdf7

7 files changed

Lines changed: 78 additions & 78 deletions

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ def scim_client(httpserver):
1717

1818

1919
@pytest.fixture
20-
def check_config(scim_client):
20+
def testing_context(scim_client):
2121
conf = CheckConfig()
2222
return CheckContext(scim_client, conf)

tests/test_discovery.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from scim2_tester.utils import Status
77

88

9-
def test_discovery_endpoint_methods_return_405(httpserver, check_config):
9+
def test_discovery_endpoint_methods_return_405(httpserver, testing_context):
1010
"""Test that discovery endpoints return 405 for unsupported HTTP methods."""
1111
endpoint = "/ServiceProviderConfig"
1212

@@ -16,7 +16,7 @@ def test_discovery_endpoint_methods_return_405(httpserver, check_config):
1616
"", status=405
1717
)
1818

19-
results = _test_discovery_endpoint_methods(check_config, endpoint)
19+
results = _test_discovery_endpoint_methods(testing_context, endpoint)
2020

2121
assert len(results) == 4
2222
assert all(result.status == Status.SUCCESS for result in results)
@@ -27,7 +27,7 @@ def test_discovery_endpoint_methods_return_405(httpserver, check_config):
2727
)
2828

2929

30-
def test_discovery_endpoint_methods_wrong_status_codes(httpserver, check_config):
30+
def test_discovery_endpoint_methods_wrong_status_codes(httpserver, testing_context):
3131
"""Test that non-405 responses are reported as errors."""
3232
endpoint = "/ResourceTypes"
3333

@@ -48,7 +48,7 @@ def test_discovery_endpoint_methods_wrong_status_codes(httpserver, check_config)
4848
"", status=405
4949
) # This one should succeed
5050

51-
results = _test_discovery_endpoint_methods(check_config, endpoint)
51+
results = _test_discovery_endpoint_methods(testing_context, endpoint)
5252

5353
assert len(results) == 4
5454
assert results[0].status == Status.ERROR
@@ -65,23 +65,23 @@ def test_discovery_endpoint_methods_wrong_status_codes(httpserver, check_config)
6565
assert all(result.data is not None for result in results)
6666

6767

68-
def test_discovery_endpoint_methods_connection_error(check_config):
68+
def test_discovery_endpoint_methods_connection_error(testing_context):
6969
"""Test handling of connection errors during HTTP method testing."""
7070
# Mock the client to raise SCIMClientError
71-
original_request = check_config.client.client.request
71+
original_request = testing_context.client.client.request
7272

7373
def mock_request(*args, **kwargs):
7474
raise SCIMClientError("Connection failed")
7575

76-
check_config.client.client.request = mock_request
76+
testing_context.client.client.request = mock_request
7777

7878
try:
79-
results = _test_discovery_endpoint_methods(check_config, "/TestEndpoint")
79+
results = _test_discovery_endpoint_methods(testing_context, "/TestEndpoint")
8080

8181
assert len(results) == 4
8282
assert all(result.status == Status.ERROR for result in results)
8383
for result in results:
8484
assert "failed: Connection failed" in result.reason
8585
finally:
8686
# Restore original method
87-
check_config.client.client.request = original_request
87+
testing_context.client.client.request = original_request

tests/test_random_url.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
from scim2_tester.utils import Status
88

99

10-
def test_random_url(httpserver, check_config):
10+
def test_random_url(httpserver, testing_context):
1111
"""Test reaching a random URL that returns a SCIM 404 error."""
1212
httpserver.expect_request(re.compile(r".*")).respond_with_json(
1313
Error(status=404, detail="Endpoint Not Found").model_dump(),
1414
status=404,
1515
content_type="application/scim+json",
1616
)
1717

18-
result = random_url(check_config)
18+
result = random_url(testing_context)
1919

2020
assert result.status == Status.SUCCESS
2121
assert "correctly returned a 404 error" in result.reason
2222

2323

24-
def test_random_url_valid_object(httpserver, check_config):
24+
def test_random_url_valid_object(httpserver, testing_context):
2525
"""Test reaching a random URL that returns a SCIM object."""
2626
httpserver.expect_request(re.compile(r".*")).respond_with_json(
2727
User(
@@ -31,21 +31,21 @@ def test_random_url_valid_object(httpserver, check_config):
3131
content_type="application/scim+json",
3232
)
3333

34-
result = random_url(check_config)
34+
result = random_url(testing_context)
3535

3636
assert result.status == Status.ERROR
3737
assert "did not return an Error object" in result.reason
3838

3939

40-
def test_random_url_not_404(httpserver, check_config):
40+
def test_random_url_not_404(httpserver, testing_context):
4141
"""Test reaching a random URL that returns a non-404 status code."""
4242
httpserver.expect_request(re.compile(r".*")).respond_with_json(
4343
Error(status=200, detail="Endpoint Not Found").model_dump(),
4444
status=200,
4545
content_type="application/scim+json",
4646
)
4747

48-
result = random_url(check_config)
48+
result = random_url(testing_context)
4949

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

tests/test_resource.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class MockClient:
8585
assert all(val in ["foo", "bar"] for val in obj.example_multiple)
8686

8787

88-
def test_resource_type_tests_with_unknown_schema(check_config):
88+
def test_resource_type_tests_with_unknown_schema(testing_context):
8989
"""Test CRUD operations on a resource type with unknown schema."""
9090
resource_type = ResourceType(
9191
id="urn:test:UnknownResource",
@@ -94,7 +94,7 @@ def test_resource_type_tests_with_unknown_schema(check_config):
9494
schema_="urn:ietf:params:scim:schemas:core:2.0:UnknownResource",
9595
)
9696

97-
results = resource_type_tests(check_config, resource_type)
97+
results = resource_type_tests(testing_context, resource_type)
9898

9999
assert len(results) == 1
100100
assert results[0].status == Status.ERROR
@@ -103,7 +103,7 @@ def test_resource_type_tests_with_unknown_schema(check_config):
103103
)
104104

105105

106-
def test_model_resolution_from_resource_type(check_config):
106+
def test_model_resolution_from_resource_type(testing_context):
107107
"""Test model resolution from ResourceType schema."""
108108
unknown_resource_type = ResourceType(
109109
id="urn:test:UnknownResource",
@@ -112,7 +112,7 @@ def test_model_resolution_from_resource_type(check_config):
112112
schema_="urn:ietf:params:scim:schemas:core:2.0:UnknownResource",
113113
)
114114

115-
model = _model_from_resource_type(check_config, unknown_resource_type)
115+
model = _model_from_resource_type(testing_context, unknown_resource_type)
116116
assert model is None
117117

118118
# Test when model matches the schema
@@ -123,12 +123,12 @@ def test_model_resolution_from_resource_type(check_config):
123123
schema_="urn:ietf:params:scim:schemas:core:2.0:User",
124124
)
125125

126-
model = _model_from_resource_type(check_config, user_resource_type)
126+
model = _model_from_resource_type(testing_context, user_resource_type)
127127
assert model == User
128128

129129

130130
def test_object_query_without_id_when_object_missing_from_list(
131-
httpserver, check_config
131+
httpserver, testing_context
132132
):
133133
"""Test querying objects when the created object is missing from the list response."""
134134
# Mock user creation first (it happens before the query)
@@ -148,15 +148,15 @@ def test_object_query_without_id_when_object_missing_from_list(
148148
content_type="application/scim+json",
149149
)
150150

151-
result = object_query_without_id(check_config, User)
151+
result = object_query_without_id(testing_context, User)
152152

153153
assert result.status == Status.ERROR
154154
assert (
155155
"Could not find User object with id test-id in list response" in result.reason
156156
)
157157

158158

159-
def test_object_deletion_with_null_id(check_config):
159+
def test_object_deletion_with_null_id(testing_context):
160160
"""Test deletion of objects without an ID."""
161161

162162
class MockResourceManager:
@@ -172,18 +172,18 @@ def create_and_register(self, model):
172172
def cleanup(self):
173173
pass
174174

175-
original_rm = check_config.resource_manager
176-
check_config.resource_manager = MockResourceManager()
175+
original_rm = testing_context.resource_manager
176+
testing_context.resource_manager = MockResourceManager()
177177

178178
try:
179-
result = object_deletion(check_config, User)
179+
result = object_deletion(testing_context, User)
180180
assert result.status == Status.SUCCESS
181181
assert "Successfully deleted User object with id None" in result.reason
182182
finally:
183-
check_config.resource_manager = original_rm
183+
testing_context.resource_manager = original_rm
184184

185185

186-
def test_object_deletion_when_object_persists(httpserver, check_config):
186+
def test_object_deletion_when_object_persists(httpserver, testing_context):
187187
"""Test deletion failure when object persists after DELETE request."""
188188
user_id = "test-user-123"
189189
test_user = User(id=user_id, user_name="testuser")
@@ -207,13 +207,13 @@ def test_object_deletion_when_object_persists(httpserver, check_config):
207207
content_type="application/scim+json",
208208
)
209209

210-
result = object_deletion(check_config, User)
210+
result = object_deletion(testing_context, User)
211211

212212
assert result.status == Status.ERROR
213213
assert f"User object with id {user_id} still exists after deletion" in result.reason
214214

215215

216-
def test_object_deletion_successful(httpserver, check_config):
216+
def test_object_deletion_successful(httpserver, testing_context):
217217
"""Test successful object deletion when object is properly removed."""
218218
user_id = "test-user-456"
219219
test_user = User(id=user_id, user_name="testuser")
@@ -235,7 +235,7 @@ def test_object_deletion_successful(httpserver, check_config):
235235
"Not Found", status=404
236236
)
237237

238-
result = object_deletion(check_config, User)
238+
result = object_deletion(testing_context, User)
239239

240240
assert result.status == Status.SUCCESS
241241
assert f"Successfully deleted User object with id {user_id}" in result.reason

tests/test_resource_types.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
from scim2_tester.utils import Status
1414

1515

16-
def test_resource_types_endpoint(httpserver, check_config):
16+
def test_resource_types_endpoint(httpserver, testing_context):
1717
"""Test a fully functional resource types endpoint."""
1818
httpserver.expect_request(re.compile(r"^/ResourceTypes$")).respond_with_json(
1919
ListResponse[ResourceType](
20-
resources=check_config.client.resource_types,
21-
total_results=len(check_config.client.resource_types),
20+
resources=testing_context.client.resource_types,
21+
total_results=len(testing_context.client.resource_types),
2222
).model_dump(scim_ctx=Context.RESOURCE_QUERY_RESPONSE),
2323
status=200,
2424
content_type="application/scim+json",
2525
)
26-
for resource_type in check_config.client.resource_types:
26+
for resource_type in testing_context.client.resource_types:
2727
httpserver.expect_request(
2828
re.compile(rf"^/ResourceTypes/{resource_type.id}$")
2929
).respond_with_json(
@@ -49,35 +49,35 @@ def test_resource_types_endpoint(httpserver, check_config):
4949
content_type="application/scim+json",
5050
)
5151

52-
results = _resource_types_endpoint(check_config)
52+
results = _resource_types_endpoint(testing_context)
5353

5454
assert all(result.status == Status.SUCCESS for result in results)
5555

5656

57-
def test_resource_missing_query_endpoint(httpserver, check_config):
57+
def test_resource_missing_query_endpoint(httpserver, testing_context):
5858
"""Test that individual ResourceType endpoints are missing."""
5959
httpserver.expect_request(re.compile(r"^/ResourceTypes$")).respond_with_json(
6060
ListResponse[ResourceType](
61-
resources=check_config.client.resource_types,
62-
total_results=len(check_config.client.resource_types),
61+
resources=testing_context.client.resource_types,
62+
total_results=len(testing_context.client.resource_types),
6363
).model_dump(scim_ctx=Context.RESOURCE_QUERY_RESPONSE),
6464
status=200,
6565
content_type="application/scim+json",
6666
)
67-
results = _resource_types_endpoint(check_config)
67+
results = _resource_types_endpoint(testing_context)
6868

6969
assert all(result.status == Status.ERROR for result in results[1:])
7070

7171

72-
def test_resource_types_endpoint_methods(httpserver, check_config):
72+
def test_resource_types_endpoint_methods(httpserver, testing_context):
7373
"""Test that resource types endpoint returns proper errors for unsupported HTTP methods."""
7474
# Mock all HTTP methods to return 405
7575
for method in ["POST", "PUT", "PATCH", "DELETE"]:
7676
httpserver.expect_request(
7777
uri="/ResourceTypes", method=method
7878
).respond_with_data("", status=405)
7979

80-
results = resource_types_endpoint_methods(check_config)
80+
results = resource_types_endpoint_methods(testing_context)
8181

8282
assert len(results) == 4
8383
assert all(result.status == Status.SUCCESS for result in results)
@@ -88,7 +88,7 @@ def test_resource_types_endpoint_methods(httpserver, check_config):
8888
)
8989

9090

91-
def test_query_resource_type_by_id_client_returns_error(httpserver, check_config):
91+
def test_query_resource_type_by_id_client_returns_error(httpserver, testing_context):
9292
"""Test query_resource_type_by_id when server returns HTTP error."""
9393
resource_type = ResourceType(
9494
id="test-id", name="Test", endpoint="/Test", schema_="urn:test"
@@ -102,21 +102,21 @@ def test_query_resource_type_by_id_client_returns_error(httpserver, check_config
102102
content_type="application/scim+json",
103103
)
104104

105-
result = query_resource_type_by_id(check_config, resource_type)
105+
result = query_resource_type_by_id(testing_context, resource_type)
106106
assert result.status == Status.ERROR
107107
assert "Resource Type not found" in result.reason
108108

109109

110-
def test_access_resource_type_by_id_success(httpserver, check_config):
110+
def test_access_resource_type_by_id_success(httpserver, testing_context):
111111
"""Test successfully accessing a resource type by ID."""
112-
resource_type = check_config.client.resource_types[0]
112+
resource_type = testing_context.client.resource_types[0]
113113
httpserver.expect_request(f"/ResourceTypes/{resource_type.id}").respond_with_json(
114114
resource_type.model_dump(scim_ctx=Context.RESOURCE_QUERY_RESPONSE),
115115
status=200,
116116
content_type="application/scim+json",
117117
)
118118

119-
result = query_resource_type_by_id(check_config, resource_type)
119+
result = query_resource_type_by_id(testing_context, resource_type)
120120
assert result.status == Status.SUCCESS
121121
assert (
122122
f"Successfully accessed the /ResourceTypes/{resource_type.id} endpoint."
@@ -125,7 +125,7 @@ def test_access_resource_type_by_id_success(httpserver, check_config):
125125
assert result.data == resource_type
126126

127127

128-
def test_access_invalid_resource_type_non_error_response(httpserver, check_config):
128+
def test_access_invalid_resource_type_non_error_response(httpserver, testing_context):
129129
"""Test accessing an invalid resource type that returns a non-Error object."""
130130
mock_resource_type = ResourceType(
131131
id="invalid-resource-type",
@@ -142,14 +142,14 @@ def test_access_invalid_resource_type_non_error_response(httpserver, check_confi
142142
content_type="application/scim+json",
143143
)
144144

145-
result = access_invalid_resource_type(check_config)
145+
result = access_invalid_resource_type(testing_context)
146146

147147
assert result.status == Status.ERROR
148148
assert "invalid URL did not return an Error object" in result.reason
149149
assert result.data == mock_resource_type
150150

151151

152-
def test_access_invalid_resource_type_wrong_status_code(httpserver, check_config):
152+
def test_access_invalid_resource_type_wrong_status_code(httpserver, testing_context):
153153
"""Test accessing an invalid resource type that returns wrong status code."""
154154
error = Error(status=400, detail="Bad Request")
155155

@@ -161,7 +161,7 @@ def test_access_invalid_resource_type_wrong_status_code(httpserver, check_config
161161
content_type="application/scim+json",
162162
)
163163

164-
result = access_invalid_resource_type(check_config)
164+
result = access_invalid_resource_type(testing_context)
165165

166166
assert result.status == Status.ERROR
167167
assert "did return an object, but the status code is 400" in result.reason

0 commit comments

Comments
 (0)