]> git.openstreetmap.org Git - nominatim.git/blob - test/python/cli/test_cmd_admin.py
Merge remote-tracking branch 'upstream/master' into collect_os_info.sh
[nominatim.git] / test / python / cli / test_cmd_admin.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Test for the command line interface wrapper admin subcommand.
9
10 These tests just check that the various command line parameters route to the
11 correct functionionality. They use a lot of monkeypatching to avoid executing
12 the actual functions.
13 """
14 import pytest
15
16 import nominatim.tools.admin
17 import nominatim.tools.check_database
18 import nominatim.tools.migration
19 import nominatim.clicmd.admin
20
21
22 @pytest.mark.parametrize("params", [('--warm', ),
23                                     ('--warm', '--reverse-only'),
24                                     ('--warm', '--search-only')])
25 def test_admin_command_legacy(cli_call, mock_func_factory, params):
26     mock_run_legacy = mock_func_factory(nominatim.clicmd.admin, 'run_legacy_script')
27
28     assert cli_call('admin', *params) == 0
29
30     assert mock_run_legacy.called == 1
31
32
33 def test_admin_command_check_database(cli_call, mock_func_factory):
34     mock = mock_func_factory(nominatim.tools.check_database, 'check_database')
35
36     assert cli_call('admin', '--check-database') == 0
37     assert mock.called == 1
38
39
40 def test_admin_migrate(cli_call, mock_func_factory):
41     mock = mock_func_factory(nominatim.tools.migration, 'migrate')
42
43     assert cli_call('admin', '--migrate') == 0
44     assert mock.called == 1
45
46
47 class TestCliAdminWithDb:
48
49     @pytest.fixture(autouse=True)
50     def setup_cli_call(self, cli_call, temp_db, cli_tokenizer_mock):
51         self.call_nominatim = cli_call
52         self.tokenizer_mock = cli_tokenizer_mock
53
54
55     @pytest.mark.parametrize("func, params", [('analyse_indexing', ('--analyse-indexing', ))])
56     def test_analyse_indexing(self, mock_func_factory, func, params):
57         mock = mock_func_factory(nominatim.tools.admin, func)
58
59         assert self.call_nominatim('admin', *params) == 0
60         assert mock.called == 1