Skip to content

fix startIndex and count lower limits #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

[0.3.1] - Unreleased
--------------------

Fixed
^^^^^
- Fix :attr:`~SearchRequest.start_index` and :attr:`~SearchRequest.count` limits. :issue:`84`

[0.3.0] - 2024-12-11
--------------------

Expand Down
10 changes: 5 additions & 5 deletions scim2_models/rfc7644/search_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class SortOrder(str, Enum):
@field_validator("start_index")
@classmethod
def start_index_floor(cls, value: int) -> int:
"""According to :rfc:`RFC7644 §3.4.2 <7644#section-3.4.2.4>, start_index values less than 0 are interpreted as 0.
"""According to :rfc:`RFC7644 §3.4.2 <7644#section-3.4.2.4>, start_index values less than 1 are interpreted as 1.

A value less than 1 SHALL be interpreted as 1.
"""
return None if value is None else max(0, value)
return None if value is None else max(1, value)

count: Optional[int] = None
"""An integer indicating the desired maximum number of query results per
Expand All @@ -62,11 +62,11 @@ def start_index_floor(cls, value: int) -> int:
@field_validator("count")
@classmethod
def count_floor(cls, value: int) -> int:
"""According to :rfc:`RFC7644 §3.4.2 <7644#section-3.4.2.4>, count values less than 1 are interpreted as 1.
"""According to :rfc:`RFC7644 §3.4.2 <7644#section-3.4.2.4>, count values less than 0 are interpreted as 0.

A value less than 1 SHALL be interpreted as 1.
A negative value SHALL be interpreted as 0.
"""
return None if value is None else max(1, value)
return None if value is None else max(0, value)

@model_validator(mode="after")
def attributes_validator(self):
Expand Down
13 changes: 5 additions & 8 deletions tests/test_search_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,27 @@ def test_start_index_floor():

https://datatracker.ietf.org/doc/html/rfc7644#section-3.4.2.4

A negative value SHALL be interpreted as 0.
A value less than 1 SHALL be interpreted as 1.
"""
sr = SearchRequest(start_index=100)
assert sr.start_index == 100

sr = SearchRequest(start_index=-1)
assert sr.start_index == 0
sr = SearchRequest(start_index=0)
assert sr.start_index == 1


def test_count_floor():
"""Test that count values less than 1 are interpreted as 1.

https://datatracker.ietf.org/doc/html/rfc7644#section-3.4.2.4

A value less than 1 SHALL be interpreted as 1.
A negative value SHALL be interpreted as 0.
"""
sr = SearchRequest(count=100)
assert sr.count == 100

sr = SearchRequest(count=0)
assert sr.count == 1

sr = SearchRequest(count=-1)
assert sr.count == 1
assert sr.count == 0


def test_attributes_or_excluded_attributes():
Expand Down