Skip to content

Commit 3d29aa7

Browse files
committed
refactor: don't require 'resource_manager' param for fill_with_random_values
1 parent 1e74322 commit 3d29aa7

5 files changed

Lines changed: 11 additions & 20 deletions

File tree

scim2_tester/checkers/resource_put.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ def object_replacement(
4141
in (Mutability.read_write, Mutability.write_only)
4242
]
4343

44-
modified_obj = fill_with_random_values(
45-
context, test_obj, context.resource_manager, mutable_fields
46-
)
44+
modified_obj = fill_with_random_values(context, test_obj, mutable_fields)
4745

4846
if modified_obj is None:
4947
raise ValueError(

scim2_tester/filling.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from scim2_tester.utils import CheckContext
2020

2121
if TYPE_CHECKING:
22-
from scim2_tester.utils import ResourceManager
22+
pass
2323

2424

2525
def model_from_ref_type(
@@ -47,7 +47,6 @@ def model_from_ref_type_(ref_type: type) -> Any:
4747
def generate_random_value(
4848
context: CheckContext,
4949
obj: Resource[Any],
50-
resource_manager: "ResourceManager",
5150
field_name: str,
5251
) -> Any:
5352
field_type = obj.get_field_root_type(field_name)
@@ -82,7 +81,7 @@ def generate_random_value(
8281
ref_type = get_args(field_type)[0]
8382
if ref_type not in (ExternalReference, URIReference):
8483
model = model_from_ref_type(context, ref_type, different_than=obj.__class__)
85-
ref_obj = resource_manager.create_and_register(model)
84+
ref_obj = context.resource_manager.create_and_register(model)
8685
value = ref_obj.meta.location
8786

8887
else:
@@ -92,10 +91,10 @@ def generate_random_value(
9291
value = random.choice(list(field_type))
9392

9493
elif isclass(field_type) and issubclass(field_type, ComplexAttribute):
95-
value = fill_with_random_values(context, field_type(), resource_manager)
94+
value = fill_with_random_values(context, field_type())
9695

9796
elif isclass(field_type) and issubclass(field_type, Extension):
98-
value = fill_with_random_values(context, field_type(), resource_manager)
97+
value = fill_with_random_values(context, field_type())
9998

10099
else:
101100
# Put emails so this will be accepted by EmailStr too
@@ -106,14 +105,12 @@ def generate_random_value(
106105
def fill_with_random_values(
107106
context: CheckContext,
108107
obj: Resource[Any],
109-
resource_manager: "ResourceManager",
110108
field_names: list[str] | None = None,
111109
) -> Resource[Any] | None:
112110
"""Fill an object with random values generated according the attribute types.
113111
114112
:param context: The check context containing the SCIM client and configuration
115113
:param obj: The Resource object to fill with random values
116-
:param resource_manager: Resource manager for automatic cleanup
117114
:param field_names: Optional list of field names to fill (defaults to all)
118115
:returns: The filled object or None if the object ends up empty
119116
"""
@@ -127,7 +124,7 @@ def fill_with_random_values(
127124
if field.default:
128125
continue
129126

130-
value = generate_random_value(context, obj, resource_manager, field_name)
127+
value = generate_random_value(context, obj, field_name)
131128

132129
is_multiple = obj.get_field_multiplicity(field_name)
133130
if is_multiple:

scim2_tester/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def create_and_register(self, model: type[Resource[Any]]) -> Resource[Any]:
166166
for field_name in model.model_fields
167167
if model.get_field_annotation(field_name, Required) == Required.true
168168
]
169-
obj = fill_with_random_values(self.context, model(), self, field_names)
169+
obj = fill_with_random_values(self.context, model(), field_names)
170170
created = self.context.client.create(obj)
171171

172172
# Handle the case where create might return Error or dict

tests/test_filling.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_generate_random_value_bytes_field():
3131

3232
cert = X509Certificate(value=base64.b64encode(b"placeholder"))
3333

34-
value = generate_random_value(context, cert, context.resource_manager, "value")
34+
value = generate_random_value(context, cert, "value")
3535

3636
assert isinstance(value, str)
3737
assert len(value) == 36 # UUID string length
@@ -61,7 +61,7 @@ def test_fill_with_empty_field_list():
6161
with patch(
6262
"scim2_tester.filling.generate_random_value", return_value="mock_value"
6363
) as mock_generate:
64-
result = fill_with_random_values(context, user, context.resource_manager, [])
64+
result = fill_with_random_values(context, user, [])
6565
mock_generate.assert_not_called()
6666

6767
assert result is user
@@ -78,9 +78,7 @@ def test_fill_with_nonexistent_field():
7878
with patch(
7979
"scim2_tester.filling.generate_random_value", return_value="mock_value"
8080
) as mock_generate:
81-
result = fill_with_random_values(
82-
context, user, context.resource_manager, ["nonexistent_field"]
83-
)
81+
result = fill_with_random_values(context, user, ["nonexistent_field"])
8482
mock_generate.assert_not_called()
8583

8684
assert result is user

tests/test_resource.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ class Type(str, Enum):
5858
def test_fill_with_random_values_generates_valid_data(testing_context):
5959
"""Test that fill_with_random_values populates all fields with valid data."""
6060
obj = CustomModel()
61-
obj = fill_with_random_values(
62-
testing_context, obj, testing_context.resource_manager
63-
)
61+
obj = fill_with_random_values(testing_context, obj)
6462

6563
assert obj is not None, (
6664
"fill_with_random_values should not return None for test object"

0 commit comments

Comments
 (0)