2017-12-06 16:23:13 +01:00
|
|
|
#!/usr/bin/env python3.5
|
|
|
|
import configparser
|
|
|
|
import datetime
|
2019-05-29 01:42:39 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import redis
|
|
|
|
|
|
|
|
from helpers import geo_helper
|
|
|
|
|
2017-12-06 16:23:13 +01:00
|
|
|
sys.path.append('..')
|
|
|
|
|
|
|
|
configfile = 'test_config.cfg'
|
|
|
|
cfg = configparser.ConfigParser()
|
|
|
|
cfg.read(configfile)
|
|
|
|
|
|
|
|
serv_redis_db = redis.StrictRedis(
|
|
|
|
host='localhost',
|
|
|
|
port=6260,
|
|
|
|
db=1)
|
|
|
|
|
|
|
|
geo_helper = geo_helper.Geo_helper(serv_redis_db, cfg)
|
|
|
|
|
|
|
|
categ = 'Network Activity'
|
|
|
|
|
|
|
|
def wipeRedis():
|
|
|
|
serv_redis_db.flushall()
|
|
|
|
|
|
|
|
def errorExit():
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def test():
|
2017-12-07 09:51:50 +01:00
|
|
|
flag_error = False
|
2017-12-06 16:23:13 +01:00
|
|
|
today = datetime.datetime.now()
|
2017-12-07 09:51:50 +01:00
|
|
|
|
2017-12-06 16:23:13 +01:00
|
|
|
# IP -> Coord
|
|
|
|
supposed_ip = '8.8.8.8'
|
|
|
|
geo_helper.getCoordFromIpAndPublish(supposed_ip, categ)
|
|
|
|
rep = geo_helper.getTopCoord(today)
|
2017-12-07 13:23:22 +01:00
|
|
|
excpected_result = [['{"lat": 37.751, "lon": -97.822, "categ": "Network Activity", "value": "8.8.8.8"}', 1.0]]
|
2017-12-06 16:23:13 +01:00
|
|
|
if rep != excpected_result:
|
|
|
|
print('ip to coord result not matching')
|
2017-12-07 09:51:50 +01:00
|
|
|
flag_error = True
|
2017-12-06 16:23:13 +01:00
|
|
|
|
|
|
|
# gethitmap
|
|
|
|
rep = geo_helper.getHitMap(today)
|
|
|
|
excpected_result = [['US', 1.0]]
|
|
|
|
if rep != excpected_result:
|
|
|
|
print('getHitMap result not matching')
|
2017-12-07 09:51:50 +01:00
|
|
|
flag_error = True
|
2017-12-06 16:23:13 +01:00
|
|
|
|
|
|
|
# getCoordsByRadius
|
|
|
|
rep = geo_helper.getCoordsByRadius(today, today, 0.000, 0.000, '1')
|
|
|
|
excpected_result = []
|
|
|
|
if rep != excpected_result:
|
|
|
|
print('getCoordsByRadius result not matching')
|
2017-12-07 09:51:50 +01:00
|
|
|
flag_error = True
|
2017-12-06 16:23:13 +01:00
|
|
|
|
|
|
|
rep = geo_helper.getCoordsByRadius(today, today, 37.750, -97.821, '10')
|
|
|
|
excpected_result = [[['{"categ": "Network Activity", "value": "8.8.8.8"}'], [-97.82200008630753, 37.75100012475438]]]
|
|
|
|
if rep != excpected_result:
|
|
|
|
print('getCoordsByRadius result not matching')
|
2017-12-07 09:51:50 +01:00
|
|
|
flag_error = True
|
2017-12-06 16:23:13 +01:00
|
|
|
|
|
|
|
wipeRedis()
|
|
|
|
|
|
|
|
|
|
|
|
# Phone -> Coord
|
|
|
|
phoneNumber = '(+352) 247-82000'
|
|
|
|
geo_helper.getCoordFromPhoneAndPublish(phoneNumber, categ)
|
|
|
|
rep = geo_helper.getTopCoord(datetime.datetime.now())[0]
|
|
|
|
excpected_result = ['{"lat": "49.7500", "lon": "6.1667"}', 1.0]
|
|
|
|
if rep != excpected_result:
|
|
|
|
print('Phone to coord result not matching')
|
2017-12-07 09:51:50 +01:00
|
|
|
flag_error = True
|
2017-12-06 16:23:13 +01:00
|
|
|
|
2017-12-07 13:23:22 +01:00
|
|
|
return flag_error
|
|
|
|
|
2017-12-06 16:23:13 +01:00
|
|
|
wipeRedis()
|
2017-12-07 09:51:50 +01:00
|
|
|
if test():
|
|
|
|
wipeRedis()
|
|
|
|
errorExit()
|
|
|
|
else:
|
|
|
|
wipeRedis()
|
|
|
|
print('Geo tests succeeded')
|