def index_mock(monkeypatch): mock = MockParamCapture() monkeypatch.setattr(nominatim.indexer.indexer.Indexer, 'index_boundaries', mock) monkeypatch.setattr(nominatim.indexer.indexer.Indexer, 'index_by_rank', mock) return mock
def test_import_from_wiki(monkeypatch, temp_db_conn, def_config, special_phrases_importer, placex_table, getorcreate_amenity_funcs, getorcreate_amenityoperator_funcs, word_table): """ Check that the main import_from_wiki() method is well executed. It should create the place_classtype table, the place_id and centroid indexes, grand access to the web user and executing the SQL functions for amenities. """ mock_fetch_existing_words_phrases = MockParamCapture() mock_fetch_existing_place_classtype_tables = MockParamCapture() mock_remove_non_existent_phrases_from_db = MockParamCapture() monkeypatch.setattr( 'nominatim.tools.special_phrases.SpecialPhrasesImporter._fetch_existing_words_phrases', mock_fetch_existing_words_phrases) monkeypatch.setattr( 'nominatim.tools.special_phrases.SpecialPhrasesImporter._fetch_existing_place_classtype_tables', mock_fetch_existing_place_classtype_tables) monkeypatch.setattr( 'nominatim.tools.special_phrases.SpecialPhrasesImporter._remove_non_existent_phrases_from_db', mock_remove_non_existent_phrases_from_db) monkeypatch.setattr( 'nominatim.tools.special_phrases.SpecialPhrasesImporter._get_wiki_content', mock_get_wiki_content) special_phrases_importer.import_from_wiki(['en']) class_test = 'aerialway' type_test = 'zip_line' assert check_table_exist(temp_db_conn, class_test, type_test) assert check_placeid_and_centroid_indexes(temp_db_conn, class_test, type_test) assert check_grant_access(temp_db_conn, def_config.DATABASE_WEBUSER, class_test, type_test) assert check_amenities_with_op(temp_db_conn) assert check_amenities_without_op(temp_db_conn) assert mock_fetch_existing_words_phrases.called == 1 assert mock_fetch_existing_place_classtype_tables.called == 1 assert mock_remove_non_existent_phrases_from_db.called == 1
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()) sleep_mock = MockParamCapture() monkeypatch.setattr(time, 'sleep', sleep_mock) with pytest.raises(IndexError): call_nominatim() assert index_mock.called == 2 assert sleep_mock.called == 1 assert sleep_mock.last_args[0] == 60
def get_mock(module, func): mock = MockParamCapture() monkeypatch.setattr(module, func, mock) return mock
def mock_run_legacy(monkeypatch): mock = MockParamCapture() monkeypatch.setattr(nominatim.cli, 'run_legacy_script', mock) return mock
def index_mock(monkeypatch, tokenizer_mock, init_status): mock = MockParamCapture() monkeypatch.setattr(nominatim.indexer.indexer.Indexer, 'index_full', mock) return mock