1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Refs #33476 -- Reformatted code with Black.

This commit is contained in:
django-bot
2022-02-03 20:24:19 +01:00
committed by Mariusz Felisiak
parent f68fa8b45d
commit 9c19aff7c7
1992 changed files with 139577 additions and 96284 deletions

View File

@@ -6,39 +6,39 @@ from django.http.request import MediaType
class MediaTypeTests(TestCase):
def test_empty(self):
for empty_media_type in (None, ''):
for empty_media_type in (None, ""):
with self.subTest(media_type=empty_media_type):
media_type = MediaType(empty_media_type)
self.assertIs(media_type.is_all_types, False)
self.assertEqual(str(media_type), '')
self.assertEqual(repr(media_type), '<MediaType: >')
self.assertEqual(str(media_type), "")
self.assertEqual(repr(media_type), "<MediaType: >")
def test_str(self):
self.assertEqual(str(MediaType('*/*; q=0.8')), '*/*; q=0.8')
self.assertEqual(str(MediaType('application/xml')), 'application/xml')
self.assertEqual(str(MediaType("*/*; q=0.8")), "*/*; q=0.8")
self.assertEqual(str(MediaType("application/xml")), "application/xml")
def test_repr(self):
self.assertEqual(repr(MediaType('*/*; q=0.8')), '<MediaType: */*; q=0.8>')
self.assertEqual(repr(MediaType("*/*; q=0.8")), "<MediaType: */*; q=0.8>")
self.assertEqual(
repr(MediaType('application/xml')),
'<MediaType: application/xml>',
repr(MediaType("application/xml")),
"<MediaType: application/xml>",
)
def test_is_all_types(self):
self.assertIs(MediaType('*/*').is_all_types, True)
self.assertIs(MediaType('*/*; q=0.8').is_all_types, True)
self.assertIs(MediaType('text/*').is_all_types, False)
self.assertIs(MediaType('application/xml').is_all_types, False)
self.assertIs(MediaType("*/*").is_all_types, True)
self.assertIs(MediaType("*/*; q=0.8").is_all_types, True)
self.assertIs(MediaType("text/*").is_all_types, False)
self.assertIs(MediaType("application/xml").is_all_types, False)
def test_match(self):
tests = [
('*/*; q=0.8', '*/*'),
('*/*', 'application/json'),
(' */* ', 'application/json'),
('application/*', 'application/json'),
('application/xml', 'application/xml'),
(' application/xml ', 'application/xml'),
('application/xml', ' application/xml '),
("*/*; q=0.8", "*/*"),
("*/*", "application/json"),
(" */* ", "application/json"),
("application/*", "application/json"),
("application/xml", "application/xml"),
(" application/xml ", "application/xml"),
("application/xml", " application/xml "),
]
for accepted_type, mime_type in tests:
with self.subTest(accepted_type, mime_type=mime_type):
@@ -46,11 +46,11 @@ class MediaTypeTests(TestCase):
def test_no_match(self):
tests = [
(None, '*/*'),
('', '*/*'),
('; q=0.8', '*/*'),
('application/xml', 'application/html'),
('application/xml', '*/*'),
(None, "*/*"),
("", "*/*"),
("; q=0.8", "*/*"),
("application/xml", "application/html"),
("application/xml", "*/*"),
]
for accepted_type, mime_type in tests:
with self.subTest(accepted_type, mime_type=mime_type):
@@ -63,39 +63,41 @@ class AcceptHeaderTests(TestCase):
request = HttpRequest()
self.assertEqual(
[str(accepted_type) for accepted_type in request.accepted_types],
['*/*'],
["*/*"],
)
def test_accept_headers(self):
request = HttpRequest()
request.META['HTTP_ACCEPT'] = (
'text/html, application/xhtml+xml,application/xml ;q=0.9,*/*;q=0.8'
)
request.META[
"HTTP_ACCEPT"
] = "text/html, application/xhtml+xml,application/xml ;q=0.9,*/*;q=0.8"
self.assertEqual(
[str(accepted_type) for accepted_type in request.accepted_types],
[
'text/html',
'application/xhtml+xml',
'application/xml; q=0.9',
'*/*; q=0.8',
"text/html",
"application/xhtml+xml",
"application/xml; q=0.9",
"*/*; q=0.8",
],
)
def test_request_accepts_any(self):
request = HttpRequest()
request.META['HTTP_ACCEPT'] = '*/*'
self.assertIs(request.accepts('application/json'), True)
request.META["HTTP_ACCEPT"] = "*/*"
self.assertIs(request.accepts("application/json"), True)
def test_request_accepts_none(self):
request = HttpRequest()
request.META['HTTP_ACCEPT'] = ''
self.assertIs(request.accepts('application/json'), False)
request.META["HTTP_ACCEPT"] = ""
self.assertIs(request.accepts("application/json"), False)
self.assertEqual(request.accepted_types, [])
def test_request_accepts_some(self):
request = HttpRequest()
request.META['HTTP_ACCEPT'] = 'text/html,application/xhtml+xml,application/xml;q=0.9'
self.assertIs(request.accepts('text/html'), True)
self.assertIs(request.accepts('application/xhtml+xml'), True)
self.assertIs(request.accepts('application/xml'), True)
self.assertIs(request.accepts('application/json'), False)
request.META[
"HTTP_ACCEPT"
] = "text/html,application/xhtml+xml,application/xml;q=0.9"
self.assertIs(request.accepts("text/html"), True)
self.assertIs(request.accepts("application/xhtml+xml"), True)
self.assertIs(request.accepts("application/xml"), True)
self.assertIs(request.accepts("application/json"), False)