summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--iss/config.py3
-rw-r--r--iss/tests/test_geoip.py19
2 files changed, 22 insertions, 0 deletions
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"