]> git.openstreetmap.org Git - nominatim.git/blob - test/python/cli/test_cmd_refresh.py
split cli tests by subcommand and extend coverage
[nominatim.git] / test / python / cli / test_cmd_refresh.py
1 """
2 Tests for command line interface wrapper for refresk command.
3 """
4 import pytest
5
6 import nominatim.tools.refresh
7 import nominatim.tools.postcodes
8 import nominatim.indexer.indexer
9
10 class TestRefresh:
11
12     @pytest.fixture(autouse=True)
13     def setup_cli_call(self, cli_call, temp_db, cli_tokenizer_mock):
14         self.call_nominatim = cli_call
15         self.tokenizer_mock = cli_tokenizer_mock
16
17
18     @pytest.mark.parametrize("command,func", [
19                              ('address-levels', 'load_address_levels_from_config'),
20                              ('wiki-data', 'import_wikipedia_articles'),
21                              ('importance', 'recompute_importance'),
22                              ('website', 'setup_website'),
23                              ])
24     def test_refresh_command(self, mock_func_factory, command, func):
25         func_mock = mock_func_factory(nominatim.tools.refresh, func)
26
27         assert self.call_nominatim('refresh', '--' + command) == 0
28         assert func_mock.called == 1
29
30
31     def test_refresh_word_count(self):
32         assert self.call_nominatim('refresh', '--word-count') == 0
33         assert self.tokenizer_mock.update_statistics_called
34
35
36     def test_refresh_postcodes(self, mock_func_factory, place_table):
37         func_mock = mock_func_factory(nominatim.tools.postcodes, 'update_postcodes')
38         idx_mock = mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_postcodes')
39
40         assert self.call_nominatim('refresh', '--postcodes') == 0
41         assert func_mock.called == 1
42         assert idx_mock.called == 1
43
44
45     def test_refresh_postcodes_no_place_table(self):
46         # Do nothing without the place table
47         assert self.call_nominatim('refresh', '--postcodes') == 0
48
49
50     def test_refresh_create_functions(self, mock_func_factory):
51         func_mock = mock_func_factory(nominatim.tools.refresh, 'create_functions')
52
53         assert self.call_nominatim('refresh', '--functions') == 0
54         assert func_mock.called == 1
55         assert self.tokenizer_mock.update_sql_functions_called
56
57
58     def test_refresh_wikidata_file_not_found(self, monkeypatch):
59         monkeypatch.setenv('NOMINATIM_WIKIPEDIA_DATA_PATH', 'gjoiergjeroi345Q')
60
61         assert self.call_nominatim('refresh', '--wiki-data') == 1
62
63
64     def test_refresh_importance_computed_after_wiki_import(self, monkeypatch):
65         calls = []
66         monkeypatch.setattr(nominatim.tools.refresh, 'import_wikipedia_articles',
67                             lambda *args, **kwargs: calls.append('import') or 0)
68         monkeypatch.setattr(nominatim.tools.refresh, 'recompute_importance',
69                             lambda *args, **kwargs: calls.append('update'))
70
71         assert self.call_nominatim('refresh', '--importance', '--wiki-data') == 0
72
73         assert calls == ['import', 'update']