|
11 | 11 | from scim2_models import ComplexAttribute |
12 | 12 | from scim2_models import Extension |
13 | 13 | from scim2_models import ExternalReference |
14 | | -from scim2_models import MultiValuedComplexAttribute |
15 | 14 | from scim2_models import Mutability |
16 | 15 | from scim2_models import Reference |
17 | 16 | from scim2_models import Resource |
@@ -124,11 +123,8 @@ def generate_random_value( |
124 | 123 | elif isclass(field_type) and issubclass(field_type, Enum): |
125 | 124 | value = random.choice(list(field_type)) |
126 | 125 |
|
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 | | - |
130 | 126 | 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] |
132 | 128 |
|
133 | 129 | elif isclass(field_type) and issubclass(field_type, Extension): |
134 | 130 | value = fill_with_random_values(context, field_type()) # type: ignore[arg-type] |
@@ -178,22 +174,23 @@ def fill_with_random_values( |
178 | 174 | return obj |
179 | 175 |
|
180 | 176 |
|
181 | | -def fill_mvca_with_random_values( |
| 177 | +def fill_complex_attribute_with_random_values( |
182 | 178 | context: "CheckContext", |
183 | | - obj: MultiValuedComplexAttribute, |
| 179 | + obj: ComplexAttribute, |
184 | 180 | ) -> Resource[Any] | None: |
185 | | - """Fill a MultiValuedComplexAttribute with random values. |
| 181 | + """Fill a ComplexAttribute with random values. |
186 | 182 |
|
187 | 183 | For SCIM reference fields, correctly sets the value field to match |
188 | 184 | the ID extracted from the reference URL. |
189 | 185 | """ |
190 | 186 | 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] |
199 | 196 | return obj |
0 commit comments