Skip to content

Commit 75ed1b4

Browse files
committed
refactor: test_filling.py uses the testing_context fixture
1 parent 3d29aa7 commit 75ed1b4

1 file changed

Lines changed: 12 additions & 31 deletions

File tree

tests/test_filling.py

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,74 +11,55 @@
1111
from scim2_tester.filling import fill_with_random_values
1212
from scim2_tester.filling import generate_random_value
1313
from scim2_tester.filling import model_from_ref_type
14-
from scim2_tester.utils import CheckConfig
15-
from scim2_tester.utils import CheckContext
1614

1715

18-
class MockClient:
19-
def __init__(self):
20-
self.resource_models = [User, Group]
21-
22-
def get_resource_model(self, model_name):
23-
model_map = {"User": User, "Group": Group}
24-
return model_map.get(model_name)
25-
26-
27-
def test_generate_random_value_bytes_field():
16+
def test_generate_random_value_bytes_field(testing_context):
2817
"""Validates random value generation for bytes fields."""
29-
config = CheckConfig()
30-
context = CheckContext(MockClient(), config)
31-
3218
cert = X509Certificate(value=base64.b64encode(b"placeholder"))
3319

34-
value = generate_random_value(context, cert, "value")
20+
value = generate_random_value(testing_context, cert, "value")
3521

3622
assert isinstance(value, str)
3723
assert len(value) == 36 # UUID string length
3824

3925

40-
def test_model_resolution_from_reference_type():
26+
def test_model_resolution_from_reference_type(testing_context):
4127
"""Ensures model resolution from reference type excludes specified models."""
42-
conf = CheckConfig()
43-
context = CheckContext(MockClient(), conf)
28+
from scim2_models import EnterpriseUser
4429

4530
ref_type = Literal["User"] | Literal["Group"]
4631
different_than = Group
4732

48-
result = model_from_ref_type(context, ref_type, different_than)
33+
result = model_from_ref_type(testing_context, ref_type, different_than)
4934

50-
assert result == User
35+
# The result should be User[EnterpriseUser] from the testing context
36+
assert result == User[EnterpriseUser]
37+
assert result != Group
5138

5239

53-
def test_fill_with_empty_field_list():
40+
def test_fill_with_empty_field_list(testing_context):
5441
"""Confirms no fields are modified when empty field list provided."""
55-
conf = CheckConfig()
56-
context = CheckContext(MockClient(), conf)
57-
5842
user = User(user_name="test")
5943
original_user_name = user.user_name
6044

6145
with patch(
6246
"scim2_tester.filling.generate_random_value", return_value="mock_value"
6347
) as mock_generate:
64-
result = fill_with_random_values(context, user, [])
48+
result = fill_with_random_values(testing_context, user, [])
6549
mock_generate.assert_not_called()
6650

6751
assert result is user
6852
assert result.user_name == original_user_name
6953

7054

71-
def test_fill_with_nonexistent_field():
55+
def test_fill_with_nonexistent_field(testing_context):
7256
"""Verifies nonexistent fields are ignored during filling process."""
73-
conf = CheckConfig()
74-
context = CheckContext(MockClient(), conf)
75-
7657
user = User(user_name="test")
7758

7859
with patch(
7960
"scim2_tester.filling.generate_random_value", return_value="mock_value"
8061
) as mock_generate:
81-
result = fill_with_random_values(context, user, ["nonexistent_field"])
62+
result = fill_with_random_values(testing_context, user, ["nonexistent_field"])
8263
mock_generate.assert_not_called()
8364

8465
assert result is user

0 commit comments

Comments
 (0)