mirror of
https://github.com/jazzband/django-axes.git
synced 2026-05-11 17:13:12 +00:00
In tests, only set cooldown if testing it
The results for the cache unit tests were inconsistent, sometimes blocking and other time allowing. The source of the non-determinism was the COOLDOWN_TIME set to 2 seconds in the test. If a test took slightly longer than the cooldown time, it would fail. Testing times on Travis CI vary with each build, and would produce unreliable results. Now all tests have no cooldown period, except when the cooldown itself is being tested. This ensures accurate and predicable test results.
This commit is contained in:
parent
4783787c6d
commit
95917a951e
2 changed files with 6 additions and 5 deletions
|
|
@ -1,5 +1,3 @@
|
|||
from datetime import timedelta
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
|
|
@ -55,4 +53,3 @@ USE_TZ = False
|
|||
LOGIN_REDIRECT_URL = '/admin/'
|
||||
|
||||
AXES_LOGIN_FAILURE_LIMIT = 10
|
||||
AXES_COOLOFF_TIME = timedelta(seconds=2)
|
||||
|
|
|
|||
|
|
@ -16,13 +16,15 @@ from django.utils import six
|
|||
from django.test.client import RequestFactory
|
||||
|
||||
from axes.decorators import get_ip, get_cache_key
|
||||
from axes.settings import COOLOFF_TIME
|
||||
from axes.settings import FAILURE_LIMIT
|
||||
from axes.models import AccessAttempt, AccessLog
|
||||
from axes.signals import user_locked_out
|
||||
from axes.utils import reset, iso8601
|
||||
|
||||
|
||||
TEST_COOLOFF_TIME = datetime.timedelta(seconds=2)
|
||||
|
||||
|
||||
class MockRequest:
|
||||
def __init__(self):
|
||||
self.META = dict()
|
||||
|
|
@ -140,17 +142,19 @@ class AccessAttemptTest(TestCase):
|
|||
self.assertNotEquals(AccessLog.objects.latest('id').logout_time, None)
|
||||
self.assertContains(response, 'Logged out')
|
||||
|
||||
@patch('axes.decorators.COOLOFF_TIME', TEST_COOLOFF_TIME)
|
||||
def test_cooling_off(self):
|
||||
"""Tests if the cooling time allows a user to login
|
||||
"""
|
||||
self.test_failure_limit_once()
|
||||
|
||||
# Wait for the cooling off period
|
||||
time.sleep(COOLOFF_TIME.total_seconds())
|
||||
time.sleep(TEST_COOLOFF_TIME.total_seconds())
|
||||
|
||||
# It should be possible to login again, make sure it is.
|
||||
self.test_valid_login()
|
||||
|
||||
@patch('axes.decorators.COOLOFF_TIME', TEST_COOLOFF_TIME)
|
||||
def test_cooling_off_for_trusted_user(self):
|
||||
"""Test the cooling time for a trusted user
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue