Change how middleware tests for is_ajax

This commit is contained in:
blag 2021-12-20 02:11:24 -08:00
parent eb863621ff
commit bae4684bdf
No known key found for this signature in database
GPG key ID: 30870D32F59C5F40
2 changed files with 4 additions and 4 deletions

View file

@ -25,7 +25,7 @@ class UserAgreementMiddleware(MiddlewareMixin):
return None
# Ignore ajax requests
if request.is_ajax():
if request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest':
return None
# Don't redirect users when they're trying to get to the confirm page

View file

@ -111,9 +111,6 @@ class TestMiddleware(TestCase):
@modify_settings(
MIDDLEWARE_CLASSES={
'append': 'tos.middleware.UserAgreementMiddleware',
},
MIDDLEWARE={
'append': 'tos.middleware.UserAgreementMiddleware',
},
@ -142,6 +139,9 @@ class BumpCoverage(TestCase):
def test_ajax_request(self):
class Request(object):
method = 'GET'
META = {
'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'
}
def is_ajax(self):
return True