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 command line interface wrapper for refresk command.
12 import nominatim.tools.refresh
13 import nominatim.tools.postcodes
14 import nominatim.indexer.indexer
18 @pytest.fixture(autouse=True)
19 def setup_cli_call(self, cli_call, temp_db, cli_tokenizer_mock):
20 self.call_nominatim = cli_call
21 self.tokenizer_mock = cli_tokenizer_mock
24 @pytest.mark.parametrize("command,func", [
25 ('address-levels', 'load_address_levels_from_config'),
26 ('wiki-data', 'import_wikipedia_articles'),
27 ('importance', 'recompute_importance'),
28 ('website', 'setup_website'),
30 def test_refresh_command(self, mock_func_factory, command, func):
31 func_mock = mock_func_factory(nominatim.tools.refresh, func)
33 assert self.call_nominatim('refresh', '--' + command) == 0
34 assert func_mock.called == 1
37 def test_refresh_word_count(self):
38 assert self.call_nominatim('refresh', '--word-count') == 0
39 assert self.tokenizer_mock.update_statistics_called
42 def test_refresh_postcodes(self, mock_func_factory, place_table):
43 func_mock = mock_func_factory(nominatim.tools.postcodes, 'update_postcodes')
44 idx_mock = mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_postcodes')
46 assert self.call_nominatim('refresh', '--postcodes') == 0
47 assert func_mock.called == 1
48 assert idx_mock.called == 1
51 def test_refresh_postcodes_no_place_table(self):
52 # Do nothing without the place table
53 assert self.call_nominatim('refresh', '--postcodes') == 0
56 def test_refresh_create_functions(self, mock_func_factory):
57 func_mock = mock_func_factory(nominatim.tools.refresh, 'create_functions')
59 assert self.call_nominatim('refresh', '--functions') == 0
60 assert func_mock.called == 1
61 assert self.tokenizer_mock.update_sql_functions_called
64 def test_refresh_wikidata_file_not_found(self, monkeypatch):
65 monkeypatch.setenv('NOMINATIM_WIKIPEDIA_DATA_PATH', 'gjoiergjeroi345Q')
67 assert self.call_nominatim('refresh', '--wiki-data') == 1
70 def test_refresh_importance_computed_after_wiki_import(self, monkeypatch):
72 monkeypatch.setattr(nominatim.tools.refresh, 'import_wikipedia_articles',
73 lambda *args, **kwargs: calls.append('import') or 0)
74 monkeypatch.setattr(nominatim.tools.refresh, 'recompute_importance',
75 lambda *args, **kwargs: calls.append('update'))
77 assert self.call_nominatim('refresh', '--importance', '--wiki-data') == 0
79 assert calls == ['import', 'update']