Refactor integration tests to share assertions and reduce API calls - #160
Merged
Merged
Conversation
The integration suites only reached search_items, get_items, get_variations and get_browse_nodes, and each one wrote its own assertions, so the sync and the async clients were not held to the same contract and feeds and reports were never checked against the real API. Both suites now share tests/integration_support.py, which holds the credentials, the snapshot of the results and every assertion, and each suite only builds its client and makes the calls. The calls carry as much as they can instead of being repeated: - The search is also the discovery call, and asks with an availability, a condition and a sort so the request is validated by Amazon as well. - A single get_items mixes a URL, a duplicate and an unknown identifier, so one request checks the parsing of URLs, the removal of duplicates, the order of the answer, its partial errors and the placeholders added by include_unavailable. - Variations and browse nodes reuse the parent ASIN and the node identifiers of the search, and are skipped instead of asked for when the search found none, so no request is spent on a call known to fail. - Feeds and reports are listed and downloaded, reporting an account without access to them as a skip instead of failing the suite. - Releasing the connections, dropping the token and using the async client outside its context manager are folded into the calls above, so they cost no request of their own. The async suite also stops making its calls while the module is imported, which ran them even when the tests were deselected and turned a failure into a collection error, and it no longer spends an extra search on checking its context manager. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ZLhDcp9SziFvYduax9evq
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ZLhDcp9SziFvYduax9evq
Both branches added entries to the Unreleased section of the changelog, so the ones of the documentation review and the ones of the integration tests are kept together. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ZLhDcp9SziFvYduax9evq
The name-tests-test hook asks every file under tests to be named after the pattern of a test module, and tests/integration_support.py is the support shared by both integration suites, holding no test of its own. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ZLhDcp9SziFvYduax9evq
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR refactors the integration test suites for both sync and async clients to eliminate code duplication and significantly reduce the number of API calls made during testing. The changes extract shared test logic into a new
integration_support.pymodule that both test suites inherit from, while restructuring how API calls are made and cached.Key Changes
New
tests/integration_support.pymodule: Contains all shared integration test infrastructure including:CredentialsandApiSnapshotdataclasses for managing test dataIntegrationAssertionsbase class with 20+ shared test methodsRefactored sync test suite (
tests/amazon_creatorsapi/integration_test.py):IntegrationAssertionscollect_snapshot()functionsetUpClassto collect snapshot once, then all tests read from cacheRefactored async test suite (
tests/amazon_creatorsapi/aio/integration_test.py):collect_snapshot()that manages connection poolingOptimized API call strategy:
get_itemscall mixes URLs, duplicates, and missing ASINs to test parsing and error handlingNotable Implementation Details
ApiSnapshotdataclass caches all results, allowing tests to run without network accesspick_item_asins()andbuild_item_ids()encapsulate the logic for selecting test datahttps://claude.ai/code/session_017ZLhDcp9SziFvYduax9evq