Skip to content

Commit

Permalink
force enricher tests not to use HTTP (except wikidata)
Browse files Browse the repository at this point in the history
  • Loading branch information
pudo committed May 26, 2024
1 parent 622b029 commit b3828f5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
10 changes: 6 additions & 4 deletions tests/enrich/test_nominatim.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@

def load_enricher():
enricher_cls = get_enricher(PATH)
assert enricher_cls is not None, PATH
assert issubclass(enricher_cls, Enricher)
cache = Cache.make_default(dataset)
return enricher_cls(dataset, cache, {})


def test_nominatim_match():
enricher = load_enricher()
with requests_mock.Mocker() as m:
with requests_mock.Mocker(real_http=False) as m:
m.get("/search.php", json=RESPONSE)
full = "Kopenhagener Str. 47, Berlin"
data = {"schema": "Address", "id": "xxx", "properties": {"full": [full]}}
Expand All @@ -99,7 +100,7 @@ def test_nominatim_match_list():

resolver = Resolver()
assert len(resolver.edges) == 0, resolver.edges
with requests_mock.Mocker() as m:
with requests_mock.Mocker(real_http=False) as m:
m.get("/search.php", json=RESPONSE)
results = list(match(enricher, resolver, [ent]))
assert len(results) == 2, results
Expand All @@ -112,7 +113,7 @@ def test_nominatim_enrich():
full = "Kopenhagener Str. 47, Berlin"
data = {"schema": "Address", "id": "xxx", "properties": {"full": [full]}}
ent = CompositeEntity.from_data(dataset, data)
with requests_mock.Mocker() as m:
with requests_mock.Mocker(real_http=False) as m:
m.get("/search.php", json=RESPONSE)
adjacent = list(enricher.expand(ent, ent))
assert len(adjacent) == 1, adjacent
Expand All @@ -124,8 +125,9 @@ def test_nominatim_enrich_list():
full = "Kopenhagener Str. 47, Berlin"
data = {"schema": "Address", "id": "xxx", "properties": {"full": [full]}}
ent = CompositeEntity.from_data(dataset, data)
assert ent.id is not None, ent.id

with requests_mock.Mocker() as m:
with requests_mock.Mocker(real_http=False) as m:
m.get("/search.php", json=RESPONSE)
resolver = Resolver()
results = list(enrich(enricher, resolver, [ent]))
Expand Down
2 changes: 1 addition & 1 deletion tests/enrich/test_openfigi.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def load_enricher():

def test_figi_match():
enricher = load_enricher()
with requests_mock.Mocker() as m:
with requests_mock.Mocker(real_http=False) as m:
m.post("/v3/search", json=RESPONSE)

data = {
Expand Down
6 changes: 3 additions & 3 deletions tests/enrich/test_permid.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def load_enricher():

def test_permid_match():
enricher = load_enricher()
with requests_mock.Mocker() as m:
with requests_mock.Mocker(real_http=False) as m:
m.post("/permid/match", json=MATCH_ROSNEFT)
m.get("https://permid.org/1-4295887083", json=ROSNEFT)
m.get("http://sws.geonames.org/2017370/about.rdf", text=GEONAME)
Expand All @@ -182,7 +182,7 @@ def test_permid_match():
assert res.has("leiCode")
assert res.has("name")

with requests_mock.Mocker() as m:
with requests_mock.Mocker(real_http=False) as m:
m.post("/permid/match", json=MATCH_FAIL)
data = {
"schema": "Company",
Expand All @@ -196,7 +196,7 @@ def test_permid_match():

def test_permid_enrich():
enricher = load_enricher()
with requests_mock.Mocker() as m:
with requests_mock.Mocker(real_http=False) as m:
m.post("/permid/match", json=MATCH_ROSNEFT)
m.get("https://permid.org/1-4295887083", json=ROSNEFT)
m.get("http://sws.geonames.org/2017370/about.rdf", text=GEONAME)
Expand Down
5 changes: 3 additions & 2 deletions tests/enrich/test_wikidata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from followthemoney import model
from nomenklatura.cache import Cache
from nomenklatura.dataset import Dataset
from nomenklatura.enrich import get_enricher
Expand All @@ -10,8 +9,10 @@
PATH = "nomenklatura.enrich.wikidata:WikidataEnricher"
dataset = Dataset.make({"name": "wikidata", "title": "Wikidata"})


def load_enricher():
enricher_cls = get_enricher(PATH)
assert enricher_cls is not None, PATH
assert issubclass(enricher_cls, Enricher)
cache = Cache.make_default(dataset)
return enricher_cls(dataset, cache, {})
Expand Down Expand Up @@ -51,4 +52,4 @@ def test_model_apply():

dirty = LangText("clean part (politician)", "en")
dirty.apply(ent, "alias", clean=clean_name)
assert ent.get("alias") == ["clean part"]
assert ent.get("alias") == ["clean part"]

0 comments on commit b3828f5

Please sign in to comment.