mirror of
https://github.com/jazzband/django-axes.git
synced 2026-05-11 17:13:12 +00:00
Boosting code coverage.
This commit is contained in:
parent
ebf9ca89ee
commit
082c6ac35d
1 changed files with 27 additions and 3 deletions
|
|
@ -9,14 +9,13 @@ from mock import patch
|
|||
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import NoReverseMatch
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils import six
|
||||
from django.test.client import RequestFactory
|
||||
|
||||
from axes.decorators import get_ip, get_cache_key
|
||||
from axes.decorators import get_ip, get_cache_key, get_client_str
|
||||
from axes.settings import COOLOFF_TIME
|
||||
from axes.settings import FAILURE_LIMIT
|
||||
from axes.models import AccessAttempt, AccessLog
|
||||
|
|
@ -286,7 +285,7 @@ class AccessAttemptTest(TestCase):
|
|||
response = self._login(is_valid_username=True, is_valid_password=False)
|
||||
self.assertContains(response, self.LOCKED_MESSAGE, status_code=403)
|
||||
|
||||
@override_settings(AXES_ONLY_USER_FAILURES=True)
|
||||
@patch('axes.decorators.AXES_ONLY_USER_FAILURES', True)
|
||||
@patch('axes.decorators.cache.set', return_value=None)
|
||||
@patch('axes.decorators.cache.get', return_value=None)
|
||||
def test_lockout_by_user_only(self, cache_set_mock, cache_get_mock):
|
||||
|
|
@ -475,6 +474,31 @@ class UtilsTest(TestCase):
|
|||
self.assertFalse(is_ipv6('67.255.125.204'))
|
||||
self.assertFalse(is_ipv6('foo'))
|
||||
|
||||
@patch('axes.decorators.VERBOSE', True)
|
||||
def test_verbose_client_details(self):
|
||||
username = 'test@example.com'
|
||||
ip = '127.0.0.1'
|
||||
user_agent = 'Googlebot/2.1 (+http://www.googlebot.com/bot.html)'
|
||||
path_info = '/admin/'
|
||||
details = "{{user: '{0}', ip: '{1}', user-agent: '{2}', path: '{3}'}}"
|
||||
|
||||
expected = details.format(username, ip, user_agent, path_info)
|
||||
actual = get_client_str(username, ip, user_agent, path_info)
|
||||
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
@patch('axes.decorators.VERBOSE', False)
|
||||
def test_non_verbose_client_details(self):
|
||||
username = 'test@example.com'
|
||||
ip = '127.0.0.1'
|
||||
user_agent = 'Googlebot/2.1 (+http://www.googlebot.com/bot.html)'
|
||||
path_info = '/admin/'
|
||||
|
||||
expected = ip
|
||||
actual = get_client_str(username, ip, user_agent, path_info)
|
||||
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
|
||||
class GetIPProxyTest(TestCase):
|
||||
"""Test get_ip returns correct addresses with proxy
|
||||
|
|
|
|||
Loading…
Reference in a new issue