]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/python/test_cli.py
port replication initialisation to Python
[nominatim.git] / test / python / test_cli.py
index 9ac629731e6c0b41dc35d0b31f7c9f9e0b77a86f..ed46eba3d3bba64dabb08fae3871f3cdea4ba91c 100644 (file)
@@ -6,6 +6,8 @@ import pytest
 
 import nominatim.cli
 import nominatim.indexer.indexer
+import nominatim.tools.refresh
+import nominatim.tools.replication
 
 def call_nominatim(*args):
     return nominatim.cli.nominatim(module_dir='build/module',
@@ -55,7 +57,6 @@ def test_cli_help(capsys):
                          (('import', '--continue', 'load-data'), 'setup'),
                          (('freeze',), 'setup'),
                          (('special-phrases',), 'specialphrases'),
-                         (('replication',), 'update'),
                          (('add-data', '--tiger-data', 'tiger'), 'setup'),
                          (('add-data', '--file', 'foo.osm'), 'update'),
                          (('check-database',), 'check_import_finished'),
@@ -83,10 +84,8 @@ def test_add_data_command(mock_run_legacy, name, oid):
                           (['--boundaries-only'], 1, 0),
                           (['--no-boundaries'], 0, 1),
                           (['--boundaries-only', '--no-boundaries'], 0, 0)])
-def test_index_command(monkeypatch, temp_db, params, do_bnds, do_ranks):
-    with psycopg2.connect(database=temp_db) as conn:
-        with conn.cursor() as cur:
-            cur.execute("CREATE TABLE import_status (indexed bool)")
+def test_index_command(monkeypatch, temp_db_cursor, params, do_bnds, do_ranks):
+    temp_db_cursor.execute("CREATE TABLE import_status (indexed bool)")
     bnd_mock = MockParamCapture()
     monkeypatch.setattr(nominatim.indexer.indexer.Indexer, 'index_boundaries', bnd_mock)
     rank_mock = MockParamCapture()
@@ -99,29 +98,51 @@ def test_index_command(monkeypatch, temp_db, params, do_bnds, do_ranks):
 
 
 @pytest.mark.parametrize("command,params", [
-                         ('postcodes', ('update.php', '--calculate-postcodes')),
-                         ('word-counts', ('update.php', '--recompute-word-counts')),
-                         ('address-levels', ('update.php', '--update-address-levels')),
-                         ('functions', ('setup.php',)),
                          ('wiki-data', ('setup.php', '--import-wikipedia-articles')),
                          ('importance', ('update.php', '--recompute-importance')),
                          ('website', ('setup.php', '--setup-website')),
                          ])
-def test_refresh_command(mock_run_legacy, command, params):
+def test_refresh_legacy_command(mock_run_legacy, temp_db, command, params):
     assert 0 == call_nominatim('refresh', '--' + command)
 
     assert mock_run_legacy.called == 1
     assert len(mock_run_legacy.last_args) >= len(params)
     assert mock_run_legacy.last_args[:len(params)] == params
 
+@pytest.mark.parametrize("command,func", [
+                         ('postcodes', 'update_postcodes'),
+                         ('word-counts', 'recompute_word_counts'),
+                         ('address-levels', 'load_address_levels_from_file'),
+                         ('functions', 'create_functions'),
+                         ])
+def test_refresh_command(monkeypatch, temp_db, command, func):
+    func_mock = MockParamCapture()
+    monkeypatch.setattr(nominatim.tools.refresh, func, func_mock)
+
+    assert 0 == call_nominatim('refresh', '--' + command)
+
+    assert func_mock.called == 1
+
 
-def test_refresh_importance_computed_after_wiki_import(mock_run_legacy):
+def test_refresh_importance_computed_after_wiki_import(mock_run_legacy, temp_db):
     assert 0 == call_nominatim('refresh', '--importance', '--wiki-data')
 
     assert mock_run_legacy.called == 2
     assert mock_run_legacy.last_args == ('update.php', '--recompute-importance')
 
 
+@pytest.mark.parametrize("params,func", [
+                         (('--init', '--no-update-functions'), 'init_replication')
+                         ])
+def test_replication_command(monkeypatch, temp_db, params, func):
+    func_mock = MockParamCapture()
+    monkeypatch.setattr(nominatim.tools.replication, func, func_mock)
+
+    assert 0 == call_nominatim('replication', *params)
+
+    assert func_mock.called == 1
+
+
 @pytest.mark.parametrize("params", [
                          ('search', '--query', 'new'),
                          ('reverse', '--lat', '0', '--lon', '0'),