From c81aeba984b08957614f7167cdbdea8780e76a11 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Mon, 28 Sep 2020 21:40:01 +0300 Subject: Add geoip tests --- iss/config.py | 3 +++ iss/tests/test_geoip.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 iss/config.py create mode 100644 iss/tests/test_geoip.py diff --git a/iss/config.py b/iss/config.py new file mode 100644 index 0000000..1248bb3 --- /dev/null +++ b/iss/config.py @@ -0,0 +1,3 @@ +from os import environ + +GEOIP_CITY_PATH = environ.get("GEOIP_GEOLITE2_CITY_FILENAME") diff --git a/iss/tests/test_geoip.py b/iss/tests/test_geoip.py new file mode 100644 index 0000000..aa3f37d --- /dev/null +++ b/iss/tests/test_geoip.py @@ -0,0 +1,19 @@ +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