diff options
| author | Yuval Adam <_@yuv.al> | 2020-09-28 21:40:01 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2020-09-28 21:40:20 +0300 |
| commit | c81aeba984b08957614f7167cdbdea8780e76a11 (patch) | |
| tree | 8b08a714a19fc48f466af6286943b4eddc3423a2 | |
| parent | f4844cd8c546d1bc6f689ffe95274596c14cc6c6 (diff) | |
Add geoip tests
| -rw-r--r-- | iss/config.py | 3 | ||||
| -rw-r--r-- | iss/tests/test_geoip.py | 19 |
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" |
