File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 6
6
from tests import WSGIRequest
7
7
8
8
9
- def skips (get_response , ip_address , ajax = False ):
10
- detector = Detector (get_response , ajax = ajax )
9
+ def skips (get_response , ip_address ):
10
+ detector = Detector (get_response )
11
11
response = detector .request_resource (ip_address )
12
12
return response .status_code == 200
13
13
@@ -84,10 +84,3 @@ def test_should_allow_users_only_from_great_britain_with_shared_session(get_resp
84
84
assert forbids_shared_session (detector , IP .ip_cobain )
85
85
# Turn off VPN - back to London
86
86
assert not forbids_shared_session (detector , IP .ip_london )
87
-
88
-
89
- @override_settings (DJANGO_FORBID = {"OPTIONS" : {"VPN" : True }})
90
- def test_should_allow_ajax_requests (get_response ):
91
- """It should give access to the user when request is done by AJAX"""
92
- for ip_address in IP .all :
93
- assert skips (get_response , ip_address , True )
Original file line number Diff line number Diff line change 9
9
request = wsgi .get ()
10
10
11
11
12
+ def skips_ajax (get_response , ip_address ):
13
+ wsgi_ajax = WSGIRequest (True )
14
+ request_ajax = wsgi_ajax .get ()
15
+ request_ajax .META ["HTTP_X_FORWARDED_FOR" ] = ip_address
16
+ response = ForbidMiddleware (get_response )(request_ajax )
17
+ return response .status_code == 200
18
+
19
+
12
20
def forbids (get_response , request ):
13
21
response = ForbidMiddleware (get_response )(request )
14
22
client_ip = request .META ["HTTP_X_FORWARDED_FOR" ]
@@ -80,3 +88,10 @@ def test_should_allow_users_only_from_great_britain_with_shared_session(get_resp
80
88
# Turn off VPN - back to London
81
89
request .META ["HTTP_X_FORWARDED_FOR" ] = IP .ip_london
82
90
assert not forbids (get_response , request )
91
+
92
+
93
+ @override_settings (DJANGO_FORBID = {"OPTIONS" : {"VPN" : True }})
94
+ def test_should_allow_ajax_requests (get_response ):
95
+ """It should give access to the user when request is done by AJAX"""
96
+ for ip_address in IP .all :
97
+ assert skips_ajax (get_response , ip_address )
You can’t perform that action at this time.
0 commit comments