From e4929d2c11b06e5721151947ae39b8b5635ffefe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksi=20Ha=CC=88kli?= Date: Wed, 8 Jan 2020 22:00:33 +0200 Subject: [PATCH] Add missing get_failures handler proxy implementation This missing implementation prevented custom implementations for the failure fetching logic in the handler classes because Axes would not invoke them from them, and would use the base handler class implementation instead. --- axes/handlers/proxy.py | 5 +++++ axes/tests/test_handlers.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/axes/handlers/proxy.py b/axes/handlers/proxy.py index 837a567..25c5650 100644 --- a/axes/handlers/proxy.py +++ b/axes/handlers/proxy.py @@ -82,6 +82,11 @@ class AxesProxyHandler(AxesHandler): cls.update_request(request) return cls.get_implementation().is_allowed(request, credentials) + @classmethod + def get_failures(cls, request, credentials: dict = None) -> int: + cls.update_request(request) + return cls.get_implementation().get_failures(request, credentials) + @classmethod @toggleable def user_login_failed(cls, sender, credentials: dict, request=None, **kwargs): diff --git a/axes/tests/test_handlers.py b/axes/tests/test_handlers.py index b16f67d..ef988c9 100644 --- a/axes/tests/test_handlers.py +++ b/axes/tests/test_handlers.py @@ -275,3 +275,18 @@ class AxesDummyHandlerTestCase(AxesHandlerBaseTestCase): self.login() self.check_login() + + +@override_settings(AXES_HANDLER="axes.handlers.test.AxesTestHandler") +class AxesTestHandlerTestCase(AxesHandlerBaseTestCase): + def test_handler_reset_attempts(self): + self.assertEqual(0, AxesProxyHandler.reset_attempts()) + + def test_handler_reset_logs(self): + self.assertEqual(0, AxesProxyHandler.reset_logs()) + + def test_handler_is_allowed(self): + self.assertEqual(True, AxesProxyHandler.is_allowed(self.request, {})) + + def test_handler_get_failures(self): + self.assertEqual(0, AxesProxyHandler.get_failures(self.request, {}))