Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/requests/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def info(self):
return self._headers

def getheaders(self, name):
self._headers.getheaders(name)
return self._headers.getheaders(name)


def extract_cookies_to_jar(jar, request, response):
Expand Down
44 changes: 44 additions & 0 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,50 @@ class MyCookiePolicy(cookielib.DefaultCookiePolicy):
jar.set_policy(MyCookiePolicy())
assert isinstance(jar.copy().get_policy(), MyCookiePolicy)

def test_mock_response_getheaders_returns_headers_list(self):
"""Test that MockResponse.getheaders() returns the list of headers."""
from http.client import HTTPMessage
from requests.cookies import MockResponse

# Create a mock HTTPMessage with getheaders method
mock_headers = mock.Mock(spec=HTTPMessage)
mock_headers.getheaders = mock.Mock(
return_value=["cookie1=value1", "cookie2=value2"]
)

# Create MockResponse
mock_response = MockResponse(mock_headers)

# Test that getheaders returns a result (not None)
result = mock_response.getheaders("Set-Cookie")
assert result is not None, "getheaders() should return a value, not None"
assert isinstance(result, list), "getheaders() should return a list"
assert result == ["cookie1=value1", "cookie2=value2"]

# Verify that the underlying getheaders method was called with correct argument
mock_headers.getheaders.assert_called_once_with("Set-Cookie")

def test_mock_response_getheaders_returns_empty_list(self):
"""Test that MockResponse.getheaders() returns an empty list when no headers match."""
from http.client import HTTPMessage
from requests.cookies import MockResponse

# Create a mock HTTPMessage with getheaders method returning empty list
mock_headers = mock.Mock(spec=HTTPMessage)
mock_headers.getheaders = mock.Mock(return_value=[])

# Create MockResponse
mock_response = MockResponse(mock_headers)

# Test that getheaders returns an empty list (not None)
result = mock_response.getheaders("NonExistent-Header")
assert result is not None, "getheaders() should return a list, not None"
assert isinstance(result, list), "getheaders() should return a list"
assert len(result) == 0, "getheaders() should return an empty list"

# Verify that the underlying getheaders method was called with correct argument
mock_headers.getheaders.assert_called_once_with("NonExistent-Header")

def test_time_elapsed_blank(self, httpbin):
r = requests.get(httpbin("get"))
td = r.elapsed
Expand Down