FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: avoid deprecated urllib3 header helpers by miachillgood · Pull Request #235 · XeroAPI/xero-python · GitHub

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

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
23 changes: 23 additions & 0 deletions tests/test_api_client/test_rest_response.py
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
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
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
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

Back | FazBrowse Home | New Git URL