mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-14 13:05:09 +00:00
feat(ip-info): return timezone and add a required-field filter
get_ip_info(require=...) skips a geolocation API whose result lacks a required field, so ipinfo Lite falls through to ipinfo.io or ip-api.in.
This commit is contained in:
@@ -80,3 +80,18 @@ def test_get_ip_info_collects_connection_errors_only(monkeypatch):
|
||||
errors: list[Exception] = []
|
||||
assert ip_info.get_ip_info(SimpleNamespace(proxies={"all": "http://127.0.0.1:9"}), errors=errors) is None
|
||||
assert [str(e) for e in errors] == ["refused"]
|
||||
|
||||
|
||||
def test_require_skips_provider_missing_field(monkeypatch):
|
||||
lite = {"country": "ca", "timezone": ""}
|
||||
full = {"country": "ca", "timezone": "America/Edmonton"}
|
||||
monkeypatch.setattr(
|
||||
ip_info, "build_providers", lambda: [("lite", lambda s: dict(lite)), ("full", lambda s: dict(full))]
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
ip_info,
|
||||
"Cacher",
|
||||
lambda *a: SimpleNamespace(get=lambda k: SimpleNamespace(data=None, expired=True, set=lambda *a, **k: None)),
|
||||
)
|
||||
assert ip_info.get_ip_info(object())["_provider"] == "lite"
|
||||
assert ip_info.get_ip_info(object(), require=("timezone",))["timezone"] == "America/Edmonton"
|
||||
|
||||
Reference in New Issue
Block a user