Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for looking up headers on django <3.2 #643

Merged
merged 1 commit into from
Jan 15, 2023
Merged
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
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 @@ -322,9 +311,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