X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/35b52c46562c3dd3427da7bca898d18edfd60047..4cc788f69e1191d2dd985aeac143597566529f24:/test/python/api/test_result_formatting_v1_reverse.py diff --git a/test/python/api/test_result_formatting_v1_reverse.py b/test/python/api/test_result_formatting_v1_reverse.py index 6e94cf10..902f0e79 100644 --- a/test/python/api/test_result_formatting_v1_reverse.py +++ b/test/python/api/test_result_formatting_v1_reverse.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 2023 by the Nominatim developer community. +# Copyright (C) 2025 by the Nominatim developer community. # For a full list of authors see the git log. """ Tests for formatting reverse results for the V1 API. @@ -15,18 +15,19 @@ import xml.etree.ElementTree as ET import pytest -import nominatim.api.v1 as api_impl -import nominatim.api as napi +from nominatim_api.v1.format import dispatch as v1_format +import nominatim_api as napi FORMATS = ['json', 'jsonv2', 'geojson', 'geocodejson', 'xml'] + @pytest.mark.parametrize('fmt', FORMATS) def test_format_reverse_minimal(fmt): reverse = napi.ReverseResult(napi.SourceTable.PLACEX, ('amenity', 'post_box'), napi.Point(0.3, -8.9)) - raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt, {}) + raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt, {}) if fmt == 'xml': root = ET.fromstring(raw) @@ -38,7 +39,7 @@ def test_format_reverse_minimal(fmt): @pytest.mark.parametrize('fmt', FORMATS) def test_format_reverse_no_result(fmt): - raw = api_impl.format_result(napi.ReverseResults(), fmt, {}) + raw = v1_format.format_result(napi.ReverseResults(), fmt, {}) if fmt == 'xml': root = ET.fromstring(raw) @@ -55,7 +56,7 @@ def test_format_reverse_with_osm_id(fmt): place_id=5564, osm_object=('N', 23)) - raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt, {}) + raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt, {}) if fmt == 'xml': root = ET.fromstring(raw).find('result') @@ -101,10 +102,10 @@ def test_format_reverse_with_address(fmt): rank_address=10, distance=0.0) ])) + reverse.localize(napi.Locales()) - raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt, - {'addressdetails': True}) - + raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt, + {'addressdetails': True}) if fmt == 'xml': root = ET.fromstring(raw) @@ -164,8 +165,10 @@ def test_format_reverse_geocodejson_special_parts(): distance=0.0) ])) - raw = api_impl.format_result(napi.ReverseResults([reverse]), 'geocodejson', - {'addressdetails': True}) + reverse.localize(napi.Locales()) + + raw = v1_format.format_result(napi.ReverseResults([reverse]), 'geocodejson', + {'addressdetails': True}) props = json.loads(raw)['features'][0]['properties']['geocoding'] assert props['housenumber'] == '1' @@ -180,9 +183,8 @@ def test_format_reverse_with_address_none(fmt): napi.Point(1.0, 2.0), address_rows=napi.AddressLines()) - raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt, - {'addressdetails': True}) - + raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt, + {'addressdetails': True}) if fmt == 'xml': root = ET.fromstring(raw) @@ -208,10 +210,10 @@ def test_format_reverse_with_extratags(fmt): reverse = napi.ReverseResult(napi.SourceTable.PLACEX, ('place', 'thing'), napi.Point(1.0, 2.0), - extratags={'one': 'A', 'two':'B'}) + extratags={'one': 'A', 'two': 'B'}) - raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt, - {'extratags': True}) + raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt, + {'extratags': True}) if fmt == 'xml': root = ET.fromstring(raw) @@ -223,7 +225,7 @@ def test_format_reverse_with_extratags(fmt): else: extra = result['extratags'] - assert extra == {'one': 'A', 'two':'B'} + assert extra == {'one': 'A', 'two': 'B'} @pytest.mark.parametrize('fmt', ['json', 'jsonv2', 'geojson', 'xml']) @@ -232,8 +234,8 @@ def test_format_reverse_with_extratags_none(fmt): ('place', 'thing'), napi.Point(1.0, 2.0)) - raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt, - {'extratags': True}) + raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt, + {'extratags': True}) if fmt == 'xml': root = ET.fromstring(raw) @@ -253,10 +255,10 @@ def test_format_reverse_with_namedetails_with_name(fmt): reverse = napi.ReverseResult(napi.SourceTable.PLACEX, ('place', 'thing'), napi.Point(1.0, 2.0), - names={'name': 'A', 'ref':'1'}) + names={'name': 'A', 'ref': '1'}) - raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt, - {'namedetails': True}) + raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt, + {'namedetails': True}) if fmt == 'xml': root = ET.fromstring(raw) @@ -268,7 +270,7 @@ def test_format_reverse_with_namedetails_with_name(fmt): else: extra = result['namedetails'] - assert extra == {'name': 'A', 'ref':'1'} + assert extra == {'name': 'A', 'ref': '1'} @pytest.mark.parametrize('fmt', ['json', 'jsonv2', 'geojson', 'xml']) @@ -277,8 +279,8 @@ def test_format_reverse_with_namedetails_without_name(fmt): ('place', 'thing'), napi.Point(1.0, 2.0)) - raw = api_impl.format_result(napi.ReverseResults([reverse]), fmt, - {'namedetails': True}) + raw = v1_format.format_result(napi.ReverseResults([reverse]), fmt, + {'namedetails': True}) if fmt == 'xml': root = ET.fromstring(raw) @@ -299,8 +301,8 @@ def test_search_details_with_icon_available(fmt): ('amenity', 'restaurant'), napi.Point(1.0, 2.0)) - result = api_impl.format_result(napi.ReverseResults([reverse]), fmt, - {'icon_base_url': 'foo'}) + result = v1_format.format_result(napi.ReverseResults([reverse]), fmt, + {'icon_base_url': 'foo'}) js = json.loads(result) @@ -313,8 +315,7 @@ def test_search_details_with_icon_not_available(fmt): ('amenity', 'tree'), napi.Point(1.0, 2.0)) - result = api_impl.format_result(napi.ReverseResults([reverse]), fmt, - {'icon_base_url': 'foo'}) + result = v1_format.format_result(napi.ReverseResults([reverse]), fmt, + {'icon_base_url': 'foo'}) assert 'icon' not in json.loads(result) -