IP to Geo

IP to Geo Commit Details

Date:2016-02-24 19:17:40 (4 years 8 months ago)
Author:Grégory Soutadé
Branch:master
Commit:b05329f9be4ea11eee3455960604614c36305821
Parents: 911f909f9632f220968254dd86e205b32c7466f6
Message:Add coherency tests

Changes:
Mtests/test_ip_to_geo.py (2 diffs)

File differences

tests/test_ip_to_geo.py
1616
1717
1818
19
19
2020
2121
2222
......
2727
2828
2929
30
30
3131
32
32
33
34
35
36
37
3338
3439
35
36
37
38
39
40
41
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
4255
4356
4457
(ord(os.urandom(1)), ord(os.urandom(1)), ord(os.urandom(1)), ord(os.urandom(1)))
return ip
def test_ip(ip, verbose=True, proxy=iptogeo):
def test_ip(ip, verbose=True, proxy=iptogeo, result=None):
try:
(ipres, country_code) = proxy.ip_to_geo(ip)
except IPToGeoException, e:
if verbose:
if not country_code:
print 'Country code for %s (%08x) not found' % (ip, ipres)
print 'Country code for %s (%s) not found' % (ip, ipres)
else:
print 'Country code for %s (%08x) is %s' % (ip, ipres, country_code)
print 'Country code for %s (%s) is %s' % (ip, ipres, country_code)
if not result is None:
if not country_code: country_code = ''
if result != country_code:
raise Exception('Bad result %s != %s' % (country_code, result))
print '#### Coherence test'
test_ip('1.5.7.3')
test_ip('1.5.255.4')
test_ip('1.6.255.4')
test_ip('2.0.0.0')
test_ip('127.0.0.1')
test_ip('1.55.3.12')
test_ip('1.57.0.0')
test_ip('1.5.7.3', result='jp')
test_ip('1.5.255.4', result='jp')
test_ip('1.6.255.4', result='in')
test_ip('2.0.0.0', result='fr')
test_ip('127.0.0.1', result='')
test_ip('1.55.3.12', result='vn')
test_ip('1.57.0.0', result='cn')
test_ip('192.168.2.2', result='')
test_ip('2001:600::', result='eu')
test_ip('2001:608::00', result='de')
test_ip('2001:0660:0000:0000:0000:0000:0000:0000', result='fr')
test_ip('2001:670:1234:5678:9abc:def0:1234:5678', result='fi')
test_ip('8001::', result='')
test_ip('fe80::1a03:73ff:fee9:8705', result='')
print '#### 5 sockets test'
for i in range(0, 6):

Archive Download the corresponding diff file

Branches

Tags