requests
requests copied to clipboard
Fix MockResponse.getheaders() to return headers list instead of None
Summary
Fixes a bug in MockResponse.getheaders() method where it was not returning the headers list, resulting in None being returned instead.
Problem
The getheaders() method in the MockResponse class (used for cookie extraction) was missing a return statement, causing it to always return None instead of the actual headers list.
Solution
- Added the missing
returnstatement insrc/requests/cookies.pyline 121 - Added comprehensive unit tests to verify the fix:
- Test for successful header retrieval with multiple values
- Test for empty list when no matching headers exist
- Mock validation to ensure proper delegation to underlying HTTPMessage
Changes
-
Modified:
src/requests/cookies.py- Addedreturnstatement toMockResponse.getheaders() -
Added: Two unit tests in
tests/test_requests.py:-
test_mock_response_getheaders_returns_headers_list() -
test_mock_response_getheaders_returns_empty_list()
-
Testing
All new tests pass and verify that:
- The method correctly returns a list of headers when present
- The method returns an empty list (not None) when no headers match
- The underlying HTTPMessage.getheaders() is called with the correct arguments