Refs #24121 -- Added __repr__() to MiddlewareMixin and subclasses.
This commit is contained in:
parent
bc43ae7c13
commit
dc86a25a67
|
@ -96,6 +96,16 @@ class MiddlewareMixin:
|
||||||
self._async_check()
|
self._async_check()
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<%s get_response=%s>' % (
|
||||||
|
self.__class__.__qualname__,
|
||||||
|
getattr(
|
||||||
|
self.get_response,
|
||||||
|
'__qualname__',
|
||||||
|
self.get_response.__class__.__name__,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
def _async_check(self):
|
def _async_check(self):
|
||||||
"""
|
"""
|
||||||
If get_response is a coroutine function, turns us into async mode so
|
If get_response is a coroutine function, turns us into async mode so
|
||||||
|
|
|
@ -54,6 +54,33 @@ class MiddlewareMixinTests(SimpleTestCase):
|
||||||
XViewMiddleware,
|
XViewMiddleware,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def test_repr(self):
|
||||||
|
class GetResponse:
|
||||||
|
def __call__(self):
|
||||||
|
return HttpResponse()
|
||||||
|
|
||||||
|
def get_response():
|
||||||
|
return HttpResponse()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
repr(MiddlewareMixin(GetResponse())),
|
||||||
|
'<MiddlewareMixin get_response=GetResponse>',
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
repr(MiddlewareMixin(get_response)),
|
||||||
|
'<MiddlewareMixin get_response='
|
||||||
|
'MiddlewareMixinTests.test_repr.<locals>.get_response>',
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
repr(CsrfViewMiddleware(GetResponse())),
|
||||||
|
'<CsrfViewMiddleware get_response=GetResponse>',
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
repr(CsrfViewMiddleware(get_response)),
|
||||||
|
'<CsrfViewMiddleware get_response='
|
||||||
|
'MiddlewareMixinTests.test_repr.<locals>.get_response>',
|
||||||
|
)
|
||||||
|
|
||||||
def test_passing_explicit_none(self):
|
def test_passing_explicit_none(self):
|
||||||
msg = 'get_response must be provided.'
|
msg = 'get_response must be provided.'
|
||||||
for middleware in self.middlewares:
|
for middleware in self.middlewares:
|
||||||
|
|
Loading…
Reference in New Issue