]> git.openstreetmap.org Git - nominatim.git/blob - test/python/cli/test_cmd_admin.py
added subcommand to clean deleted relations for issue # 2444
[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 def test_admin_command_check_database(cli_call, mock_func_factory):
23     mock = mock_func_factory(nominatim.tools.check_database, 'check_database')
24
25     assert cli_call('admin', '--check-database') == 0
26     assert mock.called == 1
27
28
29 def test_admin_migrate(cli_call, mock_func_factory):
30     mock = mock_func_factory(nominatim.tools.migration, 'migrate')
31
32     assert cli_call('admin', '--migrate') == 0
33     assert mock.called == 1
34
35
36 def test_admin_clean_deleted_relations(cli_call, mock_func_factory):
37     mock = mock_func_factory(nominatim.tools.admin, 'clean_deleted_relations')
38
39     assert cli_call('admin', '--clean-deleted') == 0
40     assert mock.called == 1
41
42 class TestCliAdminWithDb:
43
44     @pytest.fixture(autouse=True)
45     def setup_cli_call(self, cli_call, temp_db, cli_tokenizer_mock):
46         self.call_nominatim = cli_call
47         self.tokenizer_mock = cli_tokenizer_mock
48
49
50     @pytest.mark.parametrize("func, params", [('analyse_indexing', ('--analyse-indexing', ))])
51     def test_analyse_indexing(self, mock_func_factory, func, params):
52         mock = mock_func_factory(nominatim.tools.admin, func)
53
54         assert self.call_nominatim('admin', *params) == 0
55         assert mock.called == 1