Skip to content

Commit b1398ff

Browse files
committed
Review comments
1 parent ec78160 commit b1398ff

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/pbench/server/api/resources/datasets_list.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ def get_paginated_obj(
346346
parsed_url = urlparse(url)
347347
next_url = parsed_url._replace(query=urlencode_json(json)).geturl()
348348
else:
349+
if limit:
350+
raw["offset"] = str(total_count)
349351
next_url = ""
350352

351353
paginated_result["parameters"] = raw

lib/pbench/test/unit/server/test_datasets_list.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,14 @@ def convert(k: str, v: Any) -> Any:
139139
return v
140140

141141
results: list[JSON] = []
142-
offset = int(query.get("offset", 0))
142+
offset = int(query.get("offset", "0"))
143143
limit = query.get("limit")
144144

145145
if limit:
146146
next_offset = offset + int(limit)
147147
paginated_name_list = name_list[offset:next_offset]
148148
if next_offset >= len(name_list):
149+
query["offset"] = str(len(name_list))
149150
next_url = ""
150151
else:
151152
query["offset"] = str(next_offset)
@@ -167,7 +168,7 @@ def convert(k: str, v: Any) -> Any:
167168
"dataset.uploaded": datetime.datetime.isoformat(
168169
dataset.uploaded
169170
)
170-
},
171+
}
171172
}
172173
)
173174
q1 = {k: convert(k, v) for k, v in query.items()}
@@ -273,6 +274,17 @@ def compare_results(
273274
def test_dataset_list(self, server_config, query_as, login, query, results):
274275
"""Test `datasets/list` filters
275276
277+
NOTE: Several of these queries use the "limit" and/or "offset" options
278+
to test how the result set is segmented during pagination. These are
279+
represented in the parametrization above interchangeably as integers or
280+
strings. This is because (1) the actual input to the Pbench Server API
281+
is always in string form as a URI query parameter but (2) the requests
282+
package understands this and stringifies integer parameters while (3)
283+
the Pbench Server API framework recognizes these are integer values and
284+
presents them to the API code as integers. Mixing integer and string
285+
representation here must have no impact on the operation of the API so
286+
it's worth testing.
287+
276288
Args:
277289
server_config: The PbenchServerConfig object
278290
query_as: A fixture to provide a helper that executes the API call

0 commit comments

Comments
 (0)