2 Tests for import command of the command-line interface wrapper.
6 import nominatim.tools.database_import
7 import nominatim.tools.country_info
8 import nominatim.tools.refresh
9 import nominatim.tools.postcodes
10 import nominatim.indexer.indexer
11 import nominatim.db.properties
14 class TestCliImportWithDb:
16 @pytest.fixture(autouse=True)
17 def setup_cli_call(self, cli_call, temp_db, cli_tokenizer_mock):
18 self.call_nominatim = cli_call
19 self.tokenizer_mock = cli_tokenizer_mock
22 def test_import_missing_file(self):
23 assert self.call_nominatim('import', '--osm-file', 'sfsafegwedgw.reh.erh') == 1
26 def test_import_bad_file(self):
27 assert self.call_nominatim('import', '--osm-file', '.') == 1
30 @pytest.mark.parametrize('with_updates', [True, False])
31 def test_import_full(self, mock_func_factory, with_updates, place_table, property_table):
33 mock_func_factory(nominatim.tools.database_import, 'setup_database_skeleton'),
34 mock_func_factory(nominatim.tools.country_info, 'setup_country_tables'),
35 mock_func_factory(nominatim.tools.database_import, 'import_osm_data'),
36 mock_func_factory(nominatim.tools.refresh, 'import_wikipedia_articles'),
37 mock_func_factory(nominatim.tools.database_import, 'truncate_data_tables'),
38 mock_func_factory(nominatim.tools.database_import, 'load_data'),
39 mock_func_factory(nominatim.tools.database_import, 'create_tables'),
40 mock_func_factory(nominatim.tools.database_import, 'create_table_triggers'),
41 mock_func_factory(nominatim.tools.database_import, 'create_partition_tables'),
42 mock_func_factory(nominatim.tools.database_import, 'create_search_indices'),
43 mock_func_factory(nominatim.tools.country_info, 'create_country_names'),
44 mock_func_factory(nominatim.tools.refresh, 'load_address_levels_from_config'),
45 mock_func_factory(nominatim.tools.postcodes, 'update_postcodes'),
46 mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_full'),
47 mock_func_factory(nominatim.tools.refresh, 'setup_website'),
50 params = ['import', '--osm-file', __file__]
53 mocks.append(mock_func_factory(nominatim.tools.freeze, 'drop_update_tables'))
54 params.append('--no-updates')
56 cf_mock = mock_func_factory(nominatim.tools.refresh, 'create_functions')
59 assert self.call_nominatim(*params) == 0
60 assert self.tokenizer_mock.finalize_import_called
62 assert cf_mock.called > 1
65 assert mock.called == 1, "Mock '{}' not called".format(mock.func_name)
68 def test_import_continue_load_data(self, mock_func_factory):
70 mock_func_factory(nominatim.tools.database_import, 'truncate_data_tables'),
71 mock_func_factory(nominatim.tools.database_import, 'load_data'),
72 mock_func_factory(nominatim.tools.database_import, 'create_search_indices'),
73 mock_func_factory(nominatim.tools.country_info, 'create_country_names'),
74 mock_func_factory(nominatim.tools.postcodes, 'update_postcodes'),
75 mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_full'),
76 mock_func_factory(nominatim.tools.refresh, 'setup_website'),
77 mock_func_factory(nominatim.db.properties, 'set_property')
80 assert self.call_nominatim('import', '--continue', 'load-data') == 0
81 assert self.tokenizer_mock.finalize_import_called
84 assert mock.called == 1, "Mock '{}' not called".format(mock.func_name)
87 def test_import_continue_indexing(self, mock_func_factory, placex_table,
90 mock_func_factory(nominatim.tools.database_import, 'create_search_indices'),
91 mock_func_factory(nominatim.tools.country_info, 'create_country_names'),
92 mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_full'),
93 mock_func_factory(nominatim.tools.refresh, 'setup_website'),
94 mock_func_factory(nominatim.db.properties, 'set_property')
97 assert self.call_nominatim('import', '--continue', 'indexing') == 0
100 assert mock.called == 1, "Mock '{}' not called".format(mock.func_name)
102 assert temp_db_conn.index_exists('idx_placex_pendingsector')
104 # Calling it again still works for the index
105 assert self.call_nominatim('import', '--continue', 'indexing') == 0
106 assert temp_db_conn.index_exists('idx_placex_pendingsector')
109 def test_import_continue_postprocess(self, mock_func_factory):
111 mock_func_factory(nominatim.tools.database_import, 'create_search_indices'),
112 mock_func_factory(nominatim.tools.country_info, 'create_country_names'),
113 mock_func_factory(nominatim.tools.refresh, 'setup_website'),
114 mock_func_factory(nominatim.db.properties, 'set_property')
117 assert self.call_nominatim('import', '--continue', 'db-postprocess') == 0
119 assert self.tokenizer_mock.finalize_import_called
122 assert mock.called == 1, "Mock '{}' not called".format(mock.func_name)