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

Add a test suite verifying #521 fix #1

Merged
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
41 changes: 41 additions & 0 deletions tests/web/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,47 @@ def test_requests_can_be_paginated(self, mock_request):
users = users + page["members"]
self.assertTrue(len(users) == 4)

def test_response_can_be_paginated_multiple_times(self, mock_request):
# This test suite verifies the changes in #521 work as expected
page1 = {
"data": {
"ok": True,
"channels": [{"id": "C1"}],
"response_metadata": {"next_cursor": "has_page2"},
},
"status_code": 200,
"headers": {},
}
page2 = {
"data": {
"ok": True,
"channels": [{"id": "C2"}],
"response_metadata": {"next_cursor": "has_page3"},
},
"status_code": 200,
"headers": {},
}
page3 = {
"data": {"ok": True, "channels": [{"id": "C3"}]},
"status_code": 200,
"headers": {},
}
# The initial pagination
mock_request.response.side_effect = [page1, page2, page3]
response = self.client.channels_list(limit=1)
ids = []
for page in response:
ids.append(page["channels"][0]["id"])
self.assertEqual(ids, ["C1", "C2", "C3"])

# The second iteration starting with page 2
# (page1 is already cached in `response`)
mock_request.response.side_effect = [page2, page3]
ids = []
for page in response:
ids.append(page["channels"][0]["id"])
self.assertEqual(ids, ["C1", "C2", "C3"])

def test_request_pagination_stops_when_next_cursor_is_missing(self, mock_request):
mock_request.response.side_effect = [
{
Expand Down