From d5cf61d168bdbcf05032d5a8003e61386ae8deb2 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Mon, 28 Sep 2020 22:05:05 +0300 Subject: Finalize geo parsing from IP --- iss/tests/test_geo.py | 26 ++++++++++++++++++++++++++ iss/tests/test_geoip.py | 19 ------------------- 2 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 iss/tests/test_geo.py delete mode 100644 iss/tests/test_geoip.py (limited to 'iss/tests') diff --git a/iss/tests/test_geo.py b/iss/tests/test_geo.py new file mode 100644 index 0000000..c63c2d6 --- /dev/null +++ b/iss/tests/test_geo.py @@ -0,0 +1,26 @@ +import pytest + +from ..config import GEOIP_CITY_PATH +from ..geo import get_location + +geoip_required = pytest.mark.skipif( + not GEOIP_CITY_PATH, reason="Path to GeoLite2 city database must be provided" +) + + +@geoip_required +def test_geo(): + ip = "2.52.2.52" + location = get_location(ip) + assert location.latitude == 31.5 + assert location.longitude == 34.75 + assert location.time_zone == "Asia/Jerusalem" + + +@geoip_required +def test_geo_localhost(): + ip = "127.0.0.1" + location = get_location(ip) + assert location.latitude == 34.7641 + assert location.longitude == 32.0669 + assert location.time_zone == "Asia/Jerusalem" diff --git a/iss/tests/test_geoip.py b/iss/tests/test_geoip.py deleted file mode 100644 index aa3f37d..0000000 --- a/iss/tests/test_geoip.py +++ /dev/null @@ -1,19 +0,0 @@ -import pytest -import geoip2.database - -from ..config import GEOIP_CITY_PATH - -geoip_required = pytest.mark.skipif( - not GEOIP_CITY_PATH, reason="Path to GeoLite2 city database must be provided" -) - - -@geoip_required -def test_geo(): - ip = "2.52.2.52" - with geoip2.database.Reader(GEOIP_CITY_PATH) as reader: - res = reader.city(ip) - location = res.location - assert location.latitude == 31.5 - assert location.longitude == 34.75 - assert location.time_zone == "Asia/Jerusalem" -- cgit v1.3.1