X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/bd2c64876f7ddc99da14ea78a652f797e17134f4..c41f2fed2133668dc3179813261d39d3ff69cbdd:/test/python/api/search/test_search_country.py?ds=sidebyside diff --git a/test/python/api/search/test_search_country.py b/test/python/api/search/test_search_country.py index bb0abc39..82b1d37f 100644 --- a/test/python/api/search/test_search_country.py +++ b/test/python/api/search/test_search_country.py @@ -59,3 +59,70 @@ def test_find_from_fallback_countries(apiobj): def test_find_none(apiobj): assert len(run_search(apiobj, 0.0, ['xx'])) == 0 + + +@pytest.mark.parametrize('coord,numres', [((0.5, 1), 1), ((10, 10), 0)]) +def test_find_near(apiobj, 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'], + details=SearchDetails(near=napi.Point(*coord), + near_radius=0.1)) + + assert len(results) == numres + + +class TestCountryParameters: + + @pytest.fixture(autouse=True) + def fill_database(self, apiobj): + apiobj.add_placex(place_id=55, class_='boundary', type='administrative', + rank_search=4, rank_address=4, + name={'name': 'Lolaland'}, + country_code='yw', + 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))') + apiobj.add_country('ro', 'POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))') + apiobj.add_country_name('ro', {'name': 'România'}) + + + @pytest.mark.parametrize('geom', [napi.GeometryFormat.GEOJSON, + napi.GeometryFormat.KML, + 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], + details=SearchDetails(geometry_output=geom)) + + assert len(results) == 1 + assert geom.name.lower() in results[0].geometry + + + @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'], + details=SearchDetails(excluded=[pid])) + + assert [r.place_id for r in results] == rids + + + @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'], + details=SearchDetails.from_kwargs({'viewbox': viewbox, + 'bounded_viewbox': True})) + + assert [r.place_id for r in results] == rids + + + @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'], + details=SearchDetails.from_kwargs({'viewbox': viewbox, + 'bounded_viewbox': True})) + + assert len(results) == numres