Skip to content

fix(tests): set numeric status_code on mocked requests.get#17

Open
kevinypfan wants to merge 1 commit into
mainfrom
fix/rest-test-mocks
Open

fix(tests): set numeric status_code on mocked requests.get#17
kevinypfan wants to merge 1 commit into
mainfrom
fix/rest-test-mocks

Conversation

@kevinypfan

Copy link
Copy Markdown
Collaborator

Why

A prior commit added an HTTP error check response.status_code >= 400 in fugle_marketdata/rest/base_rest.py, but ~43 tests in tests/test_http_client.py patch requests.get with a bare MagicMock whose .status_code is a MagicMock — comparing it to an int raised TypeError: '>=' not supported between MagicMock and int, breaking the suite.

Fix

Added one DRY helper mock_requests_get(mocker) that patches requests.get and sets status_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.

Note: 10 unrelated pre-existing failures remain elsewhere (test_base_rest.py error-message mismatch ×9, test_fugle_realtime.py::test_version ×1) — out of scope here.

🤖 Generated with Claude Code

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant