mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-15 02:47:59 +00:00
adapt unit tests to new postcode algorithms
This commit is contained in:
@@ -109,14 +109,16 @@ class APITester:
|
||||
def add_postcode(self, **kw):
|
||||
self.add_data('postcode',
|
||||
{'place_id': kw.get('place_id', 1000),
|
||||
'osm_id': kw.get('osm_id'),
|
||||
'parent_place_id': kw.get('parent_place_id'),
|
||||
'country_code': kw.get('country_code'),
|
||||
'postcode': kw.get('postcode'),
|
||||
'rank_search': kw.get('rank_search', 20),
|
||||
'rank_address': kw.get('rank_address', 22),
|
||||
'rank_search': kw.get('rank_search', 21),
|
||||
'indexed_date': kw.get('indexed_date',
|
||||
dt.datetime(2022, 12, 7, 14, 14, 46, 0)),
|
||||
'geometry': kw.get('geometry', 'POINT(23 34)')})
|
||||
'centroid': kw.get('centroid', 'POINT(23 34)'),
|
||||
'geometry': kw.get('geometry', 'POLYGON((22.99 33.99, 22.99 34.01, '
|
||||
'23.01 34, 22.99 33.99))')})
|
||||
|
||||
def add_country(self, country_code, geometry):
|
||||
self.add_data('country_grid',
|
||||
|
||||
@@ -16,6 +16,11 @@ from nominatim_api.search.db_search_fields import WeightedStrings, FieldLookup,
|
||||
FieldRanking, RankedTokens
|
||||
|
||||
|
||||
def poly_around(x, y, diff=0.01):
|
||||
return f"POLYGON(({x - diff} {y - diff}, {x + diff} {y - diff},"\
|
||||
f" {x + diff} {y + diff}, {x - diff} {y + diff}, {x - diff} {y - diff}))"
|
||||
|
||||
|
||||
def run_search(apiobj, frontend, global_penalty, pcs, pc_penalties=None,
|
||||
ccodes=[], lookup=[], ranking=[], details=SearchDetails()):
|
||||
if pc_penalties is None:
|
||||
@@ -58,19 +63,19 @@ def test_postcode_with_country(apiobj, frontend):
|
||||
|
||||
assert len(results) == 1
|
||||
assert results[0].place_id == 101
|
||||
assert results[0].osm_object is None
|
||||
|
||||
|
||||
def test_postcode_area(apiobj, frontend):
|
||||
apiobj.add_postcode(place_id=100, country_code='ch', postcode='12345')
|
||||
apiobj.add_placex(place_id=200, country_code='ch', postcode='12345',
|
||||
osm_type='R', osm_id=34, class_='boundary', type='postal_code',
|
||||
geometry='POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
|
||||
apiobj.add_postcode(place_id=200, country_code='ch', postcode='12345',
|
||||
osm_id=34,
|
||||
centroid='POINT(0.5 0.5)', geometry=poly_around(0.5, 0.5))
|
||||
|
||||
results = run_search(apiobj, frontend, 0.3, ['12345'], [0.0])
|
||||
|
||||
assert len(results) == 1
|
||||
assert results[0].place_id == 200
|
||||
assert results[0].bbox.area == 1
|
||||
assert results[0].osm_object == ('R', 34)
|
||||
|
||||
|
||||
class TestPostcodeSearchWithAddress:
|
||||
@@ -79,10 +84,10 @@ class TestPostcodeSearchWithAddress:
|
||||
def fill_database(self, apiobj):
|
||||
apiobj.add_postcode(place_id=100, country_code='ch',
|
||||
parent_place_id=1000, postcode='12345',
|
||||
geometry='POINT(17 5)')
|
||||
centroid='POINT(17 5)', geometry=poly_around(17, 5))
|
||||
apiobj.add_postcode(place_id=101, country_code='pl',
|
||||
parent_place_id=2000, postcode='12345',
|
||||
geometry='POINT(-45 7)')
|
||||
centroid='POINT(-45 7)', geometry=poly_around(-45, 7))
|
||||
apiobj.add_placex(place_id=1000, class_='place', type='village',
|
||||
rank_search=22, rank_address=22,
|
||||
country_code='ch')
|
||||
|
||||
@@ -489,9 +489,10 @@ def test_lookup_in_postcode(apiobj, frontend):
|
||||
parent_place_id=152,
|
||||
postcode='34 425',
|
||||
country_code='gb',
|
||||
rank_search=20, rank_address=22,
|
||||
rank_search=20,
|
||||
indexed_date=import_date,
|
||||
geometry='POINT(-9.45 5.6)')
|
||||
centroid='POINT(-9.45 5.6)',
|
||||
geometry='POLYGON((-9.5 5.5, -9.5 5.7, -9.4 5.6, -9.5 5.5))')
|
||||
|
||||
api = frontend(apiobj, options={'details'})
|
||||
result = api.details(napi.PlaceID(554))
|
||||
@@ -517,7 +518,7 @@ def test_lookup_in_postcode(apiobj, frontend):
|
||||
assert result.wikipedia is None
|
||||
|
||||
assert result.rank_search == 20
|
||||
assert result.rank_address == 22
|
||||
assert result.rank_address == 5
|
||||
assert result.importance is None
|
||||
|
||||
assert result.country_code == 'gb'
|
||||
@@ -529,15 +530,17 @@ def test_lookup_in_postcode(apiobj, frontend):
|
||||
assert result.name_keywords is None
|
||||
assert result.address_keywords is None
|
||||
|
||||
assert result.geometry == {'type': 'ST_Point'}
|
||||
assert result.geometry == {'type': 'ST_Polygon'}
|
||||
|
||||
|
||||
def test_lookup_postcode_with_address_details(apiobj, frontend):
|
||||
apiobj.add_postcode(place_id=9000,
|
||||
@pytest.mark.parametrize('lookup', [napi.PlaceID(9000),
|
||||
napi.OsmID('R', 12)])
|
||||
def test_lookup_postcode_with_address_details(apiobj, frontend, lookup):
|
||||
apiobj.add_postcode(place_id=9000, osm_id=12,
|
||||
parent_place_id=332,
|
||||
postcode='34 425',
|
||||
country_code='gb',
|
||||
rank_search=25, rank_address=25)
|
||||
rank_search=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,
|
||||
@@ -549,15 +552,15 @@ def test_lookup_postcode_with_address_details(apiobj, frontend):
|
||||
rank_search=17, rank_address=16)
|
||||
|
||||
api = frontend(apiobj, options={'details'})
|
||||
result = api.details(napi.PlaceID(9000), address_details=True)
|
||||
result = api.details(lookup, address_details=True)
|
||||
napi.Locales().localize_results([result])
|
||||
|
||||
assert result.address_rows == [
|
||||
napi.AddressLine(place_id=9000, osm_object=None,
|
||||
category=('place', 'postcode'),
|
||||
napi.AddressLine(place_id=9000, osm_object=('R', 12),
|
||||
category=('boundary', 'postal_code'),
|
||||
names={'ref': '34 425'}, extratags={},
|
||||
admin_level=15, fromarea=True, isaddress=True,
|
||||
rank_address=25, distance=0.0,
|
||||
rank_address=5, distance=0.0,
|
||||
local_name='34 425'),
|
||||
napi.AddressLine(place_id=332, osm_object=('N', 3333),
|
||||
category=('place', 'suburb'),
|
||||
|
||||
Reference in New Issue
Block a user