Refs #31040 -- Used 402 HTTP status in middleware_exceptions tests.
HTTP status code 418 - "I'm a Teaport" was added to http.HTTPStatus in Python 3.9.0a5 [1] that caused failures in middleware_exceptions tests. This changes HTTP status used in middleware_exceptions tests to 402, which exists in all supported versions of Python. [1] https://docs.python.org/3.9/whatsnew/3.9.html#http
This commit is contained in:
parent
8aa71f4e87
commit
195e0cb170
|
@ -96,18 +96,18 @@ class NotFoundMiddleware(BaseMiddleware):
|
||||||
raise Http404('not found')
|
raise Http404('not found')
|
||||||
|
|
||||||
|
|
||||||
class TeapotMiddleware(BaseMiddleware):
|
class PaymentMiddleware(BaseMiddleware):
|
||||||
def __call__(self, request):
|
def __call__(self, request):
|
||||||
response = self.get_response(request)
|
response = self.get_response(request)
|
||||||
response.status_code = 418
|
response.status_code = 402
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@async_only_middleware
|
@async_only_middleware
|
||||||
def async_teapot_middleware(get_response):
|
def async_payment_middleware(get_response):
|
||||||
async def middleware(request):
|
async def middleware(request):
|
||||||
response = await get_response(request)
|
response = await get_response(request)
|
||||||
response.status_code = 418
|
response.status_code = 402
|
||||||
return response
|
return response
|
||||||
|
|
||||||
return middleware
|
return middleware
|
||||||
|
@ -119,7 +119,7 @@ class SyncAndAsyncMiddleware(BaseMiddleware):
|
||||||
|
|
||||||
|
|
||||||
@sync_only_middleware
|
@sync_only_middleware
|
||||||
class DecoratedTeapotMiddleware(TeapotMiddleware):
|
class DecoratedPaymentMiddleware(PaymentMiddleware):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -188,30 +188,30 @@ class MiddlewareNotUsedTests(SimpleTestCase):
|
||||||
)
|
)
|
||||||
class MiddlewareSyncAsyncTests(SimpleTestCase):
|
class MiddlewareSyncAsyncTests(SimpleTestCase):
|
||||||
@override_settings(MIDDLEWARE=[
|
@override_settings(MIDDLEWARE=[
|
||||||
'middleware_exceptions.middleware.TeapotMiddleware',
|
'middleware_exceptions.middleware.PaymentMiddleware',
|
||||||
])
|
])
|
||||||
def test_sync_teapot_middleware(self):
|
def test_sync_middleware(self):
|
||||||
response = self.client.get('/middleware_exceptions/view/')
|
response = self.client.get('/middleware_exceptions/view/')
|
||||||
self.assertEqual(response.status_code, 418)
|
self.assertEqual(response.status_code, 402)
|
||||||
|
|
||||||
@override_settings(MIDDLEWARE=[
|
@override_settings(MIDDLEWARE=[
|
||||||
'middleware_exceptions.middleware.DecoratedTeapotMiddleware',
|
'middleware_exceptions.middleware.DecoratedPaymentMiddleware',
|
||||||
])
|
])
|
||||||
def test_sync_decorated_teapot_middleware(self):
|
def test_sync_decorated_middleware(self):
|
||||||
response = self.client.get('/middleware_exceptions/view/')
|
response = self.client.get('/middleware_exceptions/view/')
|
||||||
self.assertEqual(response.status_code, 418)
|
self.assertEqual(response.status_code, 402)
|
||||||
|
|
||||||
@override_settings(MIDDLEWARE=[
|
@override_settings(MIDDLEWARE=[
|
||||||
'middleware_exceptions.middleware.async_teapot_middleware',
|
'middleware_exceptions.middleware.async_payment_middleware',
|
||||||
])
|
])
|
||||||
def test_async_teapot_middleware(self):
|
def test_async_middleware(self):
|
||||||
with self.assertLogs('django.request', 'DEBUG') as cm:
|
with self.assertLogs('django.request', 'DEBUG') as cm:
|
||||||
response = self.client.get('/middleware_exceptions/view/')
|
response = self.client.get('/middleware_exceptions/view/')
|
||||||
self.assertEqual(response.status_code, 418)
|
self.assertEqual(response.status_code, 402)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
cm.records[0].getMessage(),
|
cm.records[0].getMessage(),
|
||||||
"Synchronous middleware "
|
"Synchronous middleware "
|
||||||
"middleware_exceptions.middleware.async_teapot_middleware "
|
"middleware_exceptions.middleware.async_payment_middleware "
|
||||||
"adapted.",
|
"adapted.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -228,28 +228,28 @@ class MiddlewareSyncAsyncTests(SimpleTestCase):
|
||||||
self.client.get('/middleware_exceptions/view/')
|
self.client.get('/middleware_exceptions/view/')
|
||||||
|
|
||||||
@override_settings(MIDDLEWARE=[
|
@override_settings(MIDDLEWARE=[
|
||||||
'middleware_exceptions.middleware.TeapotMiddleware',
|
'middleware_exceptions.middleware.PaymentMiddleware',
|
||||||
])
|
])
|
||||||
async def test_sync_teapot_middleware_async(self):
|
async def test_sync_middleware_async(self):
|
||||||
with self.assertLogs('django.request', 'DEBUG') as cm:
|
with self.assertLogs('django.request', 'DEBUG') as cm:
|
||||||
response = await self.async_client.get('/middleware_exceptions/view/')
|
response = await self.async_client.get('/middleware_exceptions/view/')
|
||||||
self.assertEqual(response.status_code, 418)
|
self.assertEqual(response.status_code, 402)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
cm.records[0].getMessage(),
|
cm.records[0].getMessage(),
|
||||||
"Asynchronous middleware "
|
"Asynchronous middleware "
|
||||||
"middleware_exceptions.middleware.TeapotMiddleware adapted.",
|
"middleware_exceptions.middleware.PaymentMiddleware adapted.",
|
||||||
)
|
)
|
||||||
|
|
||||||
@override_settings(MIDDLEWARE=[
|
@override_settings(MIDDLEWARE=[
|
||||||
'middleware_exceptions.middleware.async_teapot_middleware',
|
'middleware_exceptions.middleware.async_payment_middleware',
|
||||||
])
|
])
|
||||||
async def test_async_teapot_middleware_async(self):
|
async def test_async_middleware_async(self):
|
||||||
with self.assertLogs('django.request', 'WARNING') as cm:
|
with self.assertLogs('django.request', 'WARNING') as cm:
|
||||||
response = await self.async_client.get('/middleware_exceptions/view/')
|
response = await self.async_client.get('/middleware_exceptions/view/')
|
||||||
self.assertEqual(response.status_code, 418)
|
self.assertEqual(response.status_code, 402)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
cm.records[0].getMessage(),
|
cm.records[0].getMessage(),
|
||||||
'Unknown Status Code: /middleware_exceptions/view/',
|
'Payment Required: /middleware_exceptions/view/',
|
||||||
)
|
)
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
|
|
Loading…
Reference in New Issue