]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/python/api/test_api_lookup.py
properly encode special HTML characters in debug mode
[nominatim.git] / test / python / api / test_api_lookup.py
index c445085730f34f1b7a84e05b4b0785c93a1bbdb4..f8e89930ca2fe143a7fdc14ee7c98da6111091db 100644 (file)
@@ -58,7 +58,7 @@ def test_lookup_in_placex(apiobj, idobj):
     assert result.importance == pytest.approx(0.01)
 
     assert result.country_code == 'gb'
     assert result.importance == pytest.approx(0.01)
 
     assert result.country_code == 'gb'
-    assert result.indexed_date == import_date
+    assert result.indexed_date == import_date.replace(tzinfo=dt.timezone.utc)
 
     assert result.address_rows is None
     assert result.linked_rows is None
 
     assert result.address_rows is None
     assert result.linked_rows is None
@@ -106,7 +106,7 @@ def test_lookup_in_placex_minimal_info(apiobj):
     assert result.importance is None
 
     assert result.country_code is None
     assert result.importance is None
 
     assert result.country_code is None
-    assert result.indexed_date == import_date
+    assert result.indexed_date == import_date.replace(tzinfo=dt.timezone.utc)
 
     assert result.address_rows is None
     assert result.linked_rows is None
 
     assert result.address_rows is None
     assert result.linked_rows is None
@@ -168,7 +168,6 @@ def test_lookup_placex_with_address_details(apiobj):
                                 names={'ref': 'pl'}, extratags={},
                                 admin_level=None, fromarea=True, isaddress=False,
                                 rank_address=4, distance=0.0)
                                 names={'ref': 'pl'}, extratags={},
                                 admin_level=None, fromarea=True, isaddress=False,
                                 rank_address=4, distance=0.0)
-
            ]
 
 
            ]
 
 
@@ -291,7 +290,7 @@ def test_lookup_in_osmline(apiobj, idobj):
     assert result.importance is None
 
     assert result.country_code == 'gb'
     assert result.importance is None
 
     assert result.country_code == 'gb'
-    assert result.indexed_date == import_date
+    assert result.indexed_date == import_date.replace(tzinfo=dt.timezone.utc)
 
     assert result.address_rows is None
     assert result.linked_rows is None
 
     assert result.address_rows is None
     assert result.linked_rows is None
@@ -370,9 +369,205 @@ def test_lookup_osmline_with_address_details(apiobj):
                                 names={'ref': 'pl'}, extratags={},
                                 admin_level=None, fromarea=True, isaddress=False,
                                 rank_address=4, distance=0.0)
                                 names={'ref': 'pl'}, extratags={},
                                 admin_level=None, fromarea=True, isaddress=False,
                                 rank_address=4, distance=0.0)
+           ]
+
+
+def test_lookup_in_tiger(apiobj):
+    apiobj.add_tiger(place_id=4924,
+                     parent_place_id=12,
+                     startnumber=1, endnumber=4, step=1,
+                     postcode='34425',
+                     geometry='LINESTRING(23 34, 23 35)')
+
+    result = apiobj.api.lookup(napi.PlaceID(4924), napi.LookupDetails())
+
+    assert result is not None
+
+    assert result.source_table.name == 'TIGER'
+    assert result.category == ('place', 'houses')
+    assert result.centroid == (pytest.approx(23.0), pytest.approx(34.5))
+
+    assert result.place_id == 4924
+    assert result.parent_place_id == 12
+    assert result.linked_place_id is None
+    assert result.osm_object is None
+    assert result.admin_level == 15
+
+    assert result.names is None
+    assert result.address is None
+    assert result.extratags == {'startnumber': '1', 'endnumber': '4', 'step': '1'}
+
+    assert result.housenumber is None
+    assert result.postcode == '34425'
+    assert result.wikipedia is None
+
+    assert result.rank_search == 30
+    assert result.rank_address == 30
+    assert result.importance is None
+
+    assert result.country_code == 'us'
+    assert result.indexed_date is None
+
+    assert result.address_rows is None
+    assert result.linked_rows is None
+    assert result.parented_rows is None
+    assert result.name_keywords is None
+    assert result.address_keywords is None
+
+    assert result.geometry == {'type': 'ST_LineString'}
+
+
+def test_lookup_tiger_with_address_details(apiobj):
+    apiobj.add_tiger(place_id=9000,
+                     startnumber=2, endnumber=4, step=1,
+                     parent_place_id=332)
+    apiobj.add_placex(place_id=332, osm_type='W', osm_id=4,
+                     class_='highway', type='residential',  name='Street',
+                     country_code='us',
+                     rank_search=27, rank_address=26)
+    apiobj.add_address_placex(332, fromarea=False, isaddress=False,
+                              distance=0.0034,
+                              place_id=1000, osm_type='N', osm_id=3333,
+                              class_='place', type='suburb', name='Smallplace',
+                              country_code='us', admin_level=13,
+                              rank_search=24, rank_address=23)
+    apiobj.add_address_placex(332, fromarea=True, isaddress=True,
+                              place_id=1001, osm_type='N', osm_id=3334,
+                              class_='place', type='city', name='Bigplace',
+                              country_code='us',
+                              rank_search=17, rank_address=16)
+
+    result = apiobj.api.lookup(napi.PlaceID(9000),
+                               napi.LookupDetails(address_details=True))
+
+    assert result.address_rows == [
+               napi.AddressLine(place_id=None, osm_object=None,
+                                category=('place', 'house_number'),
+                                names={'ref': '2'}, extratags={},
+                                admin_level=None, fromarea=True, isaddress=True,
+                                rank_address=28, distance=0.0),
+               napi.AddressLine(place_id=332, osm_object=('W', 4),
+                                category=('highway', 'residential'),
+                                names={'name': 'Street'}, extratags={},
+                                admin_level=15, fromarea=True, isaddress=True,
+                                rank_address=26, distance=0.0),
+               napi.AddressLine(place_id=1000, osm_object=('N', 3333),
+                                category=('place', 'suburb'),
+                                names={'name': 'Smallplace'}, extratags={},
+                                admin_level=13, fromarea=False, isaddress=True,
+                                rank_address=23, distance=0.0034),
+               napi.AddressLine(place_id=1001, osm_object=('N', 3334),
+                                category=('place', 'city'),
+                                names={'name': 'Bigplace'}, extratags={},
+                                admin_level=15, fromarea=True, isaddress=True,
+                                rank_address=16, distance=0.0),
+               napi.AddressLine(place_id=None, osm_object=None,
+                                category=('place', 'country_code'),
+                                names={'ref': 'us'}, extratags={},
+                                admin_level=None, fromarea=True, isaddress=False,
+                                rank_address=4, distance=0.0)
+           ]
+
+
+def test_lookup_in_postcode(apiobj):
+    import_date = dt.datetime(2022, 12, 7, 14, 14, 46, 0)
+    apiobj.add_postcode(place_id=554,
+                        parent_place_id=152,
+                        postcode='34 425',
+                        country_code='gb',
+                        rank_search=20, rank_address=22,
+                        indexed_date=import_date,
+                        geometry='POINT(-9.45 5.6)')
+
+    result = apiobj.api.lookup(napi.PlaceID(554), napi.LookupDetails())
+
+    assert result is not None
+
+    assert result.source_table.name == 'POSTCODE'
+    assert result.category == ('place', 'postcode')
+    assert result.centroid == (pytest.approx(-9.45), pytest.approx(5.6))
+
+    assert result.place_id == 554
+    assert result.parent_place_id == 152
+    assert result.linked_place_id is None
+    assert result.osm_object is None
+    assert result.admin_level == 15
+
+    assert result.names == {'ref': '34 425'}
+    assert result.address is None
+    assert result.extratags is None
+
+    assert result.housenumber is None
+    assert result.postcode is None
+    assert result.wikipedia is None
+
+    assert result.rank_search == 20
+    assert result.rank_address == 22
+    assert result.importance is None
 
 
+    assert result.country_code == 'gb'
+    assert result.indexed_date == import_date.replace(tzinfo=dt.timezone.utc)
+
+    assert result.address_rows is None
+    assert result.linked_rows is None
+    assert result.parented_rows is None
+    assert result.name_keywords is None
+    assert result.address_keywords is None
+
+    assert result.geometry == {'type': 'ST_Point'}
+
+
+def test_lookup_postcode_with_address_details(apiobj):
+    apiobj.add_postcode(place_id=9000,
+                        parent_place_id=332,
+                        postcode='34 425',
+                        country_code='gb',
+                        rank_search=25, rank_address=25)
+    apiobj.add_placex(place_id=332, osm_type='N', osm_id=3333,
+                      class_='place', type='suburb',  name='Smallplace',
+                      country_code='gb', admin_level=13,
+                      rank_search=24, rank_address=23)
+    apiobj.add_address_placex(332, fromarea=True, isaddress=True,
+                              place_id=1001, osm_type='N', osm_id=3334,
+                              class_='place', type='city', name='Bigplace',
+                              country_code='gb',
+                              rank_search=17, rank_address=16)
+
+    result = apiobj.api.lookup(napi.PlaceID(9000),
+                               napi.LookupDetails(address_details=True))
+
+    assert result.address_rows == [
+               napi.AddressLine(place_id=332, osm_object=('N', 3333),
+                                category=('place', 'suburb'),
+                                names={'name': 'Smallplace'}, extratags={},
+                                admin_level=13, fromarea=True, isaddress=True,
+                                rank_address=23, distance=0.0),
+               napi.AddressLine(place_id=1001, osm_object=('N', 3334),
+                                category=('place', 'city'),
+                                names={'name': 'Bigplace'}, extratags={},
+                                admin_level=15, fromarea=True, isaddress=True,
+                                rank_address=16, distance=0.0),
+               napi.AddressLine(place_id=None, osm_object=None,
+                                category=('place', 'postcode'),
+                                names={'ref': '34 425'}, extratags={},
+                                admin_level=None, fromarea=False, isaddress=True,
+                                rank_address=5, distance=0.0),
+               napi.AddressLine(place_id=None, osm_object=None,
+                                category=('place', 'country_code'),
+                                names={'ref': 'gb'}, extratags={},
+                                admin_level=None, fromarea=True, isaddress=False,
+                                rank_address=4, distance=0.0)
            ]
 
            ]
 
+@pytest.mark.parametrize('objid', [napi.PlaceID(1736),
+                                   napi.OsmID('W', 55),
+                                   napi.OsmID('N', 55, 'amenity')])
+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.lookup(objid, napi.LookupDetails()) is None
+
 
 @pytest.mark.parametrize('gtype', (napi.GeometryFormat.KML,
                                     napi.GeometryFormat.SVG,
 
 @pytest.mark.parametrize('gtype', (napi.GeometryFormat.KML,
                                     napi.GeometryFormat.SVG,