Skip to content

Commit d7bb973

Browse files
committed
fix: use ComplexAttribute instead of MultiValuedComplexAttribute to generate data
1 parent d143ef1 commit d7bb973

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

doc/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Changelog
77
Fixed
88
^^^^^
99
- Error and critical check results directly raise an exception when ``raise_exceptions=True``.
10+
- Use ``ComplexAttribute`` instead of ``MultiValuedComplexAttribute`` to generate data.
1011

1112
[0.2.2] - 2025-08-13
1213
--------------------

scim2_tester/filling.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from scim2_models import ComplexAttribute
1212
from scim2_models import Extension
1313
from scim2_models import ExternalReference
14-
from scim2_models import MultiValuedComplexAttribute
1514
from scim2_models import Mutability
1615
from scim2_models import Reference
1716
from scim2_models import Resource
@@ -124,11 +123,8 @@ def generate_random_value(
124123
elif isclass(field_type) and issubclass(field_type, Enum):
125124
value = random.choice(list(field_type))
126125

127-
elif isclass(field_type) and issubclass(field_type, MultiValuedComplexAttribute):
128-
value = fill_mvca_with_random_values(context, field_type()) # type: ignore[arg-type]
129-
130126
elif isclass(field_type) and issubclass(field_type, ComplexAttribute):
131-
value = fill_with_random_values(context, field_type()) # type: ignore[arg-type]
127+
value = fill_complex_attribute_with_random_values(context, field_type()) # type: ignore[arg-type]
132128

133129
elif isclass(field_type) and issubclass(field_type, Extension):
134130
value = fill_with_random_values(context, field_type()) # type: ignore[arg-type]
@@ -178,22 +174,23 @@ def fill_with_random_values(
178174
return obj
179175

180176

181-
def fill_mvca_with_random_values(
177+
def fill_complex_attribute_with_random_values(
182178
context: "CheckContext",
183-
obj: MultiValuedComplexAttribute,
179+
obj: ComplexAttribute,
184180
) -> Resource[Any] | None:
185-
"""Fill a MultiValuedComplexAttribute with random values.
181+
"""Fill a ComplexAttribute with random values.
186182
187183
For SCIM reference fields, correctly sets the value field to match
188184
the ID extracted from the reference URL.
189185
"""
190186
fill_with_random_values(context, obj)
191-
ref_type = type(obj).get_field_root_type("ref")
192-
if (
193-
get_origin(ref_type) is Reference
194-
and get_args(ref_type)
195-
and get_args(ref_type)[0] not in (URIReference, ExternalReference, Any)
196-
and (ref := getattr(obj, "ref", None))
197-
):
198-
obj.value = ref.rsplit("/", 1)[-1]
187+
if "ref" in type(obj).model_fields and "value" in type(obj).model_fields:
188+
ref_type = type(obj).get_field_root_type("ref")
189+
if (
190+
get_origin(ref_type) is Reference
191+
and get_args(ref_type)
192+
and get_args(ref_type)[0] not in (URIReference, ExternalReference, Any)
193+
and (ref := getattr(obj, "ref", None))
194+
):
195+
obj.value = ref.rsplit("/", 1)[-1]
199196
return obj

tests/test_urn.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,21 @@ def test_iter_urns_resource():
5757
assert "emails.primary" in urns
5858
assert "emails.display" in urns
5959
assert "emails.value" in urns
60-
assert "emails.ref" in urns
6160
assert "phoneNumbers" in urns
6261
assert "phoneNumbers.type" in urns
6362
assert "phoneNumbers.primary" in urns
6463
assert "phoneNumbers.display" in urns
6564
assert "phoneNumbers.value" in urns
66-
assert "phoneNumbers.ref" in urns
6765
assert "ims" in urns
6866
assert "ims.type" in urns
6967
assert "ims.primary" in urns
7068
assert "ims.display" in urns
7169
assert "ims.value" in urns
72-
assert "ims.ref" in urns
7370
assert "photos" in urns
7471
assert "photos.type" in urns
7572
assert "photos.primary" in urns
7673
assert "photos.display" in urns
7774
assert "photos.value" in urns
78-
assert "photos.ref" in urns
7975
assert "addresses" in urns
8076
assert "addresses.type" in urns
8177
assert "addresses.primary" in urns

0 commit comments

Comments
 (0)