mirror of
https://github.com/jazzband/django-axes.git
synced 2026-05-11 00:53:12 +00:00
Use mocks and test new backends, handlers and middleware on an API call level, aiming for a 100% coverage on behaviour. Also add tests for old decorators which are not covered after moving the default authentication checks from them to the authentication backends, middleware and signal handlers. Fixes #323 Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
21 lines
711 B
Python
21 lines
711 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.backends.is_already_locked', return_value=True)
|
|
def test_authenticate_raises_on_locked_request(self, _):
|
|
request = MagicMock()
|
|
|
|
with self.assertRaises(AxesBackendPermissionDenied):
|
|
AxesBackend().authenticate(request)
|