1+ import base64
12import random
23import uuid
34from enum import Enum
45from inspect import isclass
6+ from typing import Annotated
57from typing import Any
68from typing import get_args
79from typing import get_origin
810
9- from pydantic import EmailStr
1011from scim2_models import ComplexAttribute
1112from scim2_models import Extension
1213from scim2_models import ExternalReference
1314from scim2_models import Meta
1415from scim2_models import Reference
16+ from scim2_models import Required
1517from scim2_models import Resource
1618from scim2_models import ResourceType
1719from scim2_models import URIReference
@@ -37,8 +39,10 @@ def fill_with_random_values(obj: Resource) -> Resource:
3739 if field .default :
3840 continue
3941
40- field_type = obj .get_field_root_type (field_name )
4142 is_multiple = obj .get_field_multiplicity (field_name )
43+ field_type = obj .get_field_root_type (field_name )
44+ if get_origin (field_type ) == Annotated :
45+ field_type = get_args (field_type )[0 ]
4246
4347 value : Any
4448 if field_type is Meta :
@@ -50,6 +54,9 @@ def fill_with_random_values(obj: Resource) -> Resource:
5054 elif field_type is bool :
5155 value = random .choice ([True , False ])
5256
57+ elif field_type is bytes :
58+ value = base64 .b64encode (str (uuid .uuid4 ()).encode ("utf-8" ))
59+
5360 elif get_origin (field_type ) is Reference :
5461 if get_args (field_type )[0 ] not in (
5562 ExternalReference ,
@@ -64,10 +71,6 @@ def fill_with_random_values(obj: Resource) -> Resource:
6471
6572 value = f"https://{ str (uuid .uuid4 ())} .test"
6673
67- elif field_type is EmailStr :
68- # pydantic won't allow to use the 'test' TLD here
69- value = f"{ uuid .uuid4 ()} @{ uuid .uuid4 ()} .com"
70-
7174 elif isclass (field_type ) and issubclass (field_type , Enum ):
7275 value = random .choice (list (field_type ))
7376
@@ -78,7 +81,8 @@ def fill_with_random_values(obj: Resource) -> Resource:
7881 value = fill_with_random_values (field_type ())
7982
8083 else :
81- value = str (uuid .uuid4 ())
84+ # Put emails so this will be accepted by EmailStr too
85+ value = f"{ uuid .uuid4 ()} @{ uuid .uuid4 ()} .com"
8286
8387 if is_multiple :
8488 setattr (obj , field_name , [value ])
0 commit comments