Skip to content

Commit 55bb0a4

Browse files
authored
Merge pull request #89 from python-scim/84-start-index
fix startIndex and count lower limits
2 parents 935d605 + f3b5429 commit 55bb0a4

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

doc/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
[0.3.1] - Unreleased
5+
--------------------
6+
7+
Fixed
8+
^^^^^
9+
- Fix :attr:`~SearchRequest.start_index` and :attr:`~SearchRequest.count` limits. :issue:`84`
10+
411
[0.3.0] - 2024-12-11
512
--------------------
613

scim2_models/rfc7644/search_request.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ class SortOrder(str, Enum):
4949
@field_validator("start_index")
5050
@classmethod
5151
def start_index_floor(cls, value: int) -> int:
52-
"""According to :rfc:`RFC7644 §3.4.2 <7644#section-3.4.2.4>, start_index values less than 0 are interpreted as 0.
52+
"""According to :rfc:`RFC7644 §3.4.2 <7644#section-3.4.2.4>, start_index values less than 1 are interpreted as 1.
5353
5454
A value less than 1 SHALL be interpreted as 1.
5555
"""
56-
return None if value is None else max(0, value)
56+
return None if value is None else max(1, value)
5757

5858
count: Optional[int] = None
5959
"""An integer indicating the desired maximum number of query results per
@@ -62,11 +62,11 @@ def start_index_floor(cls, value: int) -> int:
6262
@field_validator("count")
6363
@classmethod
6464
def count_floor(cls, value: int) -> int:
65-
"""According to :rfc:`RFC7644 §3.4.2 <7644#section-3.4.2.4>, count values less than 1 are interpreted as 1.
65+
"""According to :rfc:`RFC7644 §3.4.2 <7644#section-3.4.2.4>, count values less than 0 are interpreted as 0.
6666
67-
A value less than 1 SHALL be interpreted as 1.
67+
A negative value SHALL be interpreted as 0.
6868
"""
69-
return None if value is None else max(1, value)
69+
return None if value is None else max(0, value)
7070

7171
@model_validator(mode="after")
7272
def attributes_validator(self):

tests/test_search_request.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,27 @@ def test_start_index_floor():
2929
3030
https://datatracker.ietf.org/doc/html/rfc7644#section-3.4.2.4
3131
32-
A negative value SHALL be interpreted as 0.
32+
A value less than 1 SHALL be interpreted as 1.
3333
"""
3434
sr = SearchRequest(start_index=100)
3535
assert sr.start_index == 100
3636

37-
sr = SearchRequest(start_index=-1)
38-
assert sr.start_index == 0
37+
sr = SearchRequest(start_index=0)
38+
assert sr.start_index == 1
3939

4040

4141
def test_count_floor():
4242
"""Test that count values less than 1 are interpreted as 1.
4343
4444
https://datatracker.ietf.org/doc/html/rfc7644#section-3.4.2.4
4545
46-
A value less than 1 SHALL be interpreted as 1.
46+
A negative value SHALL be interpreted as 0.
4747
"""
4848
sr = SearchRequest(count=100)
4949
assert sr.count == 100
5050

51-
sr = SearchRequest(count=0)
52-
assert sr.count == 1
53-
5451
sr = SearchRequest(count=-1)
55-
assert sr.count == 1
52+
assert sr.count == 0
5653

5754

5855
def test_attributes_or_excluded_attributes():

0 commit comments

Comments
 (0)