X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/dc99bbb0afb7632b5497d4f6f41acff5b2e635e2..edb1eec46d0fd222f9b30e0e3d62e906c1c9059e:/test/python/api/search/test_search_poi.py?ds=sidebyside diff --git a/test/python/api/search/test_search_poi.py b/test/python/api/search/test_search_poi.py index b80c0752..a0b578ba 100644 --- a/test/python/api/search/test_search_poi.py +++ b/test/python/api/search/test_search_poi.py @@ -15,7 +15,7 @@ from nominatim.api.search.db_searches import PoiSearch from nominatim.api.search.db_search_fields import WeightedStrings, WeightedCategories -def run_search(apiobj, global_penalty, poitypes, poi_penalties=None, +def run_search(apiobj, frontend, global_penalty, poitypes, poi_penalties=None, ccodes=[], details=SearchDetails()): if poi_penalties is None: poi_penalties = [0.0] * len(poitypes) @@ -27,16 +27,18 @@ def run_search(apiobj, global_penalty, poitypes, poi_penalties=None, search = PoiSearch(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()) @pytest.mark.parametrize('coord,pid', [('34.3, 56.100021', 2), ('5.0, 4.59933', 1)]) -def test_simple_near_search_in_placex(apiobj, coord, pid): +def test_simple_near_search_in_placex(apiobj, frontend, coord, pid): apiobj.add_placex(place_id=1, class_='highway', type='bus_stop', centroid=(5.0, 4.6)) apiobj.add_placex(place_id=2, class_='highway', type='bus_stop', @@ -44,7 +46,7 @@ def test_simple_near_search_in_placex(apiobj, coord, pid): details = SearchDetails.from_kwargs({'near': coord, 'near_radius': 0.001}) - results = run_search(apiobj, 0.1, [('highway', 'bus_stop')], [0.5], details=details) + results = run_search(apiobj, frontend, 0.1, [('highway', 'bus_stop')], [0.5], details=details) assert [r.place_id for r in results] == [pid] @@ -52,7 +54,7 @@ def test_simple_near_search_in_placex(apiobj, coord, pid): @pytest.mark.parametrize('coord,pid', [('34.3, 56.100021', 2), ('34.3, 56.4', 2), ('5.0, 4.59933', 1)]) -def test_simple_near_search_in_classtype(apiobj, coord, pid): +def test_simple_near_search_in_classtype(apiobj, frontend, coord, pid): apiobj.add_placex(place_id=1, class_='highway', type='bus_stop', centroid=(5.0, 4.6)) apiobj.add_placex(place_id=2, class_='highway', type='bus_stop', @@ -61,7 +63,7 @@ def test_simple_near_search_in_classtype(apiobj, coord, pid): details = SearchDetails.from_kwargs({'near': coord, 'near_radius': 0.5}) - results = run_search(apiobj, 0.1, [('highway', 'bus_stop')], [0.5], details=details) + results = run_search(apiobj, frontend, 0.1, [('highway', 'bus_stop')], [0.5], details=details) assert [r.place_id for r in results] == [pid] @@ -83,25 +85,25 @@ class TestPoiSearchWithRestrictions: self.args = {'near': '34.3, 56.100021', 'near_radius': 0.001} - def test_unrestricted(self, apiobj): - results = run_search(apiobj, 0.1, [('highway', 'bus_stop')], [0.5], + def test_unrestricted(self, apiobj, frontend): + results = run_search(apiobj, frontend, 0.1, [('highway', 'bus_stop')], [0.5], details=SearchDetails.from_kwargs(self.args)) assert [r.place_id for r in results] == [1, 2] - def test_restict_country(self, apiobj): - results = run_search(apiobj, 0.1, [('highway', 'bus_stop')], [0.5], + def test_restict_country(self, apiobj, frontend): + results = run_search(apiobj, frontend, 0.1, [('highway', 'bus_stop')], [0.5], ccodes=['de', 'nz'], details=SearchDetails.from_kwargs(self.args)) assert [r.place_id for r in results] == [2] - def test_restrict_by_viewbox(self, apiobj): + def test_restrict_by_viewbox(self, apiobj, frontend): args = {'bounded_viewbox': True, 'viewbox': '34.299,56.0,34.3001,56.10001'} args.update(self.args) - results = run_search(apiobj, 0.1, [('highway', 'bus_stop')], [0.5], + results = run_search(apiobj, frontend, 0.1, [('highway', 'bus_stop')], [0.5], ccodes=['de', 'nz'], details=SearchDetails.from_kwargs(args))