summaryrefslogtreecommitdiff
path: root/tests/wsgi
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2022-02-03 20:24:19 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-07 20:37:05 +0100
commit9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch)
treef0506b668a013d0063e5fba3dbf4863b466713ba /tests/wsgi
parentf68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff)
downloaddjango-9c19aff7c7561e3a82978a272ecdaad40dda5c00.tar.gz
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/wsgi')
-rw-r--r--tests/wsgi/tests.py41
-rw-r--r--tests/wsgi/urls.py4
2 files changed, 27 insertions, 18 deletions
diff --git a/tests/wsgi/tests.py b/tests/wsgi/tests.py
index 8ae6296bd1..db46070182 100644
--- a/tests/wsgi/tests.py
+++ b/tests/wsgi/tests.py
@@ -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()
diff --git a/tests/wsgi/urls.py b/tests/wsgi/urls.py
index 57e1ebf01c..b924adea41 100644
--- a/tests/wsgi/urls.py
+++ b/tests/wsgi/urls.py
@@ -7,6 +7,6 @@ def helloworld(request):
urlpatterns = [
- path('', helloworld),
- path('file/', lambda x: FileResponse(open(__file__, 'rb'))),
+ path("", helloworld),
+ path("file/", lambda x: FileResponse(open(__file__, "rb"))),
]