summaryrefslogtreecommitdiff
path: root/iss/tests
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2020-09-28 22:05:05 +0300
committerYuval Adam <_@yuv.al>2020-09-28 22:05:05 +0300
commitd5cf61d168bdbcf05032d5a8003e61386ae8deb2 (patch)
treeaeaf99cde2a147511f06d9d53a652c7b8374e86f /iss/tests
parentc81aeba984b08957614f7167cdbdea8780e76a11 (diff)
Finalize geo parsing from IP
Diffstat (limited to 'iss/tests')
-rw-r--r--iss/tests/test_geo.py26
-rw-r--r--iss/tests/test_geoip.py19
2 files changed, 26 insertions, 19 deletions
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"