Skip to content

Commit 1ea045f

Browse files
committed
feat: implement Schema.get_attribute
1 parent eb67018 commit 1ea045f

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
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.11] - Unreleased
5+
---------------------
6+
Added
7+
^^^^^
8+
- Implement :meth:`Schema.get_attribute <scim2_models.Schema.get_attribute>`.
9+
410
[0.2.10] - 2024-12-02
511
---------------------
612

scim2_models/rfc7643/schema.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,10 @@ class Schema(Resource):
266266
def urn_id(cls, value: str) -> str:
267267
"""Ensure that schema ids are URI, as defined in RFC7643 §7."""
268268
return str(Url(value))
269+
270+
def get_attribute(self, attribute_name: str) -> Optional[Attribute]:
271+
"""Find an attribute by its name."""
272+
for attribute in self.attributes or []:
273+
if attribute.name == attribute_name:
274+
return attribute
275+
return None

tests/test_schema.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,11 @@ def test_uri_ids():
8585
Schema(id="urn:ietf:params:scim:schemas:extension:enterprise:2.0:User")
8686
with pytest.raises(ValidationError):
8787
Schema(id="invalid\nuri")
88+
89+
90+
def test_get_attribute(load_sample):
91+
"""Test the Schema.get_attribute method."""
92+
payload = load_sample("rfc7643-8.7.1-schema-user.json")
93+
schema = Schema.model_validate(payload)
94+
assert schema.get_attribute("invalid") is None
95+
assert isinstance(schema.get_attribute("userName"), Attribute)

0 commit comments

Comments
 (0)