From 1b23cd8b77a8ce257c92aed7d297c7098b56d639 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Thu, 12 Jan 2023 21:41:13 -0800 Subject: [PATCH] Remove support for looking up headers on django <3.2 --- project/tests/test_compat.py | 15 --------------- silk/model_factory.py | 14 +------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/project/tests/test_compat.py b/project/tests/test_compat.py index 299797df..8deb3458 100644 --- a/project/tests/test_compat.py +++ b/project/tests/test_compat.py @@ -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, '') diff --git a/silk/model_factory.py b/silk/model_factory.py index 1ab8566d..59c57f51 100644 --- a/silk/model_factory.py +++ b/silk/model_factory.py @@ -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): @@ -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: