Admin and middleware tests

This commit is contained in:
Joffrey F 2015-01-02 15:15:34 -08:00
parent 08bb7d12fb
commit 465e45a124

View file

@ -434,3 +434,29 @@ class AccessAttemptTest(TestCase):
self.assertEqual(
utils.get_user_attempts(req), ip_attempts
)
def test_admin(self):
from .admin import AccessAttemptAdmin
AccessAttemptAdmin
@patch('defender.middleware.ViewDecoratorMiddleware.watched_logins',
(ADMIN_LOGIN_URL, ))
def test_decorator_middleware(self):
# because watch_login is called twice in this test (once by the
# middleware and once by the decorator) we have half as many attempts
# before getting locked out.
# FIXME: I tried making sure every request in only processed once but
# there seems to be an issue with django reusing request objects.
for i in range(0, config.FAILURE_LIMIT / 2):
response = self._login()
# Check if we are in the same login page
self.assertContains(response, LOGIN_FORM_KEY)
# So, we shouldn't have gotten a lock-out yet.
# But we should get one now
response = self._login()
self.assertContains(response, self.LOCKED_MESSAGE)
# doing a get should also get locked out message
response = self.client.get(ADMIN_LOGIN_URL)
self.assertContains(response, self.LOCKED_MESSAGE)