File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed
Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 11Changelog
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---------------------
612Added
Original file line number Diff line number Diff 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
242249class Schema (Resource ):
243250 schemas : Annotated [list [str ], Required .true ] = [
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ def test_uri_ids():
8787 Schema (id = "invalid\n uri" )
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
You can’t perform that action at this time.
0 commit comments