2 Tests for functions to add additional data to the database.
4 from pathlib import Path
8 from nominatim.tools import add_osm_data
12 def __init__(self, monkeypatch):
14 monkeypatch.setattr(add_osm_data, 'get_url', self)
16 def __call__(self, url):
21 def test_import_osm_file_simple(table_factory, osm2pgsql_options, capfd):
22 table_factory('place', content=((1, ), ))
24 assert add_osm_data.add_data_from_file(Path('change.osm'), osm2pgsql_options) == 0
25 captured = capfd.readouterr()
27 assert '--append' in captured.out
28 assert '--output gazetteer' in captured.out
29 assert f'--style {osm2pgsql_options["osm2pgsql_style"]}' in captured.out
30 assert f'--number-processes {osm2pgsql_options["threads"]}' in captured.out
31 assert f'--cache {osm2pgsql_options["osm2pgsql_cache"]}' in captured.out
32 assert 'change.osm' in captured.out
35 @pytest.mark.parametrize("osm_type", ['node', 'way', 'relation'])
36 @pytest.mark.parametrize("main_api,url", [(True, 'https://www.openstreetmap.org/api'),
37 (False, 'https://overpass-api.de/api/interpreter?')])
38 def test_import_osm_object_main_api(osm2pgsql_options, monkeypatch, capfd,
39 osm_type, main_api, url):
40 get_url_mock = CaptureGetUrl(monkeypatch)
42 add_osm_data.add_osm_object(osm_type, 4536, main_api, osm2pgsql_options)
43 captured = capfd.readouterr()
45 assert get_url_mock.url.startswith(url)
47 assert '--append' in captured.out
48 assert '--output gazetteer' in captured.out
49 assert f'--style {osm2pgsql_options["osm2pgsql_style"]}' in captured.out
50 assert f'--number-processes {osm2pgsql_options["threads"]}' in captured.out
51 assert f'--cache {osm2pgsql_options["osm2pgsql_cache"]}' in captured.out
52 assert captured.out.endswith(' -\n')