scim2-server 0.8.7__tar.gz → 0.8.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {scim2_server-0.8.7 → scim2_server-0.8.8}/PKG-INFO +1 -1
- {scim2_server-0.8.7 → scim2_server-0.8.8}/pyproject.toml +1 -1
- {scim2_server-0.8.7 → scim2_server-0.8.8}/pyproject.toml.orig +1 -1
- scim2_server-0.8.8/scim2_server/keyset.py +219 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/memory.py +44 -55
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/testing.py +103 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/LICENSE +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/README.md +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/__init__.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/applications/__init__.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/applications/asgi.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/applications/base.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/applications/wsgi.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/bulk.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/conditions.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/cursor.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/errors.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/handler.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/py.typed +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/requests.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/resources/default-resource-types.json +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/resources/default-schemas.json +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/resources/default-service-provider-config.json +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/responses.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/routing.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/service.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/storage.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/testserver/__init__.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/testserver/application.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/testserver/cli.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/testserver/oauth.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/testserver/precis.py +0 -0
- {scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/utils.py +0 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"""Helpers for a storage that pages with cursors by keyset.
|
|
2
|
+
|
|
3
|
+
A keyset storage orders the rows by the sort value, then by identifier. A
|
|
4
|
+
position holds the sort value and the identifier of the row a page starts
|
|
5
|
+
after, or ends before. These helpers read and write such positions, and build
|
|
6
|
+
the pages around them. A storage may use its own positions instead.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import datetime
|
|
10
|
+
import decimal
|
|
11
|
+
import uuid
|
|
12
|
+
from collections.abc import Callable
|
|
13
|
+
from collections.abc import Sequence
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from scim2_models import InvalidCursorException
|
|
18
|
+
from scim2_models import Resource
|
|
19
|
+
from scim2_models import SearchRequest
|
|
20
|
+
|
|
21
|
+
from scim2_server.storage import SearchPage
|
|
22
|
+
|
|
23
|
+
_TAGGED: dict[str, tuple[type, Callable[[Any], str], Callable[[str], Any]]] = {
|
|
24
|
+
"datetime": (
|
|
25
|
+
datetime.datetime,
|
|
26
|
+
datetime.datetime.isoformat,
|
|
27
|
+
datetime.datetime.fromisoformat,
|
|
28
|
+
),
|
|
29
|
+
"date": (datetime.date, datetime.date.isoformat, datetime.date.fromisoformat),
|
|
30
|
+
"decimal": (decimal.Decimal, str, decimal.Decimal),
|
|
31
|
+
"uuid": (uuid.UUID, str, uuid.UUID),
|
|
32
|
+
}
|
|
33
|
+
"""The sort values JSON has no type for, by tag. A datetime is a date too, so it comes first."""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def encode_sort_value(value: Any) -> Any:
|
|
37
|
+
"""Return a sort value as a value JSON can hold.
|
|
38
|
+
|
|
39
|
+
:data:`None`, booleans, numbers and strings are returned as they are.
|
|
40
|
+
A :class:`~datetime.datetime`, a :class:`~datetime.date`, a
|
|
41
|
+
:class:`~decimal.Decimal` or a :class:`~uuid.UUID` is returned as an
|
|
42
|
+
object with a tag, such as ``{"date": "2026-10-09"}``, so that
|
|
43
|
+
:func:`decode_sort_value` gives it back in its own type.
|
|
44
|
+
|
|
45
|
+
:raises TypeError: if the value has another type.
|
|
46
|
+
"""
|
|
47
|
+
if value is None or isinstance(value, bool | int | float | str):
|
|
48
|
+
return value
|
|
49
|
+
|
|
50
|
+
for tag, (python_type, dump, _) in _TAGGED.items():
|
|
51
|
+
if isinstance(value, python_type):
|
|
52
|
+
return {tag: dump(value)}
|
|
53
|
+
|
|
54
|
+
raise TypeError(f"Cannot page on a sort value of type {type(value).__name__}")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def decode_sort_value(value: Any) -> Any:
|
|
58
|
+
"""Return the sort value that :func:`encode_sort_value` gave.
|
|
59
|
+
|
|
60
|
+
:raises ~scim2_models.InvalidCursorException: if no sort value gives this value.
|
|
61
|
+
"""
|
|
62
|
+
if value is None or isinstance(value, bool | int | float | str):
|
|
63
|
+
return value
|
|
64
|
+
|
|
65
|
+
if not isinstance(value, dict) or len(value) != 1:
|
|
66
|
+
raise InvalidCursorException
|
|
67
|
+
|
|
68
|
+
((tag, text),) = value.items()
|
|
69
|
+
if tag not in _TAGGED or not isinstance(text, str):
|
|
70
|
+
raise InvalidCursorException
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
return _TAGGED[tag][2](text)
|
|
74
|
+
except (ValueError, decimal.InvalidOperation):
|
|
75
|
+
raise InvalidCursorException from None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@dataclass(frozen=True)
|
|
79
|
+
class Bound:
|
|
80
|
+
"""The first or the last row of a page, as :func:`keyset_page` needs it."""
|
|
81
|
+
|
|
82
|
+
key: Any
|
|
83
|
+
"""The sort value of the row, or :data:`None` when it has none, or when the search has no sort."""
|
|
84
|
+
|
|
85
|
+
id: str
|
|
86
|
+
"""The identifier of the resource of the row."""
|
|
87
|
+
|
|
88
|
+
type_index: int | None = None
|
|
89
|
+
"""The index of the resource type of the row, in a search at the root that orders the rows by resource type."""
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@dataclass(frozen=True)
|
|
93
|
+
class Position:
|
|
94
|
+
"""The row a cursor page starts after, or ends before.
|
|
95
|
+
|
|
96
|
+
The rows with the same sort value are ordered by identifier. In a search
|
|
97
|
+
at the root, a storage may order them by the index of their resource type
|
|
98
|
+
first, so that two resources of different types can share an identifier.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
forward: bool
|
|
102
|
+
"""Whether the page starts after the row, rather than ending before it."""
|
|
103
|
+
|
|
104
|
+
key: Any
|
|
105
|
+
"""The sort value of the row, or :data:`None` when it has none, or when the search has no sort."""
|
|
106
|
+
|
|
107
|
+
id: str
|
|
108
|
+
"""The identifier of the resource of the row."""
|
|
109
|
+
|
|
110
|
+
type_index: int | None = None
|
|
111
|
+
"""The index of the resource type of the row, in a search at the root that orders the rows by resource type."""
|
|
112
|
+
|
|
113
|
+
@classmethod
|
|
114
|
+
def load(
|
|
115
|
+
cls, value: Any, *, has_sort: bool, type_count: int | None = None
|
|
116
|
+
) -> "Position | None":
|
|
117
|
+
"""Read a position that :meth:`dump` wrote, or return :data:`None` for the first page.
|
|
118
|
+
|
|
119
|
+
``has_sort`` tells whether the search has a sort. Without one, the
|
|
120
|
+
position holds no sort value.
|
|
121
|
+
|
|
122
|
+
``type_count`` is the number of resource types that the storage
|
|
123
|
+
orders the rows by. A storage that does not order the rows by
|
|
124
|
+
resource type leaves it out. The position holds the index of a
|
|
125
|
+
resource type when ``type_count`` is given, and holds none
|
|
126
|
+
otherwise. :meth:`dump` writes this index when
|
|
127
|
+
:attr:`type_index` is not :data:`None`.
|
|
128
|
+
|
|
129
|
+
:raises ~scim2_models.InvalidCursorException: if the value is not such
|
|
130
|
+
a position.
|
|
131
|
+
"""
|
|
132
|
+
if value is None:
|
|
133
|
+
return None
|
|
134
|
+
|
|
135
|
+
by_type = type_count is not None
|
|
136
|
+
names = {"d", "k", "t", "i"} if by_type else {"d", "k", "i"}
|
|
137
|
+
if not isinstance(value, dict) or set(value) != names:
|
|
138
|
+
raise InvalidCursorException
|
|
139
|
+
|
|
140
|
+
if value["d"] not in ("next", "previous") or not isinstance(value["i"], str):
|
|
141
|
+
raise InvalidCursorException
|
|
142
|
+
|
|
143
|
+
if not has_sort and value["k"] is not None:
|
|
144
|
+
raise InvalidCursorException
|
|
145
|
+
|
|
146
|
+
type_index = value.get("t")
|
|
147
|
+
if by_type and (
|
|
148
|
+
type(type_index) is not int or type_index not in range(type_count or 0)
|
|
149
|
+
):
|
|
150
|
+
raise InvalidCursorException
|
|
151
|
+
|
|
152
|
+
key = decode_sort_value(value["k"])
|
|
153
|
+
return cls(value["d"] == "next", key, value["i"], type_index)
|
|
154
|
+
|
|
155
|
+
def dump(self) -> dict[str, Any]:
|
|
156
|
+
"""Return the position as a value JSON can hold.
|
|
157
|
+
|
|
158
|
+
:raises TypeError: if :func:`encode_sort_value` cannot hold the sort value.
|
|
159
|
+
"""
|
|
160
|
+
position: dict[str, Any] = {
|
|
161
|
+
"d": "next" if self.forward else "previous",
|
|
162
|
+
"k": encode_sort_value(self.key),
|
|
163
|
+
}
|
|
164
|
+
if self.type_index is not None:
|
|
165
|
+
position["t"] = self.type_index
|
|
166
|
+
|
|
167
|
+
position["i"] = self.id
|
|
168
|
+
return position
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def page_rows(
|
|
172
|
+
rows: Sequence[Any], search_request: SearchRequest[Any], position: Position | None
|
|
173
|
+
) -> tuple[list[Any], bool]:
|
|
174
|
+
"""Return the rows of a page in the sort order, and whether more rows follow in the reading direction.
|
|
175
|
+
|
|
176
|
+
For a cursor page, the storage reads ``count + 1`` rows, in the reverse
|
|
177
|
+
order for a page that ends before the position. Without a cursor, the
|
|
178
|
+
rows are returned as they are.
|
|
179
|
+
"""
|
|
180
|
+
if search_request.cursor is None:
|
|
181
|
+
return list(rows), False
|
|
182
|
+
|
|
183
|
+
count = search_request.count
|
|
184
|
+
more = count is not None and len(rows) > count
|
|
185
|
+
page = list(rows if count is None else rows[:count])
|
|
186
|
+
if position is not None and not position.forward:
|
|
187
|
+
page.reverse()
|
|
188
|
+
|
|
189
|
+
return page, more
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def keyset_page(
|
|
193
|
+
total: int | None,
|
|
194
|
+
resources: Sequence[Resource[Any]],
|
|
195
|
+
first: Bound | None,
|
|
196
|
+
last: Bound | None,
|
|
197
|
+
more: bool,
|
|
198
|
+
position: Position | None,
|
|
199
|
+
) -> SearchPage:
|
|
200
|
+
"""Return a cursor page, with the positions of the pages around it.
|
|
201
|
+
|
|
202
|
+
``first`` and ``last`` are the first and the last rows of the page, or
|
|
203
|
+
:data:`None` when the page is empty. ``more`` tells whether more rows
|
|
204
|
+
follow in the reading direction, as :func:`page_rows` gives it. In the
|
|
205
|
+
other direction, the page the client comes from is assumed to still
|
|
206
|
+
exist.
|
|
207
|
+
"""
|
|
208
|
+
page = SearchPage(total, list(resources))
|
|
209
|
+
if first is None or last is None:
|
|
210
|
+
return page
|
|
211
|
+
|
|
212
|
+
forward = position is None or position.forward
|
|
213
|
+
if more or not forward:
|
|
214
|
+
page.next = Position(True, last.key, last.id, last.type_index).dump()
|
|
215
|
+
|
|
216
|
+
if position is not None and (more or forward):
|
|
217
|
+
page.previous = Position(False, first.key, first.id, first.type_index).dump()
|
|
218
|
+
|
|
219
|
+
return page
|
|
@@ -10,7 +10,6 @@ from typing import Union
|
|
|
10
10
|
from typing import cast
|
|
11
11
|
|
|
12
12
|
from scim2_models import AttributeBinding
|
|
13
|
-
from scim2_models import InvalidCursorException
|
|
14
13
|
from scim2_models import Meta
|
|
15
14
|
from scim2_models import NotFoundException
|
|
16
15
|
from scim2_models import Path
|
|
@@ -25,6 +24,7 @@ from scim2_models import UniquenessException
|
|
|
25
24
|
from scim2_models.path import CompareOperator
|
|
26
25
|
from scim2_models.path import Comparison
|
|
27
26
|
|
|
27
|
+
from scim2_server.keyset import Position
|
|
28
28
|
from scim2_server.storage import AsyncScimStorage
|
|
29
29
|
from scim2_server.storage import ScimStorage
|
|
30
30
|
from scim2_server.storage import SearchPage
|
|
@@ -39,19 +39,28 @@ def utcnow() -> datetime.datetime:
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
def _page(
|
|
42
|
-
search_request: SearchRequest[Any],
|
|
42
|
+
search_request: SearchRequest[Any],
|
|
43
|
+
position: Any,
|
|
44
|
+
resources: list[Resource[Any]],
|
|
45
|
+
names: list[str | None],
|
|
43
46
|
) -> SearchPage:
|
|
44
|
-
"""Sort every matching resource by its sort value then its identifier, and return the page a search asks for.
|
|
47
|
+
"""Sort every matching resource by its sort value, its resource type then its identifier, and return the page a search asks for.
|
|
45
48
|
|
|
46
|
-
A cursor position holds the sort value
|
|
47
|
-
the page starts after, or ends before, so the
|
|
49
|
+
A cursor position holds the sort value, the resource type and the
|
|
50
|
+
identifier of the resource the page starts after, or ends before, so the
|
|
51
|
+
pages stay stable. The resource type is left out of the positions of a
|
|
52
|
+
search on a single resource type.
|
|
48
53
|
"""
|
|
54
|
+
types = {name: index for index, name in enumerate(names)}
|
|
49
55
|
descending = (
|
|
50
56
|
search_request.sort_by is not None
|
|
51
57
|
and search_request.sort_order == SearchRequest.SortOrder.descending
|
|
52
58
|
)
|
|
53
59
|
pairs = sorted(
|
|
54
|
-
(
|
|
60
|
+
(
|
|
61
|
+
(_sort_key(search_request, types, resource), resource)
|
|
62
|
+
for resource in resources
|
|
63
|
+
),
|
|
55
64
|
key=lambda pair: pair[0],
|
|
56
65
|
reverse=descending,
|
|
57
66
|
)
|
|
@@ -64,40 +73,51 @@ def _page(
|
|
|
64
73
|
if search_request.count == 0:
|
|
65
74
|
return SearchPage(len(found), [])
|
|
66
75
|
|
|
76
|
+
type_count = len(types) if len(types) > 1 else None
|
|
77
|
+
anchor = Position.load(
|
|
78
|
+
position, has_sort=search_request.sort_by is not None, type_count=type_count
|
|
79
|
+
)
|
|
67
80
|
start, stop = _bounds(
|
|
68
|
-
[key for key, _ in pairs],
|
|
81
|
+
[key for key, _ in pairs], anchor, search_request.count, descending
|
|
69
82
|
)
|
|
70
83
|
page = SearchPage(len(found), found[start:stop])
|
|
71
84
|
if page.resources and stop < len(found):
|
|
72
|
-
page.next = _position(
|
|
85
|
+
page.next = _position(True, pairs[stop - 1][0], type_count)
|
|
73
86
|
if page.resources and start > 0:
|
|
74
|
-
page.previous = _position(
|
|
87
|
+
page.previous = _position(False, pairs[start][0], type_count)
|
|
75
88
|
return page
|
|
76
89
|
|
|
77
90
|
|
|
78
|
-
SortKey = tuple[bool, Any, str]
|
|
91
|
+
SortKey = tuple[bool, Any, int, str]
|
|
79
92
|
|
|
80
93
|
|
|
81
|
-
def _sort_key(
|
|
82
|
-
|
|
94
|
+
def _sort_key(
|
|
95
|
+
search_request: SearchRequest[Any],
|
|
96
|
+
types: dict[str | None, int],
|
|
97
|
+
resource: Resource[Any],
|
|
98
|
+
) -> SortKey:
|
|
99
|
+
"""Return the key that orders a resource: its sort value, missing values last, then its resource type and its identifier."""
|
|
83
100
|
value = search_request.sort_value(resource)
|
|
84
|
-
|
|
101
|
+
type_index = types[cast(Meta, resource.meta).resource_type]
|
|
102
|
+
missing = value is None
|
|
103
|
+
return missing, "" if missing else value, type_index, cast(str, resource.id)
|
|
85
104
|
|
|
86
105
|
|
|
87
106
|
def _bounds(
|
|
88
|
-
keys: list[SortKey],
|
|
107
|
+
keys: list[SortKey], anchor: Position | None, count: int | None, descending: bool
|
|
89
108
|
) -> tuple[int, int]:
|
|
90
109
|
"""Return the slice of the sorted keys that a cursor page covers."""
|
|
91
|
-
if
|
|
110
|
+
if anchor is None:
|
|
92
111
|
return 0, len(keys) if count is None else min(count, len(keys))
|
|
93
112
|
|
|
94
|
-
|
|
113
|
+
missing = anchor.key is None
|
|
114
|
+
bound = (missing, "" if missing else anchor.key, anchor.type_index or 0, anchor.id)
|
|
95
115
|
|
|
96
116
|
def before(key: SortKey) -> bool:
|
|
97
|
-
return key >
|
|
117
|
+
return key > bound if descending else key < bound
|
|
98
118
|
|
|
99
|
-
if
|
|
100
|
-
start = sum(1 for key in keys if before(key) or key ==
|
|
119
|
+
if anchor.forward:
|
|
120
|
+
start = sum(1 for key in keys if before(key) or key == bound)
|
|
101
121
|
stop = len(keys) if count is None else min(start + count, len(keys))
|
|
102
122
|
return start, stop
|
|
103
123
|
|
|
@@ -106,42 +126,11 @@ def _bounds(
|
|
|
106
126
|
return start, stop
|
|
107
127
|
|
|
108
128
|
|
|
109
|
-
def _position(
|
|
129
|
+
def _position(forward: bool, key: SortKey, type_count: int | None) -> dict[str, Any]:
|
|
110
130
|
"""Return the position of the page that starts after, or ends before, a sort key."""
|
|
111
|
-
missing, value, identifier = key
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def _read_position(position: Any) -> tuple[str, SortKey]:
|
|
116
|
-
"""Return the direction and the sort key of a position that _page gave."""
|
|
117
|
-
try:
|
|
118
|
-
direction, value, identifier = position["d"], position["k"], position["i"]
|
|
119
|
-
except (TypeError, KeyError):
|
|
120
|
-
raise InvalidCursorException from None
|
|
121
|
-
if direction not in ("next", "previous") or not isinstance(identifier, str):
|
|
122
|
-
raise InvalidCursorException
|
|
123
|
-
if value is None:
|
|
124
|
-
return direction, (True, "", identifier)
|
|
125
|
-
return direction, (False, _decode(value), identifier)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
def _encode(value: Any) -> Any:
|
|
129
|
-
"""Return a sort value in a form JSON can hold."""
|
|
130
|
-
if isinstance(value, datetime.datetime):
|
|
131
|
-
return {"datetime": value.isoformat()}
|
|
132
|
-
if isinstance(value, str | bool | int | float):
|
|
133
|
-
return value
|
|
134
|
-
raise TypeError(f"A cursor cannot hold a sort value of type {type(value).__name__}")
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
def _decode(value: Any) -> Any:
|
|
138
|
-
"""Return the sort value that _encode gave."""
|
|
139
|
-
if not isinstance(value, dict):
|
|
140
|
-
return value
|
|
141
|
-
try:
|
|
142
|
-
return datetime.datetime.fromisoformat(value["datetime"])
|
|
143
|
-
except (KeyError, TypeError, ValueError):
|
|
144
|
-
raise InvalidCursorException from None
|
|
131
|
+
missing, value, type_index, identifier = key
|
|
132
|
+
by_type = None if type_count is None else type_index
|
|
133
|
+
return Position(forward, None if missing else value, identifier, by_type).dump()
|
|
145
134
|
|
|
146
135
|
|
|
147
136
|
Key = tuple[str | None, str]
|
|
@@ -298,7 +287,7 @@ class InMemoryStorage(ScimStorage):
|
|
|
298
287
|
found = [
|
|
299
288
|
r for r in candidates if scim_filter is None or scim_filter.match(r)
|
|
300
289
|
]
|
|
301
|
-
page = _page(search_request, position, found)
|
|
290
|
+
page = _page(search_request, position, found, names)
|
|
302
291
|
page.resources = [r.model_copy(deep=True) for r in page.resources]
|
|
303
292
|
return page
|
|
304
293
|
|
|
@@ -1028,6 +1028,109 @@ class ScimStorageContract:
|
|
|
1028
1028
|
|
|
1029
1029
|
assert sorted(self.ids(pages)) == sorted([users[0].id, users[1].id, group.id])
|
|
1030
1030
|
|
|
1031
|
+
def test_cursor_pages_back_at_the_root(
|
|
1032
|
+
self,
|
|
1033
|
+
storage: Any,
|
|
1034
|
+
user_type: ResourceType,
|
|
1035
|
+
group_type: ResourceType,
|
|
1036
|
+
user_model: Any,
|
|
1037
|
+
group_model: Any,
|
|
1038
|
+
) -> None:
|
|
1039
|
+
"""Following the previous cursors at the root returns the same pages, back to the first."""
|
|
1040
|
+
self.require(storage.supports_cursors, "cursor pagination")
|
|
1041
|
+
self.require(self.supports_root_search, "searching at the root")
|
|
1042
|
+
users = self.create_users(storage, user_type, user_model, "alice", "bob")
|
|
1043
|
+
self.create_group(storage, group_type, group_model, users[0])
|
|
1044
|
+
resource_types = [user_type, group_type]
|
|
1045
|
+
search_request = self.search_request(
|
|
1046
|
+
[user_model, group_model], cursor="", count=1
|
|
1047
|
+
)
|
|
1048
|
+
forward = self.walk(storage, resource_types, search_request)
|
|
1049
|
+
|
|
1050
|
+
backward = self.walk_back(storage, resource_types, search_request, forward[-1])
|
|
1051
|
+
|
|
1052
|
+
assert [[r.id for r in page.resources] for page in reversed(backward)] == [
|
|
1053
|
+
[r.id for r in page.resources] for page in forward[:-1]
|
|
1054
|
+
]
|
|
1055
|
+
assert backward[-1].previous is None
|
|
1056
|
+
|
|
1057
|
+
def test_cursor_pages_back_in_descending_order_with_missing_values(
|
|
1058
|
+
self,
|
|
1059
|
+
storage: Any,
|
|
1060
|
+
provider: ScimProvider,
|
|
1061
|
+
user_type: ResourceType,
|
|
1062
|
+
user_model: Any,
|
|
1063
|
+
) -> None:
|
|
1064
|
+
"""Following the previous cursors of a descending sort returns the same pages, with the resources without value first."""
|
|
1065
|
+
self.require(storage.supports_cursors, "cursor pagination")
|
|
1066
|
+
self.require(self.announces(provider, "sort"), "sorting")
|
|
1067
|
+
self.require("nick_name" in user_model.model_fields, "nickName")
|
|
1068
|
+
for user_name, nick_name in [
|
|
1069
|
+
("alice", "a"),
|
|
1070
|
+
("bob", None),
|
|
1071
|
+
("carol", "c"),
|
|
1072
|
+
("dave", "b"),
|
|
1073
|
+
("erin", None),
|
|
1074
|
+
]:
|
|
1075
|
+
storage.create(
|
|
1076
|
+
user_type, user_model(user_name=user_name, nick_name=nick_name)
|
|
1077
|
+
)
|
|
1078
|
+
|
|
1079
|
+
search_request = self.search_request(
|
|
1080
|
+
[user_model],
|
|
1081
|
+
cursor="",
|
|
1082
|
+
count=2,
|
|
1083
|
+
sort_by="nickName",
|
|
1084
|
+
sort_order="descending",
|
|
1085
|
+
)
|
|
1086
|
+
forward = self.walk(storage, [user_type], search_request)
|
|
1087
|
+
backward = self.walk_back(storage, [user_type], search_request, forward[-1])
|
|
1088
|
+
|
|
1089
|
+
names = [r.user_name for page in forward for r in page.resources]
|
|
1090
|
+
assert sorted(names[:2]) == ["bob", "erin"]
|
|
1091
|
+
assert names[2:] == ["carol", "dave", "alice"]
|
|
1092
|
+
assert [[r.id for r in page.resources] for page in reversed(backward)] == [
|
|
1093
|
+
[r.id for r in page.resources] for page in forward[:-1]
|
|
1094
|
+
]
|
|
1095
|
+
assert backward[-1].previous is None
|
|
1096
|
+
|
|
1097
|
+
def test_cursor_pages_by_date(
|
|
1098
|
+
self,
|
|
1099
|
+
storage: Any,
|
|
1100
|
+
provider: ScimProvider,
|
|
1101
|
+
user_type: ResourceType,
|
|
1102
|
+
user_model: Any,
|
|
1103
|
+
) -> None:
|
|
1104
|
+
"""A cursor pages a search sorted by date, in both directions.
|
|
1105
|
+
|
|
1106
|
+
Resources modified at the same time may come in any order.
|
|
1107
|
+
"""
|
|
1108
|
+
self.require(storage.supports_cursors, "cursor pagination")
|
|
1109
|
+
self.require(self.announces(provider, "sort"), "sorting")
|
|
1110
|
+
self.require(self.stores_last_modified, "meta.lastModified")
|
|
1111
|
+
created = self.create_users(
|
|
1112
|
+
storage, user_type, user_model, "alice", "bob", "carol", "dave", "erin"
|
|
1113
|
+
)
|
|
1114
|
+
search_request = self.search_request(
|
|
1115
|
+
[user_model], cursor="", count=2, sort_by="meta.lastModified"
|
|
1116
|
+
)
|
|
1117
|
+
first = self.search_or_skip(storage, [user_type], search_request)
|
|
1118
|
+
forward = [first]
|
|
1119
|
+
while forward[-1].next is not None:
|
|
1120
|
+
forward.append(
|
|
1121
|
+
self.search(storage, [user_type], search_request, forward[-1].next)
|
|
1122
|
+
)
|
|
1123
|
+
|
|
1124
|
+
backward = self.walk_back(storage, [user_type], search_request, forward[-1])
|
|
1125
|
+
|
|
1126
|
+
dates = [r.meta.last_modified for page in forward for r in page.resources]
|
|
1127
|
+
assert sorted(self.ids(forward)) == sorted(user.id for user in created)
|
|
1128
|
+
assert dates == sorted(dates)
|
|
1129
|
+
assert [[r.id for r in page.resources] for page in reversed(backward)] == [
|
|
1130
|
+
[r.id for r in page.resources] for page in forward[:-1]
|
|
1131
|
+
]
|
|
1132
|
+
assert backward[-1].previous is None
|
|
1133
|
+
|
|
1031
1134
|
def test_operation(
|
|
1032
1135
|
self, storage: Any, user_type: ResourceType, user_model: Any
|
|
1033
1136
|
) -> None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{scim2_server-0.8.7 → scim2_server-0.8.8}/scim2_server/resources/default-resource-types.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|