X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/c06a1d007a4e67ab5caf5bf63d351f83e4e54ab6..73953cbac95847740339d7a5ee3c0e5f142d93c5:/test/python/test_tools_replication.py diff --git a/test/python/test_tools_replication.py b/test/python/test_tools_replication.py index ee48eef5..2bf2901b 100644 --- a/test/python/test_tools_replication.py +++ b/test/python/test_tools_replication.py @@ -18,21 +18,25 @@ OSM_NODE_DATA = """\ """ +@pytest.fixture(autouse=True) +def setup_status_table(status_table): + pass + ### init replication -def test_init_replication_bad_base_url(monkeypatch, status_table, place_row, temp_db_conn): +def test_init_replication_bad_base_url(monkeypatch, place_row, temp_db_conn): place_row(osm_type='N', osm_id=100) - monkeypatch.setattr(nominatim.db.status, "get_url", lambda u : OSM_NODE_DATA) + monkeypatch.setattr(nominatim.db.status, "get_url", lambda u: OSM_NODE_DATA) with pytest.raises(UsageError, match="Failed to reach replication service"): nominatim.tools.replication.init_replication(temp_db_conn, 'https://test.io') -def test_init_replication_success(monkeypatch, status_table, place_row, temp_db_conn, temp_db_cursor): +def test_init_replication_success(monkeypatch, place_row, temp_db_conn, temp_db_cursor): place_row(osm_type='N', osm_id=100) - monkeypatch.setattr(nominatim.db.status, "get_url", lambda u : OSM_NODE_DATA) + monkeypatch.setattr(nominatim.db.status, "get_url", lambda u: OSM_NODE_DATA) monkeypatch.setattr(nominatim.tools.replication.ReplicationServer, "timestamp_to_sequence", lambda self, date: 234) @@ -48,17 +52,17 @@ def test_init_replication_success(monkeypatch, status_table, place_row, temp_db_ ### checking for updates -def test_check_for_updates_empty_status_table(status_table, temp_db_conn): +def test_check_for_updates_empty_status_table(temp_db_conn): assert nominatim.tools.replication.check_for_updates(temp_db_conn, 'https://test.io') == 254 -def test_check_for_updates_seq_not_set(status_table, temp_db_conn): +def test_check_for_updates_seq_not_set(temp_db_conn): status.set_status(temp_db_conn, dt.datetime.now(dt.timezone.utc)) assert nominatim.tools.replication.check_for_updates(temp_db_conn, 'https://test.io') == 254 -def test_check_for_updates_no_state(monkeypatch, status_table, temp_db_conn): +def test_check_for_updates_no_state(monkeypatch, temp_db_conn): status.set_status(temp_db_conn, dt.datetime.now(dt.timezone.utc), seq=345) monkeypatch.setattr(nominatim.tools.replication.ReplicationServer, @@ -68,7 +72,7 @@ def test_check_for_updates_no_state(monkeypatch, status_table, temp_db_conn): @pytest.mark.parametrize("server_sequence,result", [(344, 2), (345, 2), (346, 0)]) -def test_check_for_updates_no_new_data(monkeypatch, status_table, temp_db_conn, +def test_check_for_updates_no_new_data(monkeypatch, temp_db_conn, server_sequence, result): date = dt.datetime.now(dt.timezone.utc) status.set_status(temp_db_conn, date, seq=345) @@ -85,24 +89,24 @@ def test_check_for_updates_no_new_data(monkeypatch, status_table, temp_db_conn, @pytest.fixture def update_options(tmpdir): return dict(base_url='https://test.io', - indexed_only=False, - update_interval=3600, - import_file=tmpdir / 'foo.osm', - max_diff_size=1) + indexed_only=False, + update_interval=3600, + import_file=tmpdir / 'foo.osm', + max_diff_size=1) -def test_update_empty_status_table(status_table, temp_db_conn): +def test_update_empty_status_table(temp_db_conn): with pytest.raises(UsageError): nominatim.tools.replication.update(temp_db_conn, {}) -def test_update_already_indexed(status_table, temp_db_conn): +def test_update_already_indexed(temp_db_conn): status.set_status(temp_db_conn, dt.datetime.now(dt.timezone.utc), seq=34, indexed=False) assert nominatim.tools.replication.update(temp_db_conn, dict(indexed_only=True)) \ == nominatim.tools.replication.UpdateState.MORE_PENDING -def test_update_no_data_no_sleep(monkeypatch, status_table, temp_db_conn, update_options): +def test_update_no_data_no_sleep(monkeypatch, temp_db_conn, update_options): date = dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=1) status.set_status(temp_db_conn, date, seq=34) @@ -111,7 +115,7 @@ def test_update_no_data_no_sleep(monkeypatch, status_table, temp_db_conn, update lambda *args, **kwargs: None) sleeptime = [] - monkeypatch.setattr(time, 'sleep', lambda s: sleeptime.append(s)) + monkeypatch.setattr(time, 'sleep', sleeptime.append) assert nominatim.tools.replication.update(temp_db_conn, update_options) \ == nominatim.tools.replication.UpdateState.NO_CHANGES @@ -119,7 +123,7 @@ def test_update_no_data_no_sleep(monkeypatch, status_table, temp_db_conn, update assert not sleeptime -def test_update_no_data_sleep(monkeypatch, status_table, temp_db_conn, update_options): +def test_update_no_data_sleep(monkeypatch, temp_db_conn, update_options): date = dt.datetime.now(dt.timezone.utc) - dt.timedelta(minutes=30) status.set_status(temp_db_conn, date, seq=34) @@ -128,7 +132,7 @@ def test_update_no_data_sleep(monkeypatch, status_table, temp_db_conn, update_op lambda *args, **kwargs: None) sleeptime = [] - monkeypatch.setattr(time, 'sleep', lambda s: sleeptime.append(s)) + monkeypatch.setattr(time, 'sleep', sleeptime.append) assert nominatim.tools.replication.update(temp_db_conn, update_options) \ == nominatim.tools.replication.UpdateState.NO_CHANGES