|
11 | 11 | from scim2_tester.filling import fill_with_random_values |
12 | 12 | from scim2_tester.filling import generate_random_value |
13 | 13 | from scim2_tester.filling import model_from_ref_type |
14 | | -from scim2_tester.utils import CheckConfig |
15 | | -from scim2_tester.utils import CheckContext |
16 | 14 |
|
17 | 15 |
|
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): |
28 | 17 | """Validates random value generation for bytes fields.""" |
29 | | - config = CheckConfig() |
30 | | - context = CheckContext(MockClient(), config) |
31 | | - |
32 | 18 | cert = X509Certificate(value=base64.b64encode(b"placeholder")) |
33 | 19 |
|
34 | | - value = generate_random_value(context, cert, "value") |
| 20 | + value = generate_random_value(testing_context, cert, "value") |
35 | 21 |
|
36 | 22 | assert isinstance(value, str) |
37 | 23 | assert len(value) == 36 # UUID string length |
38 | 24 |
|
39 | 25 |
|
40 | | -def test_model_resolution_from_reference_type(): |
| 26 | +def test_model_resolution_from_reference_type(testing_context): |
41 | 27 | """Ensures model resolution from reference type excludes specified models.""" |
42 | | - conf = CheckConfig() |
43 | | - context = CheckContext(MockClient(), conf) |
| 28 | + from scim2_models import EnterpriseUser |
44 | 29 |
|
45 | 30 | ref_type = Literal["User"] | Literal["Group"] |
46 | 31 | different_than = Group |
47 | 32 |
|
48 | | - result = model_from_ref_type(context, ref_type, different_than) |
| 33 | + result = model_from_ref_type(testing_context, ref_type, different_than) |
49 | 34 |
|
50 | | - assert result == User |
| 35 | + # The result should be User[EnterpriseUser] from the testing context |
| 36 | + assert result == User[EnterpriseUser] |
| 37 | + assert result != Group |
51 | 38 |
|
52 | 39 |
|
53 | | -def test_fill_with_empty_field_list(): |
| 40 | +def test_fill_with_empty_field_list(testing_context): |
54 | 41 | """Confirms no fields are modified when empty field list provided.""" |
55 | | - conf = CheckConfig() |
56 | | - context = CheckContext(MockClient(), conf) |
57 | | - |
58 | 42 | user = User(user_name="test") |
59 | 43 | original_user_name = user.user_name |
60 | 44 |
|
61 | 45 | with patch( |
62 | 46 | "scim2_tester.filling.generate_random_value", return_value="mock_value" |
63 | 47 | ) as mock_generate: |
64 | | - result = fill_with_random_values(context, user, []) |
| 48 | + result = fill_with_random_values(testing_context, user, []) |
65 | 49 | mock_generate.assert_not_called() |
66 | 50 |
|
67 | 51 | assert result is user |
68 | 52 | assert result.user_name == original_user_name |
69 | 53 |
|
70 | 54 |
|
71 | | -def test_fill_with_nonexistent_field(): |
| 55 | +def test_fill_with_nonexistent_field(testing_context): |
72 | 56 | """Verifies nonexistent fields are ignored during filling process.""" |
73 | | - conf = CheckConfig() |
74 | | - context = CheckContext(MockClient(), conf) |
75 | | - |
76 | 57 | user = User(user_name="test") |
77 | 58 |
|
78 | 59 | with patch( |
79 | 60 | "scim2_tester.filling.generate_random_value", return_value="mock_value" |
80 | 61 | ) as mock_generate: |
81 | | - result = fill_with_random_values(context, user, ["nonexistent_field"]) |
| 62 | + result = fill_with_random_values(testing_context, user, ["nonexistent_field"]) |
82 | 63 | mock_generate.assert_not_called() |
83 | 64 |
|
84 | 65 | assert result is user |
0 commit comments