]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tools/test_add_osm_data.py
Merge pull request #2542 from lonvia/update-phpunit
[nominatim.git] / test / python / tools / test_add_osm_data.py
1 """
2 Tests for functions to add additional data to the database.
3 """
4 from pathlib import Path
5
6 import pytest
7
8 from nominatim.tools import add_osm_data
9
10 class CaptureGetUrl:
11
12     def __init__(self, monkeypatch):
13         self.url = None
14         monkeypatch.setattr(add_osm_data, 'get_url', self)
15
16     def __call__(self, url):
17         self.url = url
18         return '<xml></xml>'
19
20
21 def test_import_osm_file_simple(table_factory, osm2pgsql_options, capfd):
22     table_factory('place', content=((1, ), ))
23
24     assert add_osm_data.add_data_from_file(Path('change.osm'), osm2pgsql_options) == 0
25     captured = capfd.readouterr()
26
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
33
34
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)
41
42     add_osm_data.add_osm_object(osm_type, 4536, main_api, osm2pgsql_options)
43     captured = capfd.readouterr()
44
45     assert get_url_mock.url.startswith(url)
46
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')