django-axes/axes/tests/test_backends.py
Aleksi Häkli fa7f35dda5
Add tests for the new components
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>
2019-02-10 19:22:13 +02:00

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)