django-axes/axes/tests/test_backends.py
Aleksi Häkli e69d479f6a
Refactor handlers to a more pluggable format
- Define a base handler API with method signatures
- Move proxy handler to a separate path for importability
- Implement a database handler with clean external dependencies
- Change the authentication backend and decorators to use the authentication backend

This enables clean pluggable authentication backend definitions that users
can override and specialize with e.g. cached handlers in their own packages.

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 19:55:57 +02:00

21 lines
744 B
Python

from unittest.mock import patch, MagicMock
from django.test import TestCase
from axes.backends import AxesBackend
from axes.exceptions import AxesBackendRequestParameterRequired, AxesBackendPermissionDenied
class BackendTestCase(TestCase):
def test_authenticate_raises_on_missing_request(self):
request = None
with self.assertRaises(AxesBackendRequestParameterRequired):
AxesBackend().authenticate(request)
@patch('axes.handlers.proxy.AxesProxyHandler.is_allowed_to_authenticate', return_value=False)
def test_authenticate_raises_on_locked_request(self, _):
request = MagicMock()
with self.assertRaises(AxesBackendPermissionDenied):
AxesBackend().authenticate(request)