2 Tests for command line interface wrapper for refresk command.
6 import nominatim.tools.refresh
7 import nominatim.tools.postcodes
8 import nominatim.indexer.indexer
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
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'),
24 def test_refresh_command(self, mock_func_factory, command, func):
25 func_mock = mock_func_factory(nominatim.tools.refresh, func)
27 assert self.call_nominatim('refresh', '--' + command) == 0
28 assert func_mock.called == 1
31 def test_refresh_word_count(self):
32 assert self.call_nominatim('refresh', '--word-count') == 0
33 assert self.tokenizer_mock.update_statistics_called
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')
40 assert self.call_nominatim('refresh', '--postcodes') == 0
41 assert func_mock.called == 1
42 assert idx_mock.called == 1
45 def test_refresh_postcodes_no_place_table(self):
46 # Do nothing without the place table
47 assert self.call_nominatim('refresh', '--postcodes') == 0
50 def test_refresh_create_functions(self, mock_func_factory):
51 func_mock = mock_func_factory(nominatim.tools.refresh, 'create_functions')
53 assert self.call_nominatim('refresh', '--functions') == 0
54 assert func_mock.called == 1
55 assert self.tokenizer_mock.update_sql_functions_called
58 def test_refresh_wikidata_file_not_found(self, monkeypatch):
59 monkeypatch.setenv('NOMINATIM_WIKIPEDIA_DATA_PATH', 'gjoiergjeroi345Q')
61 assert self.call_nominatim('refresh', '--wiki-data') == 1
64 def test_refresh_importance_computed_after_wiki_import(self, monkeypatch):
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'))
71 assert self.call_nominatim('refresh', '--importance', '--wiki-data') == 0
73 assert calls == ['import', 'update']