Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2eed1b0

Browse files
committed
Add django-upgrade to pre-commit hooks
1 parentea1da76 commit2eed1b0

14 files changed

+36
-30
lines changed

‎.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ repos:
3737
hooks:
3838
-id:pyupgrade
3939
args:["--py39-plus", "--keep-percent-format"]
40+
41+
-repo:https://github.com/adamchainz/django-upgrade
42+
rev:1.24.0
43+
hooks:
44+
-id:django-upgrade
45+
args:[--target-version, "4.2"]

‎rest_framework/authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_authorization_header(request):
1717
1818
Hide some test client ickyness where the header can be unicode.
1919
"""
20-
auth=request.META.get('HTTP_AUTHORIZATION',b'')
20+
auth=request.headers.get('authorization',b'')
2121
ifisinstance(auth,str):
2222
# Work around django test client oddness
2323
auth=auth.encode(HTTP_HEADER_ENCODING)

‎rest_framework/authtoken/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def url_for_result(self, result):
2121
current_app=self.model_admin.admin_site.name)
2222

2323

24+
@admin.register(TokenProxy)
2425
classTokenAdmin(admin.ModelAdmin):
2526
list_display= ('key','user','created')
2627
fields= ('user',)
@@ -51,4 +52,3 @@ def delete_model(self, request, obj):
5152
returnsuper().delete_model(request,token)
5253

5354

54-
admin.site.register(TokenProxy,TokenAdmin)

‎rest_framework/negotiation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@ def get_accept_list(self, request):
9393
Given the incoming request, return a tokenized list of media
9494
type strings.
9595
"""
96-
header=request.META.get('HTTP_ACCEPT','*/*')
96+
header=request.headers.get('accept','*/*')
9797
return [token.strip()fortokeninheader.split(',')]

‎rest_framework/throttling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_ident(self, request):
2626
if present and number of proxies is > 0. If not use all of
2727
HTTP_X_FORWARDED_FOR if it is available, if not use REMOTE_ADDR.
2828
"""
29-
xff=request.META.get('HTTP_X_FORWARDED_FOR')
29+
xff=request.headers.get('x-forwarded-for')
3030
remote_addr=request.META.get('REMOTE_ADDR')
3131
num_proxies=api_settings.NUM_PROXIES
3232

‎tests/test_api_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
fromdjango.httpimportHttpResponse
66
fromdjango.testimportoverride_settings
7-
fromdjango.urlsimportpath,re_path
7+
fromdjango.urlsimportpath
88

99
fromrest_framework.compatimportcoreapi,coreschema
1010
fromrest_framework.parsersimportFileUploadParser
@@ -180,7 +180,7 @@ def get(self, request):
180180
urlpatterns= [
181181
path('',SchemaView.as_view()),
182182
path('example/',ListView.as_view()),
183-
re_path(r'^example/(?P<id>[0-9]+)/$',DetailView.as_view()),
183+
path('example/<int:id>/',DetailView.as_view()),
184184
path('upload/',UploadView.as_view()),
185185
path('download/',DownloadView.as_view()),
186186
path('text/',TextView.as_view()),

‎tests/test_middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_middleware_can_access_user_when_processing_response(self):
102102
key='abcd1234'
103103
Token.objects.create(key=key,user=user)
104104

105-
self.client.get('/auth',HTTP_AUTHORIZATION='Token %s'%key)
105+
self.client.get('/auth',headers={"authorization":'Token %s'%key})
106106

107107
@override_settings(MIDDLEWARE=('tests.test_middleware.RequestPOSTMiddleware',))
108108
deftest_middleware_can_access_request_post_when_processing_response(self):

‎tests/test_relations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from_pytest.monkeypatchimportMonkeyPatch
55
fromdjango.core.exceptionsimportImproperlyConfigured,ObjectDoesNotExist
66
fromdjango.testimportoverride_settings
7-
fromdjango.urlsimportre_path
7+
fromdjango.urlsimportpath
88
fromdjango.utils.datastructuresimportMultiValueDict
99

1010
fromrest_frameworkimportrelations,serializers
@@ -152,7 +152,7 @@ def test_pk_representation(self):
152152

153153

154154
urlpatterns= [
155-
re_path(r'^example/(?P<name>.+)/$',lambda:None,name='example'),
155+
path('example/<path:name>/',lambda:None,name='example'),
156156
]
157157

158158

‎tests/test_renderers.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,30 +174,30 @@ def test_head_method_serializes_no_content(self):
174174

175175
deftest_default_renderer_serializes_content_on_accept_any(self):
176176
"""If the Accept header is set to */* the default renderer should serialize the response."""
177-
resp=self.client.get('/',HTTP_ACCEPT='*/*')
177+
resp=self.client.get('/',headers={"accept":'*/*'})
178178
self.assertEqual(resp['Content-Type'],RendererA.media_type+'; charset=utf-8')
179179
self.assertEqual(resp.content,RENDERER_A_SERIALIZER(DUMMYCONTENT))
180180
self.assertEqual(resp.status_code,DUMMYSTATUS)
181181

182182
deftest_specified_renderer_serializes_content_default_case(self):
183183
"""If the Accept header is set the specified renderer should serialize the response.
184184
(In this case we check that works for the default renderer)"""
185-
resp=self.client.get('/',HTTP_ACCEPT=RendererA.media_type)
185+
resp=self.client.get('/',headers={"accept":RendererA.media_type})
186186
self.assertEqual(resp['Content-Type'],RendererA.media_type+'; charset=utf-8')
187187
self.assertEqual(resp.content,RENDERER_A_SERIALIZER(DUMMYCONTENT))
188188
self.assertEqual(resp.status_code,DUMMYSTATUS)
189189

190190
deftest_specified_renderer_serializes_content_non_default_case(self):
191191
"""If the Accept header is set the specified renderer should serialize the response.
192192
(In this case we check that works for a non-default renderer)"""
193-
resp=self.client.get('/',HTTP_ACCEPT=RendererB.media_type)
193+
resp=self.client.get('/',headers={"accept":RendererB.media_type})
194194
self.assertEqual(resp['Content-Type'],RendererB.media_type+'; charset=utf-8')
195195
self.assertEqual(resp.content,RENDERER_B_SERIALIZER(DUMMYCONTENT))
196196
self.assertEqual(resp.status_code,DUMMYSTATUS)
197197

198198
deftest_unsatisfiable_accept_header_on_request_returns_406_status(self):
199199
"""If the Accept header is unsatisfiable we should return a 406 Not Acceptable response."""
200-
resp=self.client.get('/',HTTP_ACCEPT='foo/bar')
200+
resp=self.client.get('/',headers={"accept":'foo/bar'})
201201
self.assertEqual(resp.status_code,status.HTTP_406_NOT_ACCEPTABLE)
202202

203203
deftest_specified_renderer_serializes_content_on_format_query(self):
@@ -228,14 +228,14 @@ def test_specified_renderer_is_used_on_format_query_with_matching_accept(self):
228228
RendererB.format
229229
)
230230
resp=self.client.get('/'+param,
231-
HTTP_ACCEPT=RendererB.media_type)
231+
headers={"accept":RendererB.media_type})
232232
self.assertEqual(resp['Content-Type'],RendererB.media_type+'; charset=utf-8')
233233
self.assertEqual(resp.content,RENDERER_B_SERIALIZER(DUMMYCONTENT))
234234
self.assertEqual(resp.status_code,DUMMYSTATUS)
235235

236236
deftest_parse_error_renderers_browsable_api(self):
237237
"""Invalid data should still render the browsable API correctly."""
238-
resp=self.client.post('/parseerror',data='foobar',content_type='application/json',HTTP_ACCEPT='text/html')
238+
resp=self.client.post('/parseerror',data='foobar',content_type='application/json',headers={"accept":'text/html'})
239239
self.assertEqual(resp['Content-Type'],'text/html; charset=utf-8')
240240
self.assertEqual(resp.status_code,status.HTTP_400_BAD_REQUEST)
241241

@@ -714,13 +714,13 @@ class DummyView:
714714
assertresultisNone
715715

716716
deftest_extra_actions_dropdown(self):
717-
resp=self.client.get('/api/examples/',HTTP_ACCEPT='text/html')
717+
resp=self.client.get('/api/examples/',headers={"accept":'text/html'})
718718
assert'id="extra-actions-menu"'inresp.content.decode()
719719
assert'/api/examples/list_action/'inresp.content.decode()
720720
assert'>Extra list action<'inresp.content.decode()
721721

722722
deftest_extra_actions_dropdown_not_authed(self):
723-
resp=self.client.get('/api/unauth-examples/',HTTP_ACCEPT='text/html')
723+
resp=self.client.get('/api/unauth-examples/',headers={"accept":'text/html'})
724724
assert'id="extra-actions-menu"'notinresp.content.decode()
725725
assert'/api/examples/list_action/'notinresp.content.decode()
726726
assert'>Extra list action<'notinresp.content.decode()

‎tests/test_requests_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def post(self, request):
2828
}
2929
post=request.POST
3030
json=None
31-
ifrequest.META.get('CONTENT_TYPE')=='application/json':
31+
ifrequest.headers.get('content-type')=='application/json':
3232
json=request.data
3333

3434
returnResponse({

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp