]> git.openstreetmap.org Git - nominatim.git/blob - test/python/cli/test_cmd_index.py
prepare release 5.2.0.post14
[nominatim.git] / test / python / cli / test_cmd_index.py
1 # SPDX-License-Identifier: GPL-2.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2025 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for index command of the command-line interface wrapper.
9 """
10 import pytest
11
12 import nominatim_db.indexer.indexer
13
14
15 class TestCliIndexWithDb:
16
17     @pytest.fixture(autouse=True)
18     def setup_cli_call(self, cli_call, cli_tokenizer_mock):
19         self.call_nominatim = cli_call
20         self.tokenizer_mock = cli_tokenizer_mock
21
22     def test_index_empty_subset(self, monkeypatch, async_mock_func_factory, placex_row):
23         placex_row(rank_address=1, indexed_status=1)
24         placex_row(rank_address=20, indexed_status=1)
25
26         mocks = [
27             async_mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_boundaries'),
28             async_mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_by_rank'),
29             async_mock_func_factory(nominatim_db.indexer.indexer.Indexer, 'index_postcodes'),
30         ]
31
32         def _reject_repeat_call(*args, **kwargs):
33             assert False, "Did not expect multiple Indexer.has_pending invocations"
34
35         has_pending_calls = [nominatim_db.indexer.indexer.Indexer.has_pending, _reject_repeat_call]
36         monkeypatch.setattr(nominatim_db.indexer.indexer.Indexer, 'has_pending',
37                             lambda *args, **kwargs: has_pending_calls.pop(0)(*args, **kwargs))
38
39         assert self.call_nominatim('index', '--minrank', '5', '--maxrank', '10') == 0
40
41         for mock in mocks:
42             assert mock.called == 1, "Mock '{}' not called".format(mock.func_name)