Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make next_cursor extraction logic even more robust (ref #1407) #1409

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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