Skip to content

Commit b2d18c6

Browse files
committed
chore: bump to scim2-models 0.2.4
1 parent 5684cd1 commit b2d18c6

File tree

5 files changed

+9
-37
lines changed

5 files changed

+9
-37
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ classifiers = [
2929
requires-python = ">= 3.11"
3030
dependencies = [
3131
"scim2-filter-parser>=0.7.0",
32-
"scim2-models>=0.2.3",
32+
"scim2-models>=0.2.4",
3333
"werkzeug>=3.0.3",
3434
]
3535

scim2_server/operators.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from scim2_server.utils import get_by_alias
1818
from scim2_server.utils import get_or_create
1919
from scim2_server.utils import handle_extension
20-
from scim2_server.utils import is_multi_valued
2120
from scim2_server.utils import parse_new_value
2221

2322
ATTRIBUTE_PATH_REGEX = re.compile(
@@ -221,7 +220,7 @@ class AddOperator(Operator):
221220
@classmethod
222221
def operation(cls, model: BaseModel, attribute: str, value: Any):
223222
alias = get_by_alias(model, attribute)
224-
if is_multi_valued(model, alias) and isinstance(value, list):
223+
if model.get_field_multiplicity(alias) and isinstance(value, list):
225224
for v in value:
226225
cls.operation(model, attribute, v)
227226
return
@@ -234,7 +233,7 @@ def operation(cls, model: BaseModel, attribute: str, value: Any):
234233
if model.get_field_annotation(alias, Mutability) == Mutability.read_only:
235234
raise SCIMException(Error.make_mutability_error())
236235

237-
if is_multi_valued(model, alias):
236+
if model.get_field_multiplicity(alias):
238237
if getattr(model, alias) is None:
239238
setattr(model, alias, [])
240239
if getattr(new_value, "primary", False):
@@ -281,7 +280,7 @@ class ReplaceOperator(Operator):
281280
@classmethod
282281
def operation(cls, model: BaseModel, attribute: str, value: Any):
283282
alias = get_by_alias(model, attribute)
284-
if is_multi_valued(model, alias) and not isinstance(value, list):
283+
if model.get_field_multiplicity(alias) and not isinstance(value, list):
285284
raise SCIMException(Error.make_invalid_value_error())
286285

287286
existing_value = getattr(model, alias)

scim2_server/utils.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import datetime
22
import importlib
33
import json
4-
from types import UnionType
54
from typing import Any
6-
from typing import Union
7-
from typing import get_args
8-
from typing import get_origin
95

106
from pydantic import EmailStr
117
from pydantic import ValidationError
@@ -95,17 +91,6 @@ def get_by_alias(r: BaseModel, scim_name: str, allow_none: bool = False) -> str
9591
raise SCIMException(Error.make_no_target_error()) from e
9692

9793

98-
def is_multi_valued(model: BaseModel, attribute_name: str) -> bool:
99-
"""Check whether a given attribute of a model is multi-valued."""
100-
attribute_type = model.model_fields[attribute_name].annotation
101-
102-
if get_origin(attribute_type) in (Union, UnionType):
103-
attribute_type = get_args(attribute_type)[0]
104-
105-
origin = get_origin(attribute_type)
106-
return isinstance(origin, type) and issubclass(origin, list)
107-
108-
10994
def get_schemas(resource: Resource) -> list[str]:
11095
"""Return a list of all schemas possible for a given resource.
11196
@@ -136,7 +121,7 @@ def get_or_create(
136121
raise SCIMException(Error.make_mutability_error())
137122
ret = getattr(model, attribute_name, None)
138123
if not ret:
139-
if is_multi_valued(model, attribute_name):
124+
if model.get_field_multiplicity(attribute_name):
140125
ret = []
141126
setattr(model, attribute_name, ret)
142127
else:

tests/test_utils.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from scim2_server.operators import ResolveOperator
1616
from scim2_server.utils import SCIMException
1717
from scim2_server.utils import get_or_create
18-
from scim2_server.utils import is_multi_valued
1918
from scim2_server.utils import merge_resources
2019

2120

@@ -366,17 +365,6 @@ class Foo(Resource):
366365
with pytest.raises(SCIMException, match="mutability"):
367366
merge_resources(stored, Foo(immutable_string="D"))
368367

369-
def test_is_multi_valued(self):
370-
class Foo(Resource):
371-
schemas: list[str] = ["urn:example:2.0:Foo"]
372-
some_string: str | None = None
373-
multi_valued_string: list[str] | None = None
374-
375-
res = Foo()
376-
assert is_multi_valued(res, "schemas")
377-
assert not is_multi_valued(res, "some_string")
378-
assert is_multi_valued(res, "multi_valued_string")
379-
380368
def test_get_or_create_mutability(self):
381369
u = User()
382370
with pytest.raises(SCIMException, match="immutable"):

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)