Skip to content

Commit aa48bcd

Browse files
committed
feat: fill_with_random_values can handle fields with examples
1 parent d31ef0d commit aa48bcd

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

scim2_tester/resource.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def fill_with_random_values(obj: Resource) -> Resource:
4848
if field_type is Meta:
4949
value = None
5050

51+
elif field.examples:
52+
value = random.choice(field.examples)
53+
5154
elif field_type is int:
5255
value = uuid.uuid4().int
5356

tests/test_resource.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from enum import Enum
22

3+
from pydantic import Field
34
from scim2_models import ComplexAttribute
45
from scim2_models import Reference
56
from scim2_models import Resource
@@ -40,6 +41,9 @@ class Type(str, Enum):
4041
complex_unique: Complex | None = None
4142
complex_multiple: list[Complex] | None = None
4243

44+
example_unique: str | None = Field(None, examples=["foo", "bar"])
45+
example_multiple: list[str] | None = Field(None, examples=["foo", "bar"])
46+
4347

4448
def test_random_values():
4549
"""Check that 'fill_with_random_values' produce valid objects."""
@@ -50,3 +54,6 @@ def test_random_values():
5054
continue
5155

5256
assert getattr(obj, field_name) is not None
57+
58+
assert obj.example_unique in ["foo", "bar"]
59+
assert all(val in ["foo", "bar"] for val in obj.example_multiple)

0 commit comments

Comments
 (0)