1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Tests for functions to add additional data to the database.
10 from pathlib import Path
14 from nominatim.tools import add_osm_data
18 def __init__(self, monkeypatch):
20 monkeypatch.setattr(add_osm_data, 'get_url', self)
22 def __call__(self, url):
27 def test_import_osm_file_simple(table_factory, osm2pgsql_options, capfd):
28 table_factory('place', content=((1, ), ))
30 assert add_osm_data.add_data_from_file(Path('change.osm'), osm2pgsql_options) == 0
31 captured = capfd.readouterr()
33 assert '--append' in captured.out
34 assert '--output gazetteer' in captured.out
35 assert f'--style {osm2pgsql_options["osm2pgsql_style"]}' in captured.out
36 assert f'--number-processes {osm2pgsql_options["threads"]}' in captured.out
37 assert f'--cache {osm2pgsql_options["osm2pgsql_cache"]}' in captured.out
38 assert 'change.osm' in captured.out
41 @pytest.mark.parametrize("osm_type", ['node', 'way', 'relation'])
42 @pytest.mark.parametrize("main_api,url", [(True, 'https://www.openstreetmap.org/api'),
43 (False, 'https://overpass-api.de/api/interpreter?')])
44 def test_import_osm_object_main_api(osm2pgsql_options, monkeypatch, capfd,
45 osm_type, main_api, url):
46 get_url_mock = CaptureGetUrl(monkeypatch)
48 add_osm_data.add_osm_object(osm_type, 4536, main_api, osm2pgsql_options)
49 captured = capfd.readouterr()
51 assert get_url_mock.url.startswith(url)
53 assert '--append' in captured.out
54 assert '--output gazetteer' in captured.out
55 assert f'--style {osm2pgsql_options["osm2pgsql_style"]}' in captured.out
56 assert f'--number-processes {osm2pgsql_options["threads"]}' in captured.out
57 assert f'--cache {osm2pgsql_options["osm2pgsql_cache"]}' in captured.out
58 assert captured.out.endswith(' -\n')