-
Notifications
You must be signed in to change notification settings - Fork 2
test(core): add regression tests for incorrect pagination cursor extraction #17
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a422ca3
test(core): port general behavior tests from TypeScript SDK
niklashigi 1d92975
Run tests in CI
niklashigi 23abbaf
Fix snapshots
niklashigi 0b81e4a
Add Mise tasks
niklashigi 05f6331
Add Python to Mise config
niklashigi ac71f83
Unify Python versions
niklashigi 072e8f7
Add `AGENTS.md` to explain testing
niklashigi 959399e
Deslop
niklashigi 45a903b
Add additional dev deps to Speakeasy config
niklashigi 3f1b6ea
Clean up #1
niklashigi cf19d99
Cleanup #2
niklashigi 38aca2e
Merge branch 'main' into test/core/clean-up-structure
niklashigi f6bee8a
test(core): add regression tests for incorrect pagination cursor extr…
niklashigi a9830a9
Merge branch 'main' into test/core/pagination-cursor-regression
niklashigi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,355 @@ | ||
| """Tests for pagination behavior.""" | ||
|
|
||
| from datetime import datetime | ||
| from tests.conftest import MockContext | ||
|
|
||
|
|
||
| class TestPaginationBehavior: | ||
| """Test pagination behavior.""" | ||
|
|
||
| def test_should_iterate_through_multiple_pages(self): | ||
| """Test that SDK can iterate through multiple pages of results.""" | ||
| ctx = MockContext() | ||
|
|
||
| # Mock 3 pages of results | ||
| ctx.mock_endpoint( | ||
| method="GET", | ||
| path="/v1/ats/tags", | ||
| response={ | ||
| "body": { | ||
| "status": "success", | ||
| "data": { | ||
| "results": [ | ||
| { | ||
| "id": "tag1", | ||
| "remote_id": None, | ||
| "name": "Tag 1", | ||
| "changed_at": "2024-01-01T00:00:00.000Z", | ||
| "remote_deleted_at": None, | ||
| }, | ||
| { | ||
| "id": "tag2", | ||
| "remote_id": None, | ||
| "name": "Tag 2", | ||
| "changed_at": "2024-01-01T00:00:00.000Z", | ||
| "remote_deleted_at": None, | ||
| }, | ||
| ], | ||
| "next": "cursor_page2", | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| ctx.mock_endpoint( | ||
| method="GET", | ||
| path="/v1/ats/tags", | ||
| response={ | ||
| "body": { | ||
| "status": "success", | ||
| "data": { | ||
| "results": [ | ||
| { | ||
| "id": "tag3", | ||
| "remote_id": None, | ||
| "name": "Tag 3", | ||
| "changed_at": "2024-01-01T00:00:00.000Z", | ||
| "remote_deleted_at": None, | ||
| }, | ||
| { | ||
| "id": "tag4", | ||
| "remote_id": None, | ||
| "name": "Tag 4", | ||
| "changed_at": "2024-01-01T00:00:00.000Z", | ||
| "remote_deleted_at": None, | ||
| }, | ||
| ], | ||
| "next": "cursor_page3", | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| ctx.mock_endpoint( | ||
| method="GET", | ||
| path="/v1/ats/tags", | ||
| response={ | ||
| "body": { | ||
| "status": "success", | ||
| "data": { | ||
| "results": [ | ||
| { | ||
| "id": "tag5", | ||
| "remote_id": None, | ||
| "name": "Tag 5", | ||
| "changed_at": "2024-01-01T00:00:00.000Z", | ||
| "remote_deleted_at": None, | ||
| }, | ||
| ], | ||
| "next": None, | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| page = ctx.kombo.ats.get_tags() | ||
| all_results = [] | ||
|
|
||
| # Iterate through all pages | ||
| while page is not None: | ||
| all_results.extend(page.result.data.results) | ||
| page = page.next() | ||
|
|
||
| # Verify all 5 tags were collected | ||
| assert len(all_results) == 5 | ||
| assert [tag.id for tag in all_results] == ["tag1", "tag2", "tag3", "tag4", "tag5"] | ||
|
|
||
| # Verify 3 HTTP requests were made | ||
| requests = ctx.get_requests() | ||
| assert len(requests) == 3 | ||
|
|
||
| def test_should_pass_cursor_parameter_to_subsequent_requests(self): | ||
| """Test that cursor parameter is passed to subsequent paginated requests.""" | ||
| ctx = MockContext() | ||
|
|
||
| ctx.mock_endpoint( | ||
| method="GET", | ||
| path="/v1/ats/tags", | ||
| response={ | ||
| "body": { | ||
| "status": "success", | ||
| "data": { | ||
| "results": [ | ||
| { | ||
| "id": "tag1", | ||
| "remote_id": None, | ||
| "name": "Tag 1", | ||
| "changed_at": "2024-01-01T00:00:00.000Z", | ||
| "remote_deleted_at": None, | ||
| }, | ||
| ], | ||
| "next": "test_cursor_abc123", | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| ctx.mock_endpoint( | ||
| method="GET", | ||
| path="/v1/ats/tags", | ||
| response={ | ||
| "body": { | ||
| "status": "success", | ||
| "data": { | ||
| "results": [ | ||
| { | ||
| "id": "tag2", | ||
| "remote_id": None, | ||
| "name": "Tag 2", | ||
| "changed_at": "2024-01-01T00:00:00.000Z", | ||
| "remote_deleted_at": None, | ||
| }, | ||
| ], | ||
| "next": None, | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| page = ctx.kombo.ats.get_tags() | ||
| # Iterate through all pages | ||
| while page is not None: | ||
| page = page.next() | ||
|
|
||
| requests = ctx.get_requests() | ||
| assert len(requests) == 2 | ||
|
|
||
| # First request should NOT include cursor | ||
| assert "cursor=" not in requests[0].path | ||
|
|
||
| # Second request SHOULD include cursor | ||
| assert "cursor=test_cursor_abc123" in requests[1].path | ||
|
|
||
| def test_should_stop_pagination_when_next_is_null(self): | ||
| """Test that pagination stops when next cursor is null.""" | ||
| ctx = MockContext() | ||
|
|
||
| ctx.mock_endpoint( | ||
| method="GET", | ||
| path="/v1/ats/tags", | ||
| response={ | ||
| "body": { | ||
| "status": "success", | ||
| "data": { | ||
| "results": [ | ||
| { | ||
| "id": "tag1", | ||
| "remote_id": None, | ||
| "name": "Tag 1", | ||
| "changed_at": "2024-01-01T00:00:00.000Z", | ||
| "remote_deleted_at": None, | ||
| }, | ||
| { | ||
| "id": "tag2", | ||
| "remote_id": None, | ||
| "name": "Tag 2", | ||
| "changed_at": "2024-01-01T00:00:00.000Z", | ||
| "remote_deleted_at": None, | ||
| }, | ||
| ], | ||
| "next": None, | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| page = ctx.kombo.ats.get_tags() | ||
| page_count = [] | ||
|
|
||
| while page is not None: | ||
| page_count.append(1) | ||
| page = page.next() | ||
|
|
||
| # Verify only 1 page was returned | ||
| assert len(page_count) == 1 | ||
|
|
||
| # Verify only 1 HTTP request was made | ||
| requests = ctx.get_requests() | ||
| assert len(requests) == 1 | ||
|
|
||
| def test_should_preserve_query_parameters_across_paginated_requests(self): | ||
| """Test that original query parameters are preserved across paginated requests.""" | ||
| ctx = MockContext() | ||
|
|
||
| ctx.mock_endpoint( | ||
| method="GET", | ||
| path="/v1/ats/tags", | ||
| response={ | ||
| "body": { | ||
| "status": "success", | ||
| "data": { | ||
| "results": [ | ||
| { | ||
| "id": "tag1", | ||
| "remote_id": None, | ||
| "name": "Tag 1", | ||
| "changed_at": "2024-01-01T00:00:00.000Z", | ||
| "remote_deleted_at": None, | ||
| }, | ||
| ], | ||
| "next": "cursor_for_page2", | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| ctx.mock_endpoint( | ||
| method="GET", | ||
| path="/v1/ats/tags", | ||
| response={ | ||
| "body": { | ||
| "status": "success", | ||
| "data": { | ||
| "results": [ | ||
| { | ||
| "id": "tag2", | ||
| "remote_id": None, | ||
| "name": "Tag 2", | ||
| "changed_at": "2024-01-01T00:00:00.000Z", | ||
| "remote_deleted_at": None, | ||
| }, | ||
| ], | ||
| "next": None, | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| page = ctx.kombo.ats.get_tags( | ||
| updated_after=datetime(2024, 1, 1, 0, 0, 0) | ||
| ) | ||
|
|
||
| # Iterate through all pages | ||
| while page is not None: | ||
| page = page.next() | ||
|
|
||
| requests = ctx.get_requests() | ||
| assert len(requests) == 2 | ||
|
|
||
| # Both requests should include the original query parameters | ||
| # Check that updated_after parameter is present (URL encoded) | ||
| assert "updated_after=2024-01-01T00%3A00%3A00" in requests[0].path | ||
| assert "cursor=" not in requests[0].path | ||
|
|
||
| assert "updated_after=2024-01-01T00%3A00%3A00" in requests[1].path | ||
| assert "cursor=cursor_for_page2" in requests[1].path | ||
|
|
||
| def test_should_support_manual_pagination_with_next(self): | ||
| """Test that manual pagination works by calling next() method.""" | ||
| ctx = MockContext() | ||
|
|
||
| ctx.mock_endpoint( | ||
| method="GET", | ||
| path="/v1/ats/tags", | ||
| response={ | ||
| "body": { | ||
| "status": "success", | ||
| "data": { | ||
| "results": [ | ||
| { | ||
| "id": "tag1", | ||
| "remote_id": None, | ||
| "name": "Tag 1", | ||
| "changed_at": "2024-01-01T00:00:00.000Z", | ||
| "remote_deleted_at": None, | ||
| }, | ||
| ], | ||
| "next": "manual_cursor_xyz", | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| ctx.mock_endpoint( | ||
| method="GET", | ||
| path="/v1/ats/tags", | ||
| response={ | ||
| "body": { | ||
| "status": "success", | ||
| "data": { | ||
| "results": [ | ||
| { | ||
| "id": "tag2", | ||
| "remote_id": None, | ||
| "name": "Tag 2", | ||
| "changed_at": "2024-01-01T00:00:00.000Z", | ||
| "remote_deleted_at": None, | ||
| }, | ||
| ], | ||
| "next": None, | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| page1 = ctx.kombo.ats.get_tags() | ||
|
|
||
| # Verify first page was fetched | ||
| assert page1.result.data.results is not None | ||
| assert len(page1.result.data.results) == 1 | ||
|
|
||
| # Manually call next() | ||
| page2_result = page1.next() | ||
|
|
||
| # Verify second page was fetched (should not be null if cursor was read correctly) | ||
| # This will fail if cursor extraction bug exists | ||
| assert page2_result is not None | ||
| if page2_result: | ||
| assert len(page2_result.result.data.results) == 1 | ||
| assert page2_result.result.data.results[0].id == "tag2" | ||
|
|
||
| # Verify 2 HTTP requests were made | ||
| requests = ctx.get_requests() | ||
| assert len(requests) == 2 | ||
| assert "cursor=manual_cursor_xyz" in requests[1].path | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Exception handler will re-raise same UnicodeDecodeError
The exception handler catches
UnicodeDecodeErrorfrom thedecode()call on line 95, but then the fallback on line 98 callsrequest.content.decode()again. If the original error was aUnicodeDecodeError, this second decode call will raise the same exception, which won't be caught. The fallback needs to handle the case where the content cannot be decoded as UTF-8, such as by specifying an error handler (e.g.,decode(errors='replace')) or storing raw bytes.