mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
parent
f68fa8b45d
commit
9c19aff7c7
1992 changed files with 139577 additions and 96284 deletions
|
@ -8,7 +8,7 @@ from django.test import SimpleTestCase, override_settings
|
|||
from django.test.client import RequestFactory
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='wsgi.urls')
|
||||
@override_settings(ROOT_URLCONF="wsgi.urls")
|
||||
class WSGITest(SimpleTestCase):
|
||||
request_factory = RequestFactory()
|
||||
|
||||
|
@ -25,9 +25,7 @@ class WSGITest(SimpleTestCase):
|
|||
application = get_wsgi_application()
|
||||
|
||||
environ = self.request_factory._base_environ(
|
||||
PATH_INFO="/",
|
||||
CONTENT_TYPE="text/html; charset=utf-8",
|
||||
REQUEST_METHOD="GET"
|
||||
PATH_INFO="/", CONTENT_TYPE="text/html; charset=utf-8", REQUEST_METHOD="GET"
|
||||
)
|
||||
|
||||
response_data = {}
|
||||
|
@ -41,33 +39,40 @@ class WSGITest(SimpleTestCase):
|
|||
self.assertEqual(response_data["status"], "200 OK")
|
||||
self.assertEqual(
|
||||
set(response_data["headers"]),
|
||||
{('Content-Length', '12'), ('Content-Type', 'text/html; charset=utf-8')})
|
||||
self.assertIn(bytes(response), [
|
||||
b"Content-Length: 12\r\nContent-Type: text/html; charset=utf-8\r\n\r\nHello World!",
|
||||
b"Content-Type: text/html; charset=utf-8\r\nContent-Length: 12\r\n\r\nHello World!"
|
||||
])
|
||||
{("Content-Length", "12"), ("Content-Type", "text/html; charset=utf-8")},
|
||||
)
|
||||
self.assertIn(
|
||||
bytes(response),
|
||||
[
|
||||
b"Content-Length: 12\r\nContent-Type: text/html; charset=utf-8\r\n\r\nHello World!",
|
||||
b"Content-Type: text/html; charset=utf-8\r\nContent-Length: 12\r\n\r\nHello World!",
|
||||
],
|
||||
)
|
||||
|
||||
def test_file_wrapper(self):
|
||||
"""
|
||||
FileResponse uses wsgi.file_wrapper.
|
||||
"""
|
||||
|
||||
class FileWrapper:
|
||||
def __init__(self, filelike, block_size=None):
|
||||
self.block_size = block_size
|
||||
filelike.close()
|
||||
|
||||
application = get_wsgi_application()
|
||||
environ = self.request_factory._base_environ(
|
||||
PATH_INFO='/file/',
|
||||
REQUEST_METHOD='GET',
|
||||
**{'wsgi.file_wrapper': FileWrapper}
|
||||
PATH_INFO="/file/",
|
||||
REQUEST_METHOD="GET",
|
||||
**{"wsgi.file_wrapper": FileWrapper},
|
||||
)
|
||||
response_data = {}
|
||||
|
||||
def start_response(status, headers):
|
||||
response_data['status'] = status
|
||||
response_data['headers'] = headers
|
||||
response_data["status"] = status
|
||||
response_data["headers"] = headers
|
||||
|
||||
response = application(environ, start_response)
|
||||
self.assertEqual(response_data['status'], '200 OK')
|
||||
self.assertEqual(response_data["status"], "200 OK")
|
||||
self.assertIsInstance(response, FileWrapper)
|
||||
self.assertEqual(response.block_size, FileResponse.block_size)
|
||||
|
||||
|
@ -96,7 +101,9 @@ class GetInternalWSGIApplicationTest(SimpleTestCase):
|
|||
|
||||
def mock_get_wsgi_app():
|
||||
return fake_app
|
||||
|
||||
from django.core.servers import basehttp
|
||||
|
||||
_orig_get_wsgi_app = basehttp.get_wsgi_application
|
||||
basehttp.get_wsgi_application = mock_get_wsgi_app
|
||||
|
||||
|
@ -115,6 +122,8 @@ class GetInternalWSGIApplicationTest(SimpleTestCase):
|
|||
|
||||
@override_settings(WSGI_APPLICATION="wsgi.wsgi.noexist")
|
||||
def test_bad_name(self):
|
||||
msg = "WSGI application 'wsgi.wsgi.noexist' could not be loaded; Error importing"
|
||||
msg = (
|
||||
"WSGI application 'wsgi.wsgi.noexist' could not be loaded; Error importing"
|
||||
)
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||
get_internal_wsgi_application()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue