1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2023 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Tests for lookup API call.
12 import nominatim.api as napi
14 def test_lookup_empty_list(apiobj):
15 assert apiobj.api.lookup([]) == []
18 def test_lookup_non_existing(apiobj):
19 assert apiobj.api.lookup((napi.PlaceID(332), napi.OsmID('W', 4),
20 napi.OsmID('W', 4, 'highway'))) == []
23 @pytest.mark.parametrize('idobj', (napi.PlaceID(332), napi.OsmID('W', 4),
24 napi.OsmID('W', 4, 'highway')))
25 def test_lookup_single_placex(apiobj, idobj):
26 apiobj.add_placex(place_id=332, osm_type='W', osm_id=4,
27 class_='highway', type='residential',
28 name={'name': 'Road'}, address={'city': 'Barrow'},
29 extratags={'surface': 'paved'},
30 parent_place_id=34, linked_place_id=55,
31 admin_level=15, country_code='gb',
33 postcode='34425', wikipedia='en:Faa',
34 rank_search=27, rank_address=26,
37 geometry='LINESTRING(23 34, 23.1 34, 23.1 34.1, 23 34)')
39 result = apiobj.api.lookup([idobj])
41 assert len(result) == 1
45 assert result.source_table.name == 'PLACEX'
46 assert result.category == ('highway', 'residential')
47 assert result.centroid == (pytest.approx(23.0), pytest.approx(34.0))
49 assert result.place_id == 332
50 assert result.osm_object == ('W', 4)
52 assert result.names == {'name': 'Road'}
53 assert result.address == {'city': 'Barrow'}
54 assert result.extratags == {'surface': 'paved'}
56 assert result.housenumber == '4'
57 assert result.postcode == '34425'
58 assert result.wikipedia == 'en:Faa'
60 assert result.rank_search == 27
61 assert result.rank_address == 26
62 assert result.importance == pytest.approx(0.01)
64 assert result.country_code == 'gb'
66 assert result.address_rows is None
67 assert result.linked_rows is None
68 assert result.parented_rows is None
69 assert result.name_keywords is None
70 assert result.address_keywords is None
72 assert result.geometry == {}
75 def test_lookup_multiple_places(apiobj):
76 apiobj.add_placex(place_id=332, osm_type='W', osm_id=4,
77 class_='highway', type='residential',
78 name={'name': 'Road'}, address={'city': 'Barrow'},
79 extratags={'surface': 'paved'},
80 parent_place_id=34, linked_place_id=55,
81 admin_level=15, country_code='gb',
83 postcode='34425', wikipedia='en:Faa',
84 rank_search=27, rank_address=26,
87 geometry='LINESTRING(23 34, 23.1 34, 23.1 34.1, 23 34)')
88 apiobj.add_osmline(place_id=4924, osm_id=9928,
90 startnumber=1, endnumber=4, step=1,
91 country_code='gb', postcode='34425',
92 address={'city': 'Big'},
93 geometry='LINESTRING(23 34, 23 35)')
96 result = apiobj.api.lookup((napi.OsmID('W', 1),
98 napi.OsmID('W', 9928)))
100 assert len(result) == 2
102 assert set(r.place_id for r in result) == {332, 4924}