forked from hans/Nominatim
test: use src_dir fixture instead of self-computed paths
This commit is contained in:
@@ -14,18 +14,6 @@ from nominatim.db import status
|
||||
|
||||
from mocks import MockParamCapture
|
||||
|
||||
SRC_DIR = (Path(__file__) / '..' / '..' / '..').resolve()
|
||||
|
||||
def call_nominatim(*args):
|
||||
return nominatim.cli.nominatim(module_dir='build/module',
|
||||
osm2pgsql_path='build/osm2pgsql/osm2pgsql',
|
||||
phplib_dir=str(SRC_DIR / 'lib-php'),
|
||||
data_dir=str(SRC_DIR / 'data'),
|
||||
phpcgi_path='/usr/bin/php-cgi',
|
||||
sqllib_dir=str(SRC_DIR / 'lib-sql'),
|
||||
config_dir=str(SRC_DIR / 'settings'),
|
||||
cli_args=['replication'] + list(args))
|
||||
|
||||
@pytest.fixture
|
||||
def tokenizer_mock(monkeypatch):
|
||||
class DummyTokenizer:
|
||||
@@ -77,73 +65,80 @@ def init_status(temp_db_conn, status_table):
|
||||
def update_mock(mock_func_factory, init_status, tokenizer_mock):
|
||||
return mock_func_factory(nominatim.tools.replication, 'update')
|
||||
|
||||
@pytest.mark.parametrize("params,func", [
|
||||
(('--init', '--no-update-functions'), 'init_replication'),
|
||||
(('--check-for-updates',), 'check_for_updates')
|
||||
])
|
||||
def test_replication_command(mock_func_factory, temp_db, params, func):
|
||||
func_mock = mock_func_factory(nominatim.tools.replication, func)
|
||||
|
||||
assert 0 == call_nominatim(*params)
|
||||
assert func_mock.called == 1
|
||||
class TestCliReplication:
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_cli_call(self, cli_call, temp_db):
|
||||
self.call_nominatim = lambda *args: cli_call('replication', *args)
|
||||
|
||||
@pytest.mark.parametrize("params,func", [
|
||||
(('--init', '--no-update-functions'), 'init_replication'),
|
||||
(('--check-for-updates',), 'check_for_updates')
|
||||
])
|
||||
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 func_mock.called == 1
|
||||
|
||||
|
||||
def test_replication_update_bad_interval(monkeypatch, temp_db):
|
||||
monkeypatch.setenv('NOMINATIM_REPLICATION_UPDATE_INTERVAL', 'xx')
|
||||
def test_replication_update_bad_interval(self, monkeypatch):
|
||||
monkeypatch.setenv('NOMINATIM_REPLICATION_UPDATE_INTERVAL', 'xx')
|
||||
|
||||
assert call_nominatim() == 1
|
||||
assert self.call_nominatim() == 1
|
||||
|
||||
|
||||
def test_replication_update_bad_interval_for_geofabrik(monkeypatch, temp_db):
|
||||
monkeypatch.setenv('NOMINATIM_REPLICATION_URL',
|
||||
'https://download.geofabrik.de/europe/ireland-and-northern-ireland-updates')
|
||||
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')
|
||||
|
||||
assert call_nominatim() == 1
|
||||
assert self.call_nominatim() == 1
|
||||
|
||||
|
||||
def test_replication_update_once_no_index(update_mock):
|
||||
assert 0 == call_nominatim('--once', '--no-index')
|
||||
def test_replication_update_once_no_index(self, update_mock):
|
||||
assert 0 == self.call_nominatim('--once', '--no-index')
|
||||
|
||||
assert str(update_mock.last_args[1]['osm2pgsql']) == 'build/osm2pgsql/osm2pgsql'
|
||||
assert str(update_mock.last_args[1]['osm2pgsql']) == 'OSM2PGSQL NOT AVAILABLE'
|
||||
|
||||
|
||||
def test_replication_update_custom_osm2pgsql(monkeypatch, update_mock):
|
||||
monkeypatch.setenv('NOMINATIM_OSM2PGSQL_BINARY', '/secret/osm2pgsql')
|
||||
assert 0 == call_nominatim('--once', '--no-index')
|
||||
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 str(update_mock.last_args[1]['osm2pgsql']) == '/secret/osm2pgsql'
|
||||
assert str(update_mock.last_args[1]['osm2pgsql']) == '/secret/osm2pgsql'
|
||||
|
||||
|
||||
def test_replication_update_custom_threads(update_mock):
|
||||
assert 0 == call_nominatim('--once', '--no-index', '--threads', '4')
|
||||
def test_replication_update_custom_threads(self, update_mock):
|
||||
assert 0 == self.call_nominatim('--once', '--no-index', '--threads', '4')
|
||||
|
||||
assert update_mock.last_args[1]['threads'] == 4
|
||||
assert update_mock.last_args[1]['threads'] == 4
|
||||
|
||||
|
||||
def test_replication_update_continuous(monkeypatch, init_status, index_mock):
|
||||
states = [nominatim.tools.replication.UpdateState.UP_TO_DATE,
|
||||
nominatim.tools.replication.UpdateState.UP_TO_DATE]
|
||||
monkeypatch.setattr(nominatim.tools.replication, 'update',
|
||||
lambda *args, **kwargs: states.pop())
|
||||
def test_replication_update_continuous(self, monkeypatch, init_status, index_mock):
|
||||
states = [nominatim.tools.replication.UpdateState.UP_TO_DATE,
|
||||
nominatim.tools.replication.UpdateState.UP_TO_DATE]
|
||||
monkeypatch.setattr(nominatim.tools.replication, 'update',
|
||||
lambda *args, **kwargs: states.pop())
|
||||
|
||||
with pytest.raises(IndexError):
|
||||
call_nominatim()
|
||||
with pytest.raises(IndexError):
|
||||
self.call_nominatim()
|
||||
|
||||
assert index_mock.called == 4
|
||||
assert index_mock.called == 4
|
||||
|
||||
|
||||
def test_replication_update_continuous_no_change(monkeypatch, init_status, index_mock):
|
||||
states = [nominatim.tools.replication.UpdateState.NO_CHANGES,
|
||||
nominatim.tools.replication.UpdateState.UP_TO_DATE]
|
||||
monkeypatch.setattr(nominatim.tools.replication, 'update',
|
||||
lambda *args, **kwargs: states.pop())
|
||||
def test_replication_update_continuous_no_change(self, monkeypatch, init_status, index_mock):
|
||||
states = [nominatim.tools.replication.UpdateState.NO_CHANGES,
|
||||
nominatim.tools.replication.UpdateState.UP_TO_DATE]
|
||||
monkeypatch.setattr(nominatim.tools.replication, 'update',
|
||||
lambda *args, **kwargs: states.pop())
|
||||
|
||||
sleep_mock = MockParamCapture()
|
||||
monkeypatch.setattr(time, 'sleep', sleep_mock)
|
||||
sleep_mock = MockParamCapture()
|
||||
monkeypatch.setattr(time, 'sleep', sleep_mock)
|
||||
|
||||
with pytest.raises(IndexError):
|
||||
call_nominatim()
|
||||
with pytest.raises(IndexError):
|
||||
self.call_nominatim()
|
||||
|
||||
assert index_mock.called == 2
|
||||
assert sleep_mock.called == 1
|
||||
assert sleep_mock.last_args[0] == 60
|
||||
assert index_mock.called == 2
|
||||
assert sleep_mock.called == 1
|
||||
assert sleep_mock.last_args[0] == 60
|
||||
|
||||
Reference in New Issue
Block a user