mirror of
https://github.com/jazzband/django-axes.git
synced 2026-03-16 22:30:23 +00:00
The old architecture used exceptions in the signal handler which prevented transactions from running smoothly and signal handlers from running after Axes handlers. The new architecture changes the request approach to request flagging and moves the exception handling into the middleware call method. This allows users to more flexibly run their own signal handlers and optionally use the Axes middleware if they want to do so. Fixes #440 Fixes #442
30 lines
893 B
Python
30 lines
893 B
Python
from unittest.mock import patch, MagicMock
|
|
|
|
from django.http import HttpResponse, HttpRequest
|
|
|
|
from axes.middleware import AxesMiddleware
|
|
from axes.tests.base import AxesTestCase
|
|
|
|
|
|
class MiddlewareTestCase(AxesTestCase):
|
|
STATUS_SUCCESS = 200
|
|
STATUS_LOCKOUT = 403
|
|
|
|
def setUp(self):
|
|
self.request = HttpRequest()
|
|
|
|
def test_success_response(self):
|
|
def get_response(request):
|
|
request.axes_locked_out = False
|
|
return HttpResponse()
|
|
|
|
response = AxesMiddleware(get_response)(self.request)
|
|
self.assertEqual(response.status_code, self.STATUS_SUCCESS)
|
|
|
|
def test_lockout_response(self):
|
|
def get_response(request):
|
|
request.axes_locked_out = True
|
|
return HttpResponse()
|
|
|
|
response = AxesMiddleware(get_response)(self.request)
|
|
self.assertEqual(response.status_code, self.STATUS_LOCKOUT)
|