Unable to change settings in tests
Closed this issue · 1 comments
janosroden commented
In the module defaults in IPWARE_META_PRECEDENCE_ORDER
HTTP_X_FORWARDED_FOR
precedes REMOTE_ADDR
. If I change the order then I should get the value of REMOTE_ADDR
in the following test which is not the case.
class IPv4TestCase(TestCase):
@override_settings(IPWARE_META_PRECEDENCE_ORDER=('REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR'))
def test_setting_override(self):
request = HttpRequest()
request.META = {
'HTTP_X_FORWARDED_FOR': '177.139.233.139, 198.84.193.157, 198.84.193.158',
'REMOTE_ADDR': '177.139.233.133',
}
result = get_client_ip(request)
self.assertEqual(result, ("177.139.233.133", True))
PR #43 fixes this.
un33k commented
The header order (precedence) can be passed to the get_client_ip()
.
from ipware import get_client_ip
class IPv4TestCase(TestCase):
def test_some_test(self):
request = HttpRequest()
request.META = {
'HTTP_X_FORWARDED_FOR': '177.139.233.139, 198.84.193.157, 198.84.193.158',
'REMOTE_ADDR': '177.139.233.133',
}
result = get_client_ip(request, request_header_order=['REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR'])
self.assertEqual(result, ("177.139.233.133", True))
It is mentioned in the readme under advanced users