IP to Geo

IP to Geo Commit Details

Date:2016-02-04 20:39:50 (4 years 8 months ago)
Author:Grégory Soutadé
Branch:master
Commit:73732adbef88a8b2c50f514a02247e629f8037fd
Parents: d110f892b46fbaa1a1d6c4914eb8955bd05c7cf0
Message:Add more tests

Changes:
Mtests/test_ip_to_geo.py (2 diffs)

File differences

tests/test_ip_to_geo.py
44
55
66
7
7
8
9
10
11
12
813
9
14
1015
11
16
1217
13
18
19
20
1421
1522
16
17
18
19
23
24
25
26
27
2028
29
2130
2231
2332
......
2635
2736
2837
38
39
40
41
2942
43
44
45
46
47
48
3049
31
32
33
50
51
52
53
54
55
56
57
58
59
60
61
import os
from iptogeo import IPToGeo, IPToGeoException
iptogeo = IPToGeo()
TIMEOUT=3
iptogeo = IPToGeo(timeout=TIMEOUT)
def get_random_ip_v4():
ip = '%d.%d.%d.%d' % \
(ord(os.urandom(1)), ord(os.urandom(1)), ord(os.urandom(1)), ord(os.urandom(1)))
return ip
def test_ip(ip):
def test_ip(ip, verbose=True, proxy=iptogeo):
try:
(ipres, country_code) = iptogeo.ip_to_geo(ip)
(ipres, country_code) = proxy.ip_to_geo(ip)
except IPToGeoException, e:
print e
if verbose:
print 'Error with IP %s' % (ip)
print e
return
if not country_code:
print 'Country code for %s (%08x) not found' % (ip, ipres)
else:
print 'Country code for %s (%08x) is %s' % (ip, ipres, country_code)
if verbose:
if not country_code:
print 'Country code for %s (%08x) not found' % (ip, ipres)
else:
print 'Country code for %s (%08x) is %s' % (ip, ipres, country_code)
print '#### Coherence test'
test_ip('1.5.7.3')
test_ip('1.5.255.4')
test_ip('1.6.255.4')
test_ip('1.55.3.12')
test_ip('1.57.0.0')
print '#### 5 sockets test'
for i in range(0, 6):
print 'Test %d' % (i)
test_ip(get_random_ip_v4(), verbose=False, proxy=IPToGeo(timeout=TIMEOUT))
print '#### 35 sockets test'
for i in range(0, 36):
print 'Test %d' % (i)
test_ip(get_random_ip_v4(), verbose=False, proxy=IPToGeo(timeout=TIMEOUT))
print '#### 1 socket heavy test'
for i in range(0, 1000):
ip = '%d.%d.%d.%d' % \
(ord(os.urandom(1)), ord(os.urandom(1)), ord(os.urandom(1)), ord(os.urandom(1)))
test_ip(ip)
print 'Test %d' % (i)
test_ip(get_random_ip_v4(), verbose=False)
print '#### 35 sockets heavy test'
geo_proxy = []
for i in range(0, 36):
geo_proxy.append(IPToGeo(timeout=TIMEOUT))
for i in range(0, 1000):
print 'Test %d' % (i)
for proxy in geo_proxy:
test_ip(get_random_ip_v4(), verbose=False, proxy=proxy)

Archive Download the corresponding diff file

Branches

Tags