X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/f93d0fa95745c9f1e5b1126e8dd4b09a9daa32d2..0fb8eade136ea03e7853aca0795ca69833c33661:/test/python/test_cli_replication.py?ds=sidebyside diff --git a/test/python/test_cli_replication.py b/test/python/test_cli_replication.py index ebb89443..dcaeaf25 100644 --- a/test/python/test_cli_replication.py +++ b/test/python/test_cli_replication.py @@ -3,7 +3,6 @@ Tests for replication command of command-line interface wrapper. """ import datetime as dt import time -from pathlib import Path import pytest @@ -28,23 +27,14 @@ def tokenizer_mock(monkeypatch): self.finalize_import_called = True tok = DummyTokenizer() - monkeypatch.setattr(nominatim.tokenizer.factory, 'get_tokenizer_for_db' , + monkeypatch.setattr(nominatim.tokenizer.factory, 'get_tokenizer_for_db', lambda *args: tok) - monkeypatch.setattr(nominatim.tokenizer.factory, 'create_tokenizer' , + monkeypatch.setattr(nominatim.tokenizer.factory, 'create_tokenizer', lambda *args: tok) return tok -@pytest.fixture -def index_mock(monkeypatch, tokenizer_mock): - mock = MockParamCapture() - monkeypatch.setattr(nominatim.indexer.indexer.Indexer, 'index_boundaries', mock) - monkeypatch.setattr(nominatim.indexer.indexer.Indexer, 'index_by_rank', mock) - - return mock - - @pytest.fixture def mock_func_factory(monkeypatch): def get_mock(module, func): @@ -58,7 +48,15 @@ def mock_func_factory(monkeypatch): @pytest.fixture def init_status(temp_db_conn, status_table): status.set_status(temp_db_conn, date=dt.datetime.now(dt.timezone.utc), seq=1) - return 1 + + +@pytest.fixture +def index_mock(monkeypatch, tokenizer_mock, init_status): + mock = MockParamCapture() + monkeypatch.setattr(nominatim.indexer.indexer.Indexer, 'index_boundaries', mock) + monkeypatch.setattr(nominatim.indexer.indexer.Indexer, 'index_by_rank', mock) + + return mock @pytest.fixture @@ -79,7 +77,7 @@ class TestCliReplication: def test_replication_command(self, mock_func_factory, params, func): func_mock = mock_func_factory(nominatim.tools.replication, func) - assert 0 == self.call_nominatim(*params) + assert self.call_nominatim(*params) == 0 assert func_mock.called == 1 @@ -91,31 +89,31 @@ class TestCliReplication: def test_replication_update_bad_interval_for_geofabrik(self, monkeypatch): monkeypatch.setenv('NOMINATIM_REPLICATION_URL', - 'https://download.geofabrik.de/europe/ireland-and-northern-ireland-updates') + 'https://download.geofabrik.de/europe/italy-updates') assert self.call_nominatim() == 1 def test_replication_update_once_no_index(self, update_mock): - assert 0 == self.call_nominatim('--once', '--no-index') + assert self.call_nominatim('--once', '--no-index') == 0 assert str(update_mock.last_args[1]['osm2pgsql']) == 'OSM2PGSQL NOT AVAILABLE' def test_replication_update_custom_osm2pgsql(self, monkeypatch, update_mock): monkeypatch.setenv('NOMINATIM_OSM2PGSQL_BINARY', '/secret/osm2pgsql') - assert 0 == self.call_nominatim('--once', '--no-index') + assert self.call_nominatim('--once', '--no-index') == 0 assert str(update_mock.last_args[1]['osm2pgsql']) == '/secret/osm2pgsql' def test_replication_update_custom_threads(self, update_mock): - assert 0 == self.call_nominatim('--once', '--no-index', '--threads', '4') + assert self.call_nominatim('--once', '--no-index', '--threads', '4') == 0 assert update_mock.last_args[1]['threads'] == 4 - def test_replication_update_continuous(self, monkeypatch, init_status, index_mock): + def test_replication_update_continuous(self, monkeypatch, index_mock): states = [nominatim.tools.replication.UpdateState.UP_TO_DATE, nominatim.tools.replication.UpdateState.UP_TO_DATE] monkeypatch.setattr(nominatim.tools.replication, 'update', @@ -127,7 +125,7 @@ class TestCliReplication: assert index_mock.called == 4 - def test_replication_update_continuous_no_change(self, monkeypatch, init_status, index_mock): + def test_replication_update_continuous_no_change(self, monkeypatch, index_mock): states = [nominatim.tools.replication.UpdateState.NO_CHANGES, nominatim.tools.replication.UpdateState.UP_TO_DATE] monkeypatch.setattr(nominatim.tools.replication, 'update',