1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
from generalresearch.managers.thl.ipinfo import GeoIpInfoManager
from generalresearch.models.thl.ipinfo import GeoIPInformation
class TestGeoIpInfoManager:
def test_get(self, geoip_info_manager: GeoIpInfoManager):
result = geoip_info_manager.get("8.8.8.8")
assert result == GeoIPInformation(
ip="8.8.8.8",
country_iso="us",
is_anonymous=False,
autonomous_system_number=15169,
autonomous_system_organization="Google",
access_type=None,
)
geoip_info_manager.grip_mmdb.lookup.assert_called_once_with("8.8.8.8")
def test_get_multi(self, geoip_info_manager: GeoIpInfoManager):
result = geoip_info_manager.get_multi(["8.8.8.8", "1.1.1.1", "8.8.8.8"])
assert result == {
"8.8.8.8": GeoIPInformation(
ip="8.8.8.8",
country_iso="us",
is_anonymous=False,
autonomous_system_number=15169,
autonomous_system_organization="Google",
access_type=None,
),
"1.1.1.1": GeoIPInformation(
ip="1.1.1.1",
country_iso="au",
is_anonymous=True,
autonomous_system_number=13335,
autonomous_system_organization="Cloudflare",
access_type=None,
),
}
assert geoip_info_manager.grip_mmdb.lookup.call_count == 2
assert {
call.args[0] for call in geoip_info_manager.grip_mmdb.lookup.call_args_list
} == {"8.8.8.8", "1.1.1.1"}
def test_get_multi_empty(self, geoip_info_manager: GeoIpInfoManager):
assert geoip_info_manager.get_multi([]) == {}
geoip_info_manager.grip_mmdb.lookup.assert_not_called()
|