@@ -149,7 +149,7 @@ def test_exception_handler_with_auth_header():
149149 exc .auth_header = 'Bearer realm="api"'
150150 response = exception_handler (exc , {})
151151 assert response .status_code == status .HTTP_401_UNAUTHORIZED
152- assert response ._headers .get ('www-authenticate' , ( None , None ))[ 1 ] == 'Bearer realm="api"'
152+ assert response .headers .get ('www-authenticate' ) == 'Bearer realm="api"'
153153
154154# Test view methods
155155def test_api_view_options_method (api_rf , sample_view ):
@@ -235,8 +235,8 @@ def test_api_view_options_allowed_methods(api_rf, sample_view):
235235 request = api_rf .options ('/' )
236236 response = sample_view .dispatch (request )
237237 assert response .status_code == status .HTTP_200_OK
238- assert 'allow' in response ._headers
239- allow_header = response ._headers ['allow' ][ 1 ].split (', ' )
238+ assert 'allow' in response .headers
239+ allow_header = response .headers ['allow' ].split (', ' )
240240 assert 'GET' in allow_header
241241 assert 'POST' in allow_header
242242 assert 'OPTIONS' in allow_header
@@ -274,7 +274,7 @@ def head(self, request, *args, **kwargs):
274274 head_response = view .dispatch (head_request )
275275
276276 assert head_response .status_code == get_response .status_code
277- assert head_response ._headers == get_response ._headers
277+ assert dict ( head_response .headers ) == dict ( get_response .headers )
278278 assert head_response .content == b''
279279
280280@pytest .mark .django_db
@@ -859,9 +859,9 @@ def get(self, request):
859859
860860 response = view .finalize_response (request , Response ({'message' : 'test' }))
861861
862- assert 'vary' in response ._headers
863- assert 'Accept-Version' in response ._headers ['vary' ][ 1 ]
864- assert response ._headers ['custom-header' ][ 1 ] == 'Value'
862+ assert 'vary' in response .headers
863+ assert 'Accept-Version' in response .headers ['vary' ]
864+ assert response .headers ['custom-header' ] == 'Value'
865865
866866# Test Versioning
867867class CustomURLVersioning (versioning .BaseVersioning ):
@@ -1041,8 +1041,8 @@ def get(self, request, *args, **kwargs):
10411041 request = api_rf .get ('/test/' )
10421042 response = view .dispatch (request )
10431043
1044- assert 'allow' in response ._headers
1045- assert 'GET, OPTIONS' in response ._headers ['allow' ][ 1 ]
1044+ assert 'allow' in response .headers
1045+ assert 'GET, OPTIONS' in response .headers ['allow' ]
10461046
10471047@pytest .mark .django_db
10481048def test_dispatch_with_custom_headers (api_rf ):
@@ -1058,8 +1058,8 @@ def get(self, request, *args, **kwargs):
10581058 request = api_rf .get ('/test/' )
10591059 response = view .dispatch (request )
10601060
1061- assert 'custom-header' in response ._headers
1062- assert response ._headers ['custom-header' ][ 1 ] == 'test-value'
1061+ assert 'custom-header' in response .headers
1062+ assert response .headers ['custom-header' ] == 'test-value'
10631063
10641064# Test raise_uncaught_exception method
10651065@pytest .mark .django_db
@@ -1251,7 +1251,7 @@ def custom_handler(exc, context):
12511251 assert response .status_code == status .HTTP_400_BAD_REQUEST
12521252 assert response .data == {'detail' : 'Custom error' , 'extra' : 'data' }
12531253 assert response .exception is True
1254- assert response ._headers ['custom-header' ] == ( 'Custom-Header' , ' test')
1254+ assert response .headers ['custom-header' ] == ' test'
12551255
12561256# Test exception handler and context logic (lines 456-461)
12571257@pytest .mark .django_db
@@ -2039,13 +2039,13 @@ def get(self, request, *args, **kwargs):
20392039 final_response = view .finalize_response (request , response )
20402040
20412041 # Verify Vary headers were properly handled
2042- assert 'vary' in final_response ._headers
2043- vary_value = final_response ._headers ['vary' ][ 1 ]
2042+ assert 'vary' in final_response .headers
2043+ vary_value = final_response .headers ['vary' ]
20442044 assert 'Accept-Language' in vary_value
20452045 assert 'Cookie' in vary_value
20462046
20472047 # Verify other headers were set
2048- assert final_response ._headers ['custom-header' ] == ( 'Custom-Header' , ' test-value')
2048+ assert final_response .headers ['custom-header' ] == ' test-value'
20492049
20502050def test_finalize_response_multiple_vary_merging ():
20512051 """Test finalize_response merging multiple Vary headers."""
@@ -2077,8 +2077,8 @@ def get(self, request, *args, **kwargs):
20772077 final_response = view .finalize_response (request , response )
20782078
20792079 # Verify all Vary headers were merged
2080- assert 'vary' in final_response ._headers
2081- vary_value = final_response ._headers ['vary' ][ 1 ]
2080+ assert 'vary' in final_response .headers
2081+ vary_value = final_response .headers ['vary' ]
20822082 assert 'Accept' in vary_value
20832083 assert 'Accept-Language' in vary_value
20842084 assert 'Cookie' in vary_value
@@ -2106,8 +2106,8 @@ def get(self, request, *args, **kwargs):
21062106 final_response = view .finalize_response (request , response )
21072107
21082108 # Verify headers were added to HttpResponse
2109- assert final_response ._headers ['custom-header' ] == ( 'Custom-Header' , ' test-value')
2110- assert 'Accept-Language' in final_response ._headers ['vary' ][ 1 ]
2109+ assert final_response .headers ['custom-header' ] == ' test-value'
2110+ assert 'Accept-Language' in final_response .headers ['vary' ]
21112111
21122112def test_handle_exception_not_authenticated_with_auth_header ():
21132113 """Test handle_exception with NotAuthenticated and WWW-Authenticate header."""
0 commit comments