Skip to content

Commit 7fdcb76

Browse files
committed
tests: ensure externalId is exported with to_schema when redefined in subclasses
1 parent f752c49 commit 7fdcb76

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/test_schema.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
from typing import Annotated
12
from typing import Optional
23

34
import pytest
45
from pydantic import ValidationError
56

67
from scim2_models import Attribute
8+
from scim2_models import CaseExact
79
from scim2_models import Mutability
10+
from scim2_models import Required
811
from scim2_models import Returned
912
from scim2_models import Schema
1013
from 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

Comments
 (0)