1 # SPDX-License-Identifier: GPL-3.0-or-later
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2025 by the Nominatim developer community.
 
   6 # For a full list of authors see the git log.
 
   8 Test for the command line interface wrapper admin subcommand.
 
  10 These tests just check that the various command line parameters route to the
 
  11 correct functionality. They use a lot of monkeypatching to avoid executing
 
  16 import nominatim_db.tools.admin
 
  17 import nominatim_db.tools.check_database
 
  18 import nominatim_db.tools.migration
 
  19 import nominatim_db.clicmd.admin
 
  22 def test_admin_command_check_database(cli_call, mock_func_factory):
 
  23     mock = mock_func_factory(nominatim_db.tools.check_database, 'check_database')
 
  25     assert cli_call('admin', '--check-database') == 0
 
  26     assert mock.called == 1
 
  29 def test_admin_migrate(cli_call, mock_func_factory):
 
  30     mock = mock_func_factory(nominatim_db.tools.migration, 'migrate')
 
  32     assert cli_call('admin', '--migrate') == 0
 
  33     assert mock.called == 1
 
  36 def test_admin_clean_deleted_relations(cli_call, mock_func_factory):
 
  37     mock = mock_func_factory(nominatim_db.tools.admin, 'clean_deleted_relations')
 
  39     assert cli_call('admin', '--clean-deleted', '1 month') == 0
 
  40     assert mock.called == 1
 
  43 def test_admin_clean_deleted_relations_no_age(cli_call, mock_func_factory):
 
  44     mock_func_factory(nominatim_db.tools.admin, 'clean_deleted_relations')
 
  46     assert cli_call('admin', '--clean-deleted') == 1
 
  49 class TestCliAdminWithDb:
 
  51     @pytest.fixture(autouse=True)
 
  52     def setup_cli_call(self, cli_call, temp_db, cli_tokenizer_mock):
 
  53         self.call_nominatim = cli_call
 
  54         self.tokenizer_mock = cli_tokenizer_mock
 
  56     @pytest.mark.parametrize("func, params", [('analyse_indexing', ('--analyse-indexing', ))])
 
  57     def test_analyse_indexing(self, mock_func_factory, func, params):
 
  58         mock = mock_func_factory(nominatim_db.tools.admin, func)
 
  60         assert self.call_nominatim('admin', *params) == 0
 
  61         assert mock.called == 1