mirror of
https://github.com/jazzband/django-axes.git
synced 2026-03-16 22:30:23 +00:00
Add str import also
This commit is contained in:
parent
dbc0c13029
commit
9a043a23d8
3 changed files with 11 additions and 1 deletions
|
|
@ -255,6 +255,8 @@ def get_query_str(query: Type[QueryDict], max_length: int = 1024) -> str:
|
|||
def get_failure_limit(request, credentials) -> int:
|
||||
if callable(settings.AXES_FAILURE_LIMIT):
|
||||
return settings.AXES_FAILURE_LIMIT(request, credentials)
|
||||
if isinstance(settings.AXES_FAILURE_LIMIT, str):
|
||||
return import_string(settings.AXES_FAILURE_LIMIT)(request, credentials)
|
||||
if isinstance(settings.AXES_FAILURE_LIMIT, int):
|
||||
return settings.AXES_FAILURE_LIMIT
|
||||
raise TypeError('settings.AXES_FAILURE_LIMIT needs to be a callable or an integer')
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ from axes.helpers import (
|
|||
from axes.models import AccessAttempt
|
||||
|
||||
|
||||
def custom_failure_limit(request, credentials):
|
||||
return 3
|
||||
|
||||
|
||||
class AxesTestCase(TestCase):
|
||||
"""
|
||||
Test case using custom settings for testing.
|
||||
|
|
|
|||
|
|
@ -115,7 +115,11 @@ class AxesDatabaseHandlerTestCase(AxesHandlerBaseTestCase):
|
|||
def test_handler_callable_failure_limit(self):
|
||||
self.check_handler()
|
||||
|
||||
@override_settings(AXES_FAILURE_LIMIT='3')
|
||||
@override_settings(AXES_FAILURE_LIMIT='axes.tests.base.custom_failure_limit')
|
||||
def test_handler_str_failure_limit(self):
|
||||
self.check_handler()
|
||||
|
||||
@override_settings(AXES_FAILURE_LIMIT=None)
|
||||
def test_handler_invalid_failure_limit(self):
|
||||
with self.assertRaises(TypeError):
|
||||
self.check_handler()
|
||||
|
|
|
|||
Loading…
Reference in a new issue