Skip to content

Commit

Permalink
feat: implement SearchRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed May 25, 2024
1 parent 1b0ca0a commit 62fa3e5
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pydantic_scim2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .schema import Returned
from .schema import Schema
from .schema import Uniqueness
from .search_request import SearchRequest
from .service_provider import AuthenticationScheme
from .service_provider import Bulk
from .service_provider import ChangePassword
Expand Down Expand Up @@ -73,6 +74,7 @@
"Role",
"Schema",
"SchemaExtension",
"SearchRequest",
"ServiceProviderConfiguration",
"Sort",
"Uniqueness",
Expand Down
50 changes: 50 additions & 0 deletions pydantic_scim2/search_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from enum import Enum
from typing import List
from typing import Optional

from .base import SCIM2Model


class SortOrder(str, Enum):
ascending = "ascending"
descending = "descending"


class SearchRequest(SCIM2Model):
"""SearchRequest object defined at https://datatracker.ietf.org/doc/html/rfc7644#section-3.4.3"""

schemas: List[str] = ["urn:ietf:params:scim:api:messages:2.0:SearchRequest"]

attributes: Optional[List[str]] = None
"""A multi-valued list of strings indicating the names of resource
attributes to return in the response, overriding the set of attributes that
would be returned by default."""
# TODO: Attribute names
# MUST be in standard attribute notation (Section 3.10) form.

excluded_attributes: Optional[List[str]] = None
"""A multi-valued list of strings indicating the names of resource
attributes to be removed from the default set of attributes to return."""
# TODO: Attribute names MUST be in
# standard attribute notation (Section 3.10) form. See Section 3.9
# for additional retrieval query parameters.

filter: Optional[str] = None
"""The filter string used to request a subset of resources."""
# TODO: The filter string MUST be a valid filter (Section 3.4.2.2) expression.

sort_by: Optional[str] = None
"""A string indicating the attribute whose value SHALL be used to order the
returned responses."""
# TODO: The "sortBy" attribute MUST be in standard attribute notation (Section 3.10) form.

sort_order: Optional[SortOrder] = None
"""A string indicating the order in which the "sortBy" parameter is
applied."""

start_index: Optional[int] = None
"""An integer indicating the 1-based index of the first query result."""

count: Optional[int] = None
"""An integer indicating the desired maximum number of query results per
page."""
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2952,3 +2952,16 @@ def error_bad_request_payload():
"detail": "Attribute 'id' is readOnly",
"status": "400",
}


@pytest.fixture
def search_request_payload():
"""https://datatracker.ietf.org/doc/html/rfc7644#section-3.4.3"""

return {
"schemas": ["urn:ietf:params:scim:api:messages:2.0:SearchRequest"],
"attributes": ["displayName", "userName"],
"filter": 'displayName sw "smith"',
"startIndex": 1,
"count": 10,
}
13 changes: 13 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pydantic_scim2 import ResourceType
from pydantic_scim2 import Returned
from pydantic_scim2 import Schema
from pydantic_scim2 import SearchRequest
from pydantic_scim2 import ServiceProviderConfiguration
from pydantic_scim2 import Uniqueness
from pydantic_scim2 import User
Expand Down Expand Up @@ -863,3 +864,15 @@ def test_error_bad_request(
)
== error_bad_request_payload
)


def test_search_request(
search_request_payload,
):
obj = SearchRequest.model_validate(search_request_payload)
assert (
obj.model_dump(
exclude_none=True, exclude_unset=True, by_alias=True, mode="json"
)
== search_request_payload
)

0 comments on commit 62fa3e5

Please sign in to comment.