Skip to content

Commit

Permalink
Boosting code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
SafeEval committed Apr 25, 2017
1 parent ebf9ca8 commit 082c6ac
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions axes/tests.py
Expand Up @@ -9,14 +9,13 @@

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
Expand Down Expand Up @@ -286,7 +285,7 @@ def test_lockout_by_combination_user_and_ip(self, cache_set_mock,
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):
Expand Down Expand Up @@ -475,6 +474,31 @@ def test_is_ipv6(self):
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
Expand Down

0 comments on commit 082c6ac

Please sign in to comment.