Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dbutenhof committed May 2, 2023
1 parent ec78160 commit b1398ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/pbench/server/api/resources/datasets_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ def get_paginated_obj(
parsed_url = urlparse(url)
next_url = parsed_url._replace(query=urlencode_json(json)).geturl()
else:
if limit:
raw["offset"] = str(total_count)
next_url = ""

paginated_result["parameters"] = raw
Expand Down
16 changes: 14 additions & 2 deletions lib/pbench/test/unit/server/test_datasets_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,14 @@ def convert(k: str, v: Any) -> Any:
return v

results: list[JSON] = []
offset = int(query.get("offset", 0))
offset = int(query.get("offset", "0"))
limit = query.get("limit")

if limit:
next_offset = offset + int(limit)
paginated_name_list = name_list[offset:next_offset]
if next_offset >= len(name_list):
query["offset"] = str(len(name_list))
next_url = ""
else:
query["offset"] = str(next_offset)
Expand All @@ -167,7 +168,7 @@ def convert(k: str, v: Any) -> Any:
"dataset.uploaded": datetime.datetime.isoformat(
dataset.uploaded
)
},
}
}
)
q1 = {k: convert(k, v) for k, v in query.items()}
Expand Down Expand Up @@ -273,6 +274,17 @@ def compare_results(
def test_dataset_list(self, server_config, query_as, login, query, results):
"""Test `datasets/list` filters
NOTE: Several of these queries use the "limit" and/or "offset" options
to test how the result set is segmented during pagination. These are
represented in the parametrization above interchangeably as integers or
strings. This is because (1) the actual input to the Pbench Server API
is always in string form as a URI query parameter but (2) the requests
package understands this and stringifies integer parameters while (3)
the Pbench Server API framework recognizes these are integer values and
presents them to the API code as integers. Mixing integer and string
representation here must have no impact on the operation of the API so
it's worth testing.
Args:
server_config: The PbenchServerConfig object
query_as: A fixture to provide a helper that executes the API call
Expand Down

0 comments on commit b1398ff

Please sign in to comment.