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
23 changes: 23 additions & 0 deletions tests/test_api_client/test_rest_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from xero_python.rest import RESTResponse


class DummyResponse:
def __init__(self):
self.status = 200
self.reason = "OK"
self.data = b"{}"
self.headers = {
"Content-Disposition": "attachment; filename=test.json",
"X-Trace-Id": "abc123",
}


def test_rest_response_reads_headers_without_deprecated_urllib3_helpers():
response = RESTResponse(DummyResponse())

assert response.getheaders() == {
"Content-Disposition": "attachment; filename=test.json",
"X-Trace-Id": "abc123",
}
assert response.getheader("Content-Disposition") == "attachment; filename=test.json"
assert response.getheader("Missing", "fallback") == "fallback"
4 changes: 2 additions & 2 deletions xero_python/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def text(self):

def getheaders(self):
"""Returns a dictionary of the response headers."""
return self.urllib3_response.getheaders()
return dict(self.urllib3_response.headers.items())

def getheader(self, name, default=None):
"""Returns a given response header."""
return self.urllib3_response.getheader(name, default)
return self.urllib3_response.headers.get(name, default)


class RESTClientObject(object):
Expand Down