1+ from typing import Annotated
12from typing import Optional
23
34import pytest
45from pydantic import ValidationError
56
67from scim2_models import Attribute
8+ from scim2_models import CaseExact
79from scim2_models import Mutability
10+ from scim2_models import Required
811from scim2_models import Returned
912from scim2_models import Schema
1013from scim2_models import Uniqueness
@@ -137,7 +140,7 @@ class TestResource(Resource):
137140 valid_attr : Optional [str ] = None
138141 none_attr : None = None
139142
140- schema = _model_to_schema ( TestResource )
143+ schema = TestResource . to_schema ( )
141144
142145 assert schema .id == "urn:test:schema"
143146 assert schema .name == "TestResource"
@@ -146,3 +149,31 @@ class TestResource(Resource):
146149
147150 assert "validAttr" in attribute_names
148151 assert "noneAttr" not in attribute_names
152+
153+
154+ def test_external_id_redefined_in_subclass_is_exported ():
155+ class CustomResource (Resource ):
156+ schemas : list [str ] = ["urn:custom:schema" ]
157+
158+ external_id : Annotated [
159+ Optional [str ],
160+ Mutability .immutable ,
161+ Returned .always ,
162+ Required .true ,
163+ CaseExact .false ,
164+ ] = None
165+
166+ schema = CustomResource .to_schema ()
167+
168+ attribute_names = [attr .name for attr in schema .attributes ]
169+ assert "externalId" in attribute_names
170+
171+
172+ def test_external_id_not_exported_when_not_redefined ():
173+ class SimpleResource (Resource ):
174+ schemas : list [str ] = ["urn:simple:schema" ]
175+
176+ schema = _model_to_schema (SimpleResource )
177+
178+ attribute_names = [attr .name for attr in schema .attributes ]
179+ assert "externalId" not in attribute_names
0 commit comments