From f3b54297bd1b6ea9b37cd901c016bb2c45b19b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89loi=20Rivard?= Date: Fri, 7 Mar 2025 18:40:22 +0100 Subject: [PATCH] fix: startIndex and count lower limits --- doc/changelog.rst | 7 +++++++ scim2_models/rfc7644/search_request.py | 10 +++++----- tests/test_search_request.py | 13 +++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 947848f..9a0460f 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -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 -------------------- diff --git a/scim2_models/rfc7644/search_request.py b/scim2_models/rfc7644/search_request.py index e1c0e91..8713281 100644 --- a/scim2_models/rfc7644/search_request.py +++ b/scim2_models/rfc7644/search_request.py @@ -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 @@ -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): diff --git a/tests/test_search_request.py b/tests/test_search_request.py index 6fc686d..2f7e58e 100644 --- a/tests/test_search_request.py +++ b/tests/test_search_request.py @@ -29,13 +29,13 @@ 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(): @@ -43,16 +43,13 @@ def test_count_floor(): 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():