Skip to content

Commit 15f439f

Browse files
committed
GH-29: Move the content type-specific tests to the proper place
1 parent 813847e commit 15f439f

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

tests/test_network_middleware.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from tests import WSGIRequest
77

88

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)
1111
response = detector.request_resource(ip_address)
1212
return response.status_code == 200
1313

@@ -84,10 +84,3 @@ def test_should_allow_users_only_from_great_britain_with_shared_session(get_resp
8484
assert forbids_shared_session(detector, IP.ip_cobain)
8585
# Turn off VPN - back to London
8686
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)

tests/test_primary_middleware.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
request = wsgi.get()
1010

1111

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+
1220
def forbids(get_response, request):
1321
response = ForbidMiddleware(get_response)(request)
1422
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
8088
# Turn off VPN - back to London
8189
request.META["HTTP_X_FORWARDED_FOR"] = IP.ip_london
8290
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)

0 commit comments

Comments
 (0)