Skip to content

Commit d6795a2

Browse files
committed
feat: implement Attribute.get_attribute
1 parent ca2f011 commit d6795a2

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

doc/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
[0.2.12] - Unreleased
5+
---------------------
6+
Added
7+
^^^^^
8+
- Implement :meth:`Attribute.get_attribute <scim2_models.Attribute.get_attribute>`.
9+
410
[0.2.11] - 2024-12-08
511
---------------------
612
Added

scim2_models/rfc7643/schema.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ def to_python(self) -> Optional[tuple[Any, Field]]:
238238

239239
return annotation, field
240240

241+
def get_attribute(self, attribute_name: str) -> Optional["Attribute"]:
242+
"""Find an attribute by its name."""
243+
for sub_attribute in self.sub_attributes or []:
244+
if sub_attribute.name == attribute_name:
245+
return sub_attribute
246+
return None
247+
241248

242249
class Schema(Resource):
243250
schemas: Annotated[list[str], Required.true] = [

tests/test_schema.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_uri_ids():
8787
Schema(id="invalid\nuri")
8888

8989

90-
def test_get_attribute(load_sample):
90+
def test_get_schema_attribute(load_sample):
9191
"""Test the Schema.get_attribute method."""
9292
payload = load_sample("rfc7643-8.7.1-schema-user.json")
9393
schema = Schema.model_validate(payload)
@@ -98,3 +98,18 @@ def test_get_attribute(load_sample):
9898
schema.get_attribute("userName").mutability = Mutability.read_only
9999

100100
assert schema.attributes[0].mutability == Mutability.read_only
101+
102+
103+
def test_get_attribute_attribute(load_sample):
104+
"""Test the Schema.get_attribute method."""
105+
payload = load_sample("rfc7643-8.7.1-schema-group.json")
106+
schema = Schema.model_validate(payload)
107+
attribute = schema.get_attribute("members")
108+
109+
assert attribute.get_attribute("invalid") is None
110+
111+
assert attribute.sub_attributes[0].name == "value"
112+
assert attribute.sub_attributes[0].mutability == Mutability.immutable
113+
attribute.get_attribute("value").mutability = Mutability.read_only
114+
115+
assert attribute.sub_attributes[0].mutability == Mutability.read_only

0 commit comments

Comments
 (0)