fix(tests): set numeric status_code on mocked requests.get#17
Open
kevinypfan wants to merge 1 commit into
Open
fix(tests): set numeric status_code on mocked requests.get#17kevinypfan wants to merge 1 commit into
kevinypfan wants to merge 1 commit into
Conversation
…client
The tests in tests/test_http_client.py patched requests.get with a bare
MagicMock via `mocker.patch('requests.get')`. BaseRest.request now performs
an HTTP error check (`response.status_code >= 400`) in
fugle_marketdata/rest/base_rest.py. Because the bare mock's `.status_code`
is itself a MagicMock, that comparison raised
`TypeError: '>=' not supported between instances of 'MagicMock' and 'int'`,
causing ~43 tests to fail. This is a test-mock defect, not a library bug;
raising on HTTP >= 400 is legitimate behavior and is left unchanged.
Fix: add a `mock_requests_get(mocker)` helper that patches requests.get and
sets a numeric `status_code` (200) on the mocked response, then route all
inline patch sites through it. Keeps every assertion intact and exercises the
intended success path. DRY single source of mock configuration.
Before: tests/test_http_client.py 26 passed / 43 failed.
After: tests/test_http_client.py 69 passed / 0 failed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Why
A prior commit added an HTTP error check
response.status_code >= 400infugle_marketdata/rest/base_rest.py, but ~43 tests intests/test_http_client.pypatchrequests.getwith a bareMagicMockwhose.status_codeis a MagicMock — comparing it to an int raisedTypeError: '>=' not supported between MagicMock and int, breaking the suite.Fix
Added one DRY helper
mock_requests_get(mocker)that patchesrequests.getand setsstatus_code = 200, routed every inline patch site through it. Library untouched (raising on >= 400 is legitimate); no assertions weakened.tests/test_http_client.py: 26 passed / 43 failed → 69 passed / 0 failed.🤖 Generated with Claude Code