Skip to content

Commit 1e74322

Browse files
committed
fix: do not rely on examples anymore to generate data
1 parent b5a6ad1 commit 1e74322

2 files changed

Lines changed: 7 additions & 33 deletions

File tree

scim2_tester/filling.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,12 @@ def generate_random_value(
5050
resource_manager: "ResourceManager",
5151
field_name: str,
5252
) -> Any:
53-
field = obj.__class__.model_fields[field_name]
5453
field_type = obj.get_field_root_type(field_name)
5554

5655
value: Any
5756
if obj.get_field_annotation(field_name, Mutability) == Mutability.read_only:
5857
value = None
5958

60-
elif field.examples:
61-
value = random.choice(field.examples)
62-
6359
# RFC7643 §4.1.2 provides the following indications, however
6460
# there is no way to guess the existence of such requirements
6561
# just by looking at the object schema.

tests/test_resource.py

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from unittest.mock import MagicMock
33
from unittest.mock import patch
44

5-
from pydantic import Field
65
from scim2_models import ComplexAttribute
76
from scim2_models import Context
87
from scim2_models import EnterpriseUser
@@ -19,8 +18,6 @@
1918
from scim2_tester.checkers.resource_get import object_query_without_id
2019
from scim2_tester.checkers.resource_put import object_replacement
2120
from scim2_tester.filling import fill_with_random_values
22-
from scim2_tester.utils import CheckConfig
23-
from scim2_tester.utils import CheckContext
2421
from scim2_tester.utils import Status
2522

2623

@@ -57,21 +54,13 @@ class Type(str, Enum):
5754
complex_unique: Complex | None = None
5855
complex_multiple: list[Complex] | None = None
5956

60-
example_unique: str | None = Field(None, examples=["foo", "bar"])
61-
example_multiple: list[str] | None = Field(None, examples=["foo", "bar"])
6257

63-
64-
def test_fill_with_random_values_generates_valid_data():
58+
def test_fill_with_random_values_generates_valid_data(testing_context):
6559
"""Test that fill_with_random_values populates all fields with valid data."""
66-
67-
class MockClient:
68-
pass
69-
70-
conf = CheckConfig()
71-
context = CheckContext(MockClient(), conf)
72-
7360
obj = CustomModel()
74-
obj = fill_with_random_values(context, obj, context.resource_manager)
61+
obj = fill_with_random_values(
62+
testing_context, obj, testing_context.resource_manager
63+
)
7564

7665
assert obj is not None, (
7766
"fill_with_random_values should not return None for test object"
@@ -83,9 +72,6 @@ class MockClient:
8372

8473
assert getattr(obj, field_name) is not None
8574

86-
assert obj.example_unique in ["foo", "bar"]
87-
assert all(val in ["foo", "bar"] for val in obj.example_multiple)
88-
8975

9076
def test_resource_type_tests_with_unknown_schema(testing_context):
9177
"""Test CRUD operations on a resource type with unknown schema."""
@@ -246,27 +232,19 @@ def test_object_deletion_successful(httpserver, testing_context):
246232
assert f"Successfully deleted User object with id {user_id}" in result[0].reason
247233

248234

249-
def test_object_replacement_fails_when_no_mutable_fields():
235+
def test_object_replacement_fails_when_no_mutable_fields(testing_context):
250236
"""Test object replacement failure when object cannot be modified."""
251-
252-
# Create a context with mock resource manager
253-
class MockClient:
254-
pass
255-
256-
conf = CheckConfig()
257-
context = CheckContext(MockClient(), conf)
258-
259237
# Mock resource manager to avoid HTTP calls
260238
mock_rm = MagicMock()
261239
mock_rm.create_and_register.return_value = User(id="test-id", user_name="test")
262-
context.resource_manager = mock_rm
240+
testing_context.resource_manager = mock_rm
263241

264242
with patch(
265243
"scim2_tester.checkers.resource_put.fill_with_random_values"
266244
) as mock_fill:
267245
mock_fill.return_value = None
268246

269-
result = object_replacement(context, User)
247+
result = object_replacement(testing_context, User)
270248

271249
# The @checker decorator catches ValueError and returns CheckResult with ERROR status
272250
assert result[0].status == Status.ERROR

0 commit comments

Comments
 (0)