mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-15 10:57:58 +00:00
switch API parameters to keyword arguments
This switches the input parameters for API calls to a generic keyword argument catch-all which is then loaded into a dataclass where the parameters are checked and forwarded to internal function. The dataclass gives more flexibility with the parameters and makes it easier to reuse common parameters for the different API calls.
This commit is contained in:
@@ -31,7 +31,7 @@ def test_lookup_in_placex(apiobj, idobj):
|
||||
indexed_date=import_date,
|
||||
geometry='LINESTRING(23 34, 23.1 34, 23.1 34.1, 23 34)')
|
||||
|
||||
result = apiobj.api.details(idobj, napi.LookupDetails())
|
||||
result = apiobj.api.details(idobj)
|
||||
|
||||
assert result is not None
|
||||
|
||||
@@ -79,7 +79,7 @@ def test_lookup_in_placex_minimal_info(apiobj):
|
||||
indexed_date=import_date,
|
||||
geometry='LINESTRING(23 34, 23.1 34, 23.1 34.1, 23 34)')
|
||||
|
||||
result = apiobj.api.details(napi.PlaceID(332), napi.LookupDetails())
|
||||
result = apiobj.api.details(napi.PlaceID(332))
|
||||
|
||||
assert result is not None
|
||||
|
||||
@@ -121,8 +121,7 @@ def test_lookup_in_placex_with_geometry(apiobj):
|
||||
apiobj.add_placex(place_id=332,
|
||||
geometry='LINESTRING(23 34, 23.1 34)')
|
||||
|
||||
result = apiobj.api.details(napi.PlaceID(332),
|
||||
napi.LookupDetails(geometry_output=napi.GeometryFormat.GEOJSON))
|
||||
result = apiobj.api.details(napi.PlaceID(332), geometry_output=napi.GeometryFormat.GEOJSON)
|
||||
|
||||
assert result.geometry == {'geojson': '{"type":"LineString","coordinates":[[23,34],[23.1,34]]}'}
|
||||
|
||||
@@ -144,8 +143,7 @@ def test_lookup_placex_with_address_details(apiobj):
|
||||
country_code='pl',
|
||||
rank_search=17, rank_address=16)
|
||||
|
||||
result = apiobj.api.details(napi.PlaceID(332),
|
||||
napi.LookupDetails(address_details=True))
|
||||
result = apiobj.api.details(napi.PlaceID(332), address_details=True)
|
||||
|
||||
assert result.address_rows == [
|
||||
napi.AddressLine(place_id=332, osm_object=('W', 4),
|
||||
@@ -177,8 +175,7 @@ def test_lookup_place_with_linked_places_none_existing(apiobj):
|
||||
country_code='pl', linked_place_id=45,
|
||||
rank_search=27, rank_address=26)
|
||||
|
||||
result = apiobj.api.details(napi.PlaceID(332),
|
||||
napi.LookupDetails(linked_places=True))
|
||||
result = apiobj.api.details(napi.PlaceID(332), linked_places=True)
|
||||
|
||||
assert result.linked_rows == []
|
||||
|
||||
@@ -197,8 +194,7 @@ def test_lookup_place_with_linked_places_existing(apiobj):
|
||||
country_code='pl', linked_place_id=332,
|
||||
rank_search=27, rank_address=26)
|
||||
|
||||
result = apiobj.api.details(napi.PlaceID(332),
|
||||
napi.LookupDetails(linked_places=True))
|
||||
result = apiobj.api.details(napi.PlaceID(332), linked_places=True)
|
||||
|
||||
assert result.linked_rows == [
|
||||
napi.AddressLine(place_id=1001, osm_object=('W', 5),
|
||||
@@ -220,8 +216,7 @@ def test_lookup_place_with_parented_places_not_existing(apiobj):
|
||||
country_code='pl', parent_place_id=45,
|
||||
rank_search=27, rank_address=26)
|
||||
|
||||
result = apiobj.api.details(napi.PlaceID(332),
|
||||
napi.LookupDetails(parented_places=True))
|
||||
result = apiobj.api.details(napi.PlaceID(332), parented_places=True)
|
||||
|
||||
assert result.parented_rows == []
|
||||
|
||||
@@ -240,8 +235,7 @@ def test_lookup_place_with_parented_places_existing(apiobj):
|
||||
country_code='pl', parent_place_id=332,
|
||||
rank_search=27, rank_address=26)
|
||||
|
||||
result = apiobj.api.details(napi.PlaceID(332),
|
||||
napi.LookupDetails(parented_places=True))
|
||||
result = apiobj.api.details(napi.PlaceID(332), parented_places=True)
|
||||
|
||||
assert result.parented_rows == [
|
||||
napi.AddressLine(place_id=1001, osm_object=('N', 5),
|
||||
@@ -263,7 +257,7 @@ def test_lookup_in_osmline(apiobj, idobj):
|
||||
indexed_date=import_date,
|
||||
geometry='LINESTRING(23 34, 23 35)')
|
||||
|
||||
result = apiobj.api.details(idobj, napi.LookupDetails())
|
||||
result = apiobj.api.details(idobj)
|
||||
|
||||
assert result is not None
|
||||
|
||||
@@ -310,13 +304,13 @@ def test_lookup_in_osmline_split_interpolation(apiobj):
|
||||
startnumber=11, endnumber=20, step=1)
|
||||
|
||||
for i in range(1, 6):
|
||||
result = apiobj.api.details(napi.OsmID('W', 9, str(i)), napi.LookupDetails())
|
||||
result = apiobj.api.details(napi.OsmID('W', 9, str(i)))
|
||||
assert result.place_id == 1000
|
||||
for i in range(7, 11):
|
||||
result = apiobj.api.details(napi.OsmID('W', 9, str(i)), napi.LookupDetails())
|
||||
result = apiobj.api.details(napi.OsmID('W', 9, str(i)))
|
||||
assert result.place_id == 1001
|
||||
for i in range(12, 22):
|
||||
result = apiobj.api.details(napi.OsmID('W', 9, str(i)), napi.LookupDetails())
|
||||
result = apiobj.api.details(napi.OsmID('W', 9, str(i)))
|
||||
assert result.place_id == 1002
|
||||
|
||||
|
||||
@@ -340,8 +334,7 @@ def test_lookup_osmline_with_address_details(apiobj):
|
||||
country_code='pl',
|
||||
rank_search=17, rank_address=16)
|
||||
|
||||
result = apiobj.api.details(napi.PlaceID(9000),
|
||||
napi.LookupDetails(address_details=True))
|
||||
result = apiobj.api.details(napi.PlaceID(9000), address_details=True)
|
||||
|
||||
assert result.address_rows == [
|
||||
napi.AddressLine(place_id=None, osm_object=None,
|
||||
@@ -383,7 +376,7 @@ def test_lookup_in_tiger(apiobj):
|
||||
osm_type='W', osm_id=6601223,
|
||||
geometry='LINESTRING(23 34, 23 35)')
|
||||
|
||||
result = apiobj.api.details(napi.PlaceID(4924), napi.LookupDetails())
|
||||
result = apiobj.api.details(napi.PlaceID(4924))
|
||||
|
||||
assert result is not None
|
||||
|
||||
@@ -441,8 +434,7 @@ def test_lookup_tiger_with_address_details(apiobj):
|
||||
country_code='us',
|
||||
rank_search=17, rank_address=16)
|
||||
|
||||
result = apiobj.api.details(napi.PlaceID(9000),
|
||||
napi.LookupDetails(address_details=True))
|
||||
result = apiobj.api.details(napi.PlaceID(9000), address_details=True)
|
||||
|
||||
assert result.address_rows == [
|
||||
napi.AddressLine(place_id=None, osm_object=None,
|
||||
@@ -483,7 +475,7 @@ def test_lookup_in_postcode(apiobj):
|
||||
indexed_date=import_date,
|
||||
geometry='POINT(-9.45 5.6)')
|
||||
|
||||
result = apiobj.api.details(napi.PlaceID(554), napi.LookupDetails())
|
||||
result = apiobj.api.details(napi.PlaceID(554))
|
||||
|
||||
assert result is not None
|
||||
|
||||
@@ -537,8 +529,7 @@ def test_lookup_postcode_with_address_details(apiobj):
|
||||
country_code='gb',
|
||||
rank_search=17, rank_address=16)
|
||||
|
||||
result = apiobj.api.details(napi.PlaceID(9000),
|
||||
napi.LookupDetails(address_details=True))
|
||||
result = apiobj.api.details(napi.PlaceID(9000), address_details=True)
|
||||
|
||||
assert result.address_rows == [
|
||||
napi.AddressLine(place_id=332, osm_object=('N', 3333),
|
||||
@@ -570,7 +561,7 @@ def test_lookup_missing_object(apiobj, objid):
|
||||
apiobj.add_placex(place_id=1, osm_type='N', osm_id=55,
|
||||
class_='place', type='suburb')
|
||||
|
||||
assert apiobj.api.details(objid, napi.LookupDetails()) is None
|
||||
assert apiobj.api.details(objid) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('gtype', (napi.GeometryFormat.KML,
|
||||
@@ -580,5 +571,4 @@ def test_lookup_unsupported_geometry(apiobj, gtype):
|
||||
apiobj.add_placex(place_id=332)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
apiobj.api.details(napi.PlaceID(332),
|
||||
napi.LookupDetails(geometry_output=gtype))
|
||||
apiobj.api.details(napi.PlaceID(332), geometry_output=gtype)
|
||||
|
||||
@@ -95,7 +95,7 @@ def test_lookup_multiple_places(apiobj):
|
||||
|
||||
result = apiobj.api.lookup((napi.OsmID('W', 1),
|
||||
napi.OsmID('W', 4),
|
||||
napi.OsmID('W', 9928)), napi.LookupDetails())
|
||||
napi.OsmID('W', 9928)))
|
||||
|
||||
assert len(result) == 2
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ def test_reverse_rank_30_layers(apiobj, y, layer, place_id):
|
||||
rank_search=30,
|
||||
centroid=(1.3, 0.70005))
|
||||
|
||||
assert apiobj.api.reverse((1.3, y), layer=layer).place_id == place_id
|
||||
assert apiobj.api.reverse((1.3, y), layers=layer).place_id == place_id
|
||||
|
||||
|
||||
def test_reverse_poi_layer_with_no_pois(apiobj):
|
||||
@@ -95,7 +95,7 @@ def test_reverse_poi_layer_with_no_pois(apiobj):
|
||||
centroid=(1.3, 0.70001))
|
||||
|
||||
assert apiobj.api.reverse((1.3, 0.70001), max_rank=29,
|
||||
layer=napi.DataLayer.POI) is None
|
||||
layers=napi.DataLayer.POI) is None
|
||||
|
||||
|
||||
def test_reverse_housenumber_on_street(apiobj):
|
||||
@@ -245,7 +245,7 @@ def test_reverse_larger_area_layers(apiobj, layer, place_id):
|
||||
rank_search=16,
|
||||
centroid=(1.3, 0.70005))
|
||||
|
||||
assert apiobj.api.reverse((1.3, 0.7), layer=layer).place_id == place_id
|
||||
assert apiobj.api.reverse((1.3, 0.7), layers=layer).place_id == place_id
|
||||
|
||||
|
||||
def test_reverse_country_lookup_no_objects(apiobj):
|
||||
@@ -296,10 +296,8 @@ def test_reverse_geometry_output_placex(apiobj, gtype):
|
||||
country_code='xx',
|
||||
centroid=(0.5, 0.5))
|
||||
|
||||
details = napi.LookupDetails(geometry_output=gtype)
|
||||
|
||||
assert apiobj.api.reverse((59.3, 80.70001), details=details).place_id == 1001
|
||||
assert apiobj.api.reverse((0.5, 0.5), details=details).place_id == 1003
|
||||
assert apiobj.api.reverse((59.3, 80.70001), geometry_output=gtype).place_id == 1001
|
||||
assert apiobj.api.reverse((0.5, 0.5), geometry_output=gtype).place_id == 1003
|
||||
|
||||
|
||||
def test_reverse_simplified_geometry(apiobj):
|
||||
@@ -309,9 +307,9 @@ def test_reverse_simplified_geometry(apiobj):
|
||||
rank_search=30,
|
||||
centroid=(59.3, 80.70001))
|
||||
|
||||
details = napi.LookupDetails(geometry_output=napi.GeometryFormat.GEOJSON,
|
||||
geometry_simplification=0.1)
|
||||
assert apiobj.api.reverse((59.3, 80.70001), details=details).place_id == 1001
|
||||
details = dict(geometry_output=napi.GeometryFormat.GEOJSON,
|
||||
geometry_simplification=0.1)
|
||||
assert apiobj.api.reverse((59.3, 80.70001), **details).place_id == 1001
|
||||
|
||||
|
||||
def test_reverse_interpolation_geometry(apiobj):
|
||||
@@ -321,8 +319,7 @@ def test_reverse_interpolation_geometry(apiobj):
|
||||
centroid=(10.0, 10.00001),
|
||||
geometry='LINESTRING(9.995 10.00001, 10.005 10.00001)')
|
||||
|
||||
details = napi.LookupDetails(geometry_output=napi.GeometryFormat.TEXT)
|
||||
assert apiobj.api.reverse((10.0, 10.0), details=details)\
|
||||
assert apiobj.api.reverse((10.0, 10.0), geometry_output=napi.GeometryFormat.TEXT)\
|
||||
.geometry['text'] == 'POINT(10 10.00001)'
|
||||
|
||||
|
||||
@@ -339,8 +336,8 @@ def test_reverse_tiger_geometry(apiobj):
|
||||
centroid=(10.0, 10.00001),
|
||||
geometry='LINESTRING(9.995 10.00001, 10.005 10.00001)')
|
||||
|
||||
details = napi.LookupDetails(geometry_output=napi.GeometryFormat.GEOJSON)
|
||||
output = apiobj.api.reverse((10.0, 10.0), details=details).geometry['geojson']
|
||||
output = apiobj.api.reverse((10.0, 10.0),
|
||||
geometry_output=napi.GeometryFormat.GEOJSON).geometry['geojson']
|
||||
|
||||
assert json.loads(output) == {'coordinates': [10, 10.00001], 'type': 'Point'}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user