Skip to content

Commit

Permalink
Remove support for looking up headers on django <3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
albertyw committed Jan 15, 2023
1 parent 708a36f commit 1b23cd8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 28 deletions.
15 changes: 0 additions & 15 deletions project/tests/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,3 @@ def test_bytes_compat(self):
factory = ResponseModelFactory(mock)
body, content = factory.body()
self.assertDictEqual(json.loads(body), d)

# Testing invalid json throws an exception in the tests
# def test_python3_invalid_content_compat(self):
# """
# Test ResponseModelFactory returns empty string for invalid json
# """
# if sys.version_info >= (3, 0, 0):
# mock = Mock()
# mock.pk = 'test'
# mock._headers = {HTTP_CONTENT_TYPE: 'application/json;'}
# mock.content = b'invalid json'
# mock.get = mock._headers.get
# factory = ResponseModelFactory(mock)
# body, content = factory.body()
# self.assertEqual(body, '')
14 changes: 1 addition & 13 deletions silk/model_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@
content_type_css = ['text/css']


def _get_response_headers(response):
"""
Django 3.2 (more specifically, commit bcc2befd0e9c1885e45b46d0b0bcdc11def8b249) broke the usage of _headers, which
were turned into a public interface, so we need this compatibility wrapper.
"""
try:
return response.headers
except AttributeError:
return response._headers


class DefaultEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, UUID):
Expand Down Expand Up @@ -312,9 +301,8 @@ def construct_response_model(self):
% self.request.pk
)
b, content = self.body()
raw_headers = _get_response_headers(self.response)
headers = {}
for k, v in raw_headers.items():
for k, v in self.response.headers.items():
try:
header, val = v
except ValueError:
Expand Down

0 comments on commit 1b23cd8

Please # to comment.