/
test.py
46 lines (31 loc) · 1.41 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import unittest
import redis
from provider.geonames import GeonamesImporter
from provider.ip2location import IP2LocationImporter
from location import Location
from iprange import IPRange
class TestProvidersTestCase(unittest.TestCase):
def setUp(self):
self.redisHost = 'localhost'
self.redisPort = 6379
def test1_ImportGeonames(self):
importer = GeonamesImporter('./data/locations.csv', self.redisHost, self.redisPort)
self.assertTrue(importer.runImport() > 0, 'Could not import locations csv')
def test2_ImportIP2Location(self):
importer = IP2LocationImporter('./data/ip2location.csv', self.redisHost, self.redisPort)
self.assertTrue(importer.runImport() > 0, 'Could not import ip ranges csv')
def test3_resolve(self):
r = redis.Redis(self.redisHost, self.redisPort)
#resolve by coords
loc = Location.getByLatLon(34.05,-118.24, r)
self.assertTrue(loc is not None)
self.assertTrue(loc.country == 'United States')
self.assertTrue(loc.state == 'CA' or loc.state == 'California')
#resolve by ip
ip = '4.3.32.1'
loc = IPRange.getLocation(ip, r)
self.assertTrue(loc is not None)
self.assertTrue(loc.country == 'United States')
self.assertTrue(loc.state == 'CA' or loc.state == 'California')
if __name__ == '__main__':
unittest.main()