def process_exception(self, request, exception): # pylint: disable=inconsistent-return-statements """ Exception handler that processes exceptions raised by the axes signal handler when request fails with login. Refer to axes.signals.log_user_login_failed for the error code. :param request: HTTPRequest that will be locked out. :param exception: Exception raised by Django views or signals. Only AxesSignalPermissionDenied will be handled. :return: HTTPResponse that indicates the lockout or None. """ if isinstance(exception, AxesSignalPermissionDenied): return get_lockout_response(request)
def inner(request, *args, **kwargs): if is_already_locked(request): return get_lockout_response(request) return func(request, *args, **kwargs)
def test_get_lockout_response_lockout_response(self): response = get_lockout_response(request=self.request) self.assertEqual(type(response), HttpResponse)
def test_get_lockout_response_lockout_json(self): self.request.is_ajax = lambda: True response = get_lockout_response(request=self.request) self.assertEqual(type(response), JsonResponse)
def test_get_lockout_response_lockout_template(self, render): self.assertFalse(render.called) get_lockout_response(request=self.request) self.assertTrue(render.called)
def test_get_lockout_response_cool_off(self): get_lockout_response(request=self.request)