Merge branch 'Andrew-Crosio-django1.7_compatibility'

This commit is contained in:
Camilo Nova 2014-05-10 09:45:14 -05:00
commit 87a740439d
2 changed files with 18 additions and 6 deletions

View file

@ -5,7 +5,6 @@ from datetime import timedelta
from django.conf import settings
from django.contrib.auth import logout
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth.models import SiteProfileNotAvailable
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
@ -20,6 +19,11 @@ except ImportError: # django < 1.5
else:
User = get_user_model()
try:
from django.contrib.auth.models import SiteProfileNotAvailable
except ImportError: # django >= 1.7
SiteProfileNotAvailable = type('SiteProfileNotAvailable', (Exception,), {})
from axes.models import AccessLog
from axes.models import AccessAttempt
from axes.signals import user_locked_out
@ -58,7 +62,6 @@ IP_BLACKLIST = getattr(settings, 'AXES_IP_BLACKLIST', None)
ERROR_MESSAGE = ugettext_lazy("Please enter a correct username and password. "
"Note that both fields are case-sensitive.")
LOGIN_FORM_KEY = 'this_is_the_login_form'
def get_ip(request):

View file

@ -5,15 +5,24 @@ import time
from django.test import TestCase
from django.test.client import Client
from django.contrib.auth.models import User
from django.core.urlresolvers import NoReverseMatch
from django.core.urlresolvers import reverse
from axes.decorators import COOLOFF_TIME
from axes.decorators import FAILURE_LIMIT
from axes.decorators import LOGIN_FORM_KEY
from axes.models import AccessLog
from axes.utils import reset
# Django >= 1.7 compatibility
try:
ADMIN_LOGIN_URL = reverse('admin:login')
LOGIN_FORM_KEY = '<form action="/admin/login/" method="post" id="login-form">'
except NoReverseMatch:
ADMIN_LOGIN_URL = reverse('admin:index')
LOGIN_FORM_KEY = 'this_is_the_login_form'
class AccessAttemptTest(TestCase):
"""Test case using custom settings for testing
"""
@ -35,7 +44,7 @@ class AccessAttemptTest(TestCase):
return self._generate_random_string()
def _login(self, existing_username=False, user_agent='test-browser'):
response = self.client.post(reverse('admin:index'), {
response = self.client.post(ADMIN_LOGIN_URL, {
'username': self._random_username(existing_username),
'password': self._generate_random_string(),
'this_is_the_login_form': 1,
@ -102,7 +111,7 @@ class AccessAttemptTest(TestCase):
"""Tests a valid login for a real username
"""
valid_username = self._random_username(existing_username=True)
response = self.client.post(reverse('admin:index'), {
response = self.client.post(ADMIN_LOGIN_URL, {
'username': valid_username,
'password': valid_username,
'this_is_the_login_form': 1,
@ -167,7 +176,7 @@ class AccessAttemptTest(TestCase):
"""Tests a valid logout and make sure the logout_time is updated
"""
valid_username = self._random_username(existing_username=True)
response = self.client.post(reverse('admin:index'), {
self.client.post(ADMIN_LOGIN_URL, {
'username': valid_username,
'password': valid_username,
'this_is_the_login_form': 1,