Skip to content

Commit

Permalink
Make next_cursor extraction logic even more robust (ref #1407)
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Oct 5, 2023
1 parent 2caacbb commit 4d58b5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion slack_sdk/web/internal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,10 @@ def _next_cursor_is_present(data) -> bool:
A boolean value.
"""
# Only admin.conversations.search returns next_cursor at the top level
present = ("next_cursor" in data and data["next_cursor"] != "") or (
present = ("next_cursor" in data and data["next_cursor"] is not None and data["next_cursor"] != "") or (
"response_metadata" in data
and "next_cursor" in data["response_metadata"]
and data["response_metadata"]["next_cursor"] is not None
and data["response_metadata"]["next_cursor"] != ""
)
return present
Expand Down
10 changes: 10 additions & 0 deletions tests/slack_sdk/web/test_internal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
_build_unexpected_body_error_message,
_parse_web_class_objects,
_to_v2_file_upload_item,
_next_cursor_is_present,
)


Expand Down Expand Up @@ -98,3 +99,12 @@ def test_files_upload_v2_issue_1356(self):
assert file_io_item.get("filename") == "Uploaded file"
file_io_item = _to_v2_file_upload_item({"file": file_io, "filename": "foo.txt"})
assert file_io_item.get("filename") == "foo.txt"

def test_next_cursor_is_present(self):
assert _next_cursor_is_present({"next_cursor": "next-page"}) is True
assert _next_cursor_is_present({"next_cursor": ""}) is False
assert _next_cursor_is_present({"next_cursor": None}) is False
assert _next_cursor_is_present({"response_metadata": {"next_cursor": "next-page"}}) is True
assert _next_cursor_is_present({"response_metadata": {"next_cursor": ""}}) is False
assert _next_cursor_is_present({"response_metadata": {"next_cursor": None}}) is False
assert _next_cursor_is_present({"something_else": {"next_cursor": "next-page"}}) is False

0 comments on commit 4d58b5b

Please sign in to comment.