mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
enable all API tests for sqlite and port missing features
This commit is contained in:
@@ -15,7 +15,7 @@ from nominatim.api.search.db_searches import CountrySearch
|
||||
from nominatim.api.search.db_search_fields import WeightedStrings
|
||||
|
||||
|
||||
def run_search(apiobj, global_penalty, ccodes,
|
||||
def run_search(apiobj, frontend, global_penalty, ccodes,
|
||||
country_penalties=None, details=SearchDetails()):
|
||||
if country_penalties is None:
|
||||
country_penalties = [0.0] * len(ccodes)
|
||||
@@ -25,15 +25,16 @@ def run_search(apiobj, global_penalty, ccodes,
|
||||
countries = WeightedStrings(ccodes, country_penalties)
|
||||
|
||||
search = CountrySearch(MySearchData())
|
||||
api = frontend(apiobj, options=['search'])
|
||||
|
||||
async def run():
|
||||
async with apiobj.api._async_api.begin() as conn:
|
||||
async with api._async_api.begin() as conn:
|
||||
return await search.lookup(conn, details)
|
||||
|
||||
return apiobj.async_to_sync(run())
|
||||
return api._loop.run_until_complete(run())
|
||||
|
||||
|
||||
def test_find_from_placex(apiobj):
|
||||
def test_find_from_placex(apiobj, frontend):
|
||||
apiobj.add_placex(place_id=55, class_='boundary', type='administrative',
|
||||
rank_search=4, rank_address=4,
|
||||
name={'name': 'Lolaland'},
|
||||
@@ -41,32 +42,32 @@ def test_find_from_placex(apiobj):
|
||||
centroid=(10, 10),
|
||||
geometry='POLYGON((9.5 9.5, 9.5 10.5, 10.5 10.5, 10.5 9.5, 9.5 9.5))')
|
||||
|
||||
results = run_search(apiobj, 0.5, ['de', 'yw'], [0.0, 0.3])
|
||||
results = run_search(apiobj, frontend, 0.5, ['de', 'yw'], [0.0, 0.3])
|
||||
|
||||
assert len(results) == 1
|
||||
assert results[0].place_id == 55
|
||||
assert results[0].accuracy == 0.8
|
||||
|
||||
def test_find_from_fallback_countries(apiobj):
|
||||
def test_find_from_fallback_countries(apiobj, frontend):
|
||||
apiobj.add_country('ro', 'POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))')
|
||||
apiobj.add_country_name('ro', {'name': 'România'})
|
||||
|
||||
results = run_search(apiobj, 0.0, ['ro'])
|
||||
results = run_search(apiobj, frontend, 0.0, ['ro'])
|
||||
|
||||
assert len(results) == 1
|
||||
assert results[0].names == {'name': 'România'}
|
||||
|
||||
|
||||
def test_find_none(apiobj):
|
||||
assert len(run_search(apiobj, 0.0, ['xx'])) == 0
|
||||
def test_find_none(apiobj, frontend):
|
||||
assert len(run_search(apiobj, frontend, 0.0, ['xx'])) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('coord,numres', [((0.5, 1), 1), ((10, 10), 0)])
|
||||
def test_find_near(apiobj, coord, numres):
|
||||
def test_find_near(apiobj, frontend, coord, numres):
|
||||
apiobj.add_country('ro', 'POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))')
|
||||
apiobj.add_country_name('ro', {'name': 'România'})
|
||||
|
||||
results = run_search(apiobj, 0.0, ['ro'],
|
||||
results = run_search(apiobj, frontend, 0.0, ['ro'],
|
||||
details=SearchDetails(near=napi.Point(*coord),
|
||||
near_radius=0.1))
|
||||
|
||||
@@ -92,8 +93,8 @@ class TestCountryParameters:
|
||||
napi.GeometryFormat.SVG,
|
||||
napi.GeometryFormat.TEXT])
|
||||
@pytest.mark.parametrize('cc', ['yw', 'ro'])
|
||||
def test_return_geometries(self, apiobj, geom, cc):
|
||||
results = run_search(apiobj, 0.5, [cc],
|
||||
def test_return_geometries(self, apiobj, frontend, geom, cc):
|
||||
results = run_search(apiobj, frontend, 0.5, [cc],
|
||||
details=SearchDetails(geometry_output=geom))
|
||||
|
||||
assert len(results) == 1
|
||||
@@ -101,8 +102,8 @@ class TestCountryParameters:
|
||||
|
||||
|
||||
@pytest.mark.parametrize('pid,rids', [(76, [55]), (55, [])])
|
||||
def test_exclude_place_id(self, apiobj, pid, rids):
|
||||
results = run_search(apiobj, 0.5, ['yw', 'ro'],
|
||||
def test_exclude_place_id(self, apiobj, frontend, pid, rids):
|
||||
results = run_search(apiobj, frontend, 0.5, ['yw', 'ro'],
|
||||
details=SearchDetails(excluded=[pid]))
|
||||
|
||||
assert [r.place_id for r in results] == rids
|
||||
@@ -110,8 +111,8 @@ class TestCountryParameters:
|
||||
|
||||
@pytest.mark.parametrize('viewbox,rids', [((9, 9, 11, 11), [55]),
|
||||
((-10, -10, -3, -3), [])])
|
||||
def test_bounded_viewbox_in_placex(self, apiobj, viewbox, rids):
|
||||
results = run_search(apiobj, 0.5, ['yw'],
|
||||
def test_bounded_viewbox_in_placex(self, apiobj, frontend, viewbox, rids):
|
||||
results = run_search(apiobj, frontend, 0.5, ['yw'],
|
||||
details=SearchDetails.from_kwargs({'viewbox': viewbox,
|
||||
'bounded_viewbox': True}))
|
||||
|
||||
@@ -120,8 +121,8 @@ class TestCountryParameters:
|
||||
|
||||
@pytest.mark.parametrize('viewbox,numres', [((0, 0, 1, 1), 1),
|
||||
((-10, -10, -3, -3), 0)])
|
||||
def test_bounded_viewbox_in_fallback(self, apiobj, viewbox, numres):
|
||||
results = run_search(apiobj, 0.5, ['ro'],
|
||||
def test_bounded_viewbox_in_fallback(self, apiobj, frontend, viewbox, numres):
|
||||
results = run_search(apiobj, frontend, 0.5, ['ro'],
|
||||
details=SearchDetails.from_kwargs({'viewbox': viewbox,
|
||||
'bounded_viewbox': True}))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user