Skip to content

Commit 825c702

Browse files
committed
monkeypatch probe_geoip to provide static responses
1 parent 7d87a10 commit 825c702

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1-
def test_geolookup(client):
1+
from typing import Dict, Tuple
2+
import ooniprobe.routers.v1.probe_services as ps
3+
from ooniprobe.dependencies import CCReaderDep, ASNReaderDep
4+
5+
def fake_probe_geoip(
6+
ipaddr: str,
7+
probe_cc: str,
8+
asn: str,
9+
cc_reader: CCReaderDep,
10+
asn_reader: ASNReaderDep,
11+
) -> Tuple[Dict, str, int]:
12+
return {"probe_cc": "US", "probe_asn": "AS4242", "probe_network_name": "Testing Networks"}, "US", 4242
13+
14+
15+
def test_geolookup(client, monkeypatch):
16+
monkeypatch.setattr(ps, "probe_geoip", fake_probe_geoip)
217
j = dict(
318
addresses=["192.33.4.12", "170.247.170.2", "2801:1b8:10::b", "2001:500:2::c"]
419
)
520
c = client.post("/api/v1/geolookup", json=j).json()
621
assert "geolocation" in c
722
assert "v" in c
823
g = c["geolocation"]
24+
925
for ip in j["addresses"]:
10-
assert g[ip]["cc"] != "ZZ"
11-
assert g[ip]["asn"] != "AS0"
12-
assert g[ip]["as_name"] is not None
26+
assert g[ip]["cc"] == "US"
27+
assert g[ip]["asn"] == "AS4242"
28+
assert g[ip]["as_name"] == "Testing Networks"

0 commit comments

Comments
 (0)