Repository navigation
fix: compare query params order-insensitively in assert_call_count - #825
Open
Shubham-Padkonde wants to merge 3 commits into
Open
Shubham-Padkonde wants to merge 3 commits into
Shubham-Padkonde wants to merge 3 commits into
Conversation
assert_call_count compared the full URL string verbatim, so asserting against http://example.com/api?a=1&b=2 would fail when requests built the URL as ?b=2&a=1 (preserving the dict's insertion order). Fix by splitting each URL into its base and a sorted list of (key, value) pairs before comparing, matching the same order-independent semantics that query_string_matcher and query_param_matcher already use. Closes getsentry#822 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012acaiEt2JyZdUxjQndUWQL
markstory
reviewed
Sep 24, 2026
| responses.add(responses.GET, "http://example.com/api", body="ok") | ||
|
|
||
| # Make a request; requests preserves the insertion order of params. | ||
| requests.get("http://example.com/api", params={"b": "2", "a": "1"}) |
Member
There was a problem hiding this comment.
It would be good to have a test case covering nested structures as well.
Author
There was a problem hiding this comment.
Added three nested-query cases covering bracket-encoded keys, list values, reordered pairs, and percent-encoded names. The tests also ensure missing, changed, and duplicate values do not match. Included the changelog entry and corrected the optional request-URL type handling.
Validation: 255 tests passed; the six focused call-count cases passed after the type adjustment. Black, flake8, and git diff --check passed. Local mypy still reports three errors in unchanged matchers.py and test_recorder.py; no errors remain in the changed files.
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.
assert_call_count compared the full URL string verbatim, so asserting against http://example.com/api?a=1&b=2 would fail when requests built the URL as ?b=2&a=1 (preserving the dict's insertion order).
Fix by splitting each URL into its base and a sorted list of (key, value) pairs before comparing, matching the same order-independent semantics that query_string_matcher and query_param_matcher already use.
Closes #822
Claude-Session: https://claude.ai/code/session_012acaiEt2JyZdUxjQndUWQL
What type of PR is this? (check all applicable)
Refactor
Feature
Bug Fix
Optimization
Documentation Update
Other
Description
Related Issues
PR checklist
Before submitting this pull request, I have done the following:
Read the contributing guidelines
Ran
toxandpre-commitchecks locallyAdded my changes to the CHANGES file
Added/updated tests?
Yes
No, and this is why: <!-- _please replace this line with details on why tests
I need help with writing tests
Latest validation
255 tests passed. Six focused call-count tests passed after optional-URL type handling was corrected. Black, flake8, and git diff --check passed. Local mypy reports three pre-existing errors in unchanged matchers.py and test_recorder.py (also present in the saved baseline). Full tox/pre-commit matrix was not run.