|
1 | | -from typing import Annotated |
2 | | -from typing import Optional |
3 | | - |
4 | 1 | import pytest |
5 | 2 | from pydantic import ValidationError |
6 | 3 |
|
7 | 4 | from scim2_models import Attribute |
8 | | -from scim2_models import CaseExact |
9 | 5 | from scim2_models import Mutability |
10 | | -from scim2_models import Required |
11 | 6 | from scim2_models import Returned |
12 | 7 | from scim2_models import Schema |
13 | 8 | from scim2_models import Uniqueness |
14 | | -from scim2_models.resources.resource import Resource |
15 | | -from scim2_models.resources.resource import _model_to_schema |
16 | 9 |
|
17 | 10 |
|
18 | 11 | def test_group_schema(load_sample): |
@@ -130,50 +123,3 @@ def test_get_attribute_attribute(load_sample): |
130 | 123 |
|
131 | 124 | attribute["value"].mutability = Mutability.read_write |
132 | 125 | assert attribute.sub_attributes[0].mutability == Mutability.read_write |
133 | | - |
134 | | - |
135 | | -def test_model_to_schema_excludes_none_type_attributes(): |
136 | | - """Test that _model_to_schema excludes attributes with None type from schema.""" |
137 | | - |
138 | | - class TestResource(Resource): |
139 | | - schemas: list[str] = ["urn:test:schema"] |
140 | | - valid_attr: Optional[str] = None |
141 | | - none_attr: None = None |
142 | | - |
143 | | - schema = TestResource.to_schema() |
144 | | - |
145 | | - assert schema.id == "urn:test:schema" |
146 | | - assert schema.name == "TestResource" |
147 | | - |
148 | | - attribute_names = [attr.name for attr in schema.attributes] |
149 | | - |
150 | | - assert "validAttr" in attribute_names |
151 | | - 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