1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Test for various refresh functions.
10 from pathlib import Path
14 from nominatim.tools import refresh
16 def test_refresh_import_wikipedia_not_existing(dsn):
17 assert refresh.import_wikipedia_articles(dsn, Path('.')) == 1
20 def test_refresh_import_osm_views_geotiff_not_existing(dsn):
21 assert refresh.import_osm_views_geotiff(dsn, Path('.')) == 1
24 @pytest.mark.parametrize("replace", (True, False))
25 def test_refresh_import_wikipedia(dsn, src_dir, table_factory, temp_db_cursor, replace):
27 table_factory('wikipedia_article')
28 table_factory('wikipedia_redirect')
30 # use the small wikipedia file for the API testdb
31 assert refresh.import_wikipedia_articles(dsn, src_dir / 'test' / 'testdb') == 0
33 assert temp_db_cursor.table_rows('wikipedia_article') > 0
34 assert temp_db_cursor.table_rows('wikipedia_redirect') > 0
37 def test_recompute_importance(placex_table, table_factory, temp_db_conn, temp_db_cursor):
38 temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION compute_importance(extratags HSTORE,
39 country_code varchar(2),
40 osm_type varchar(1), osm_id BIGINT,
43 AS $$ SELECT 0.1::float, 'foo'::text $$ LANGUAGE SQL""")
45 refresh.recompute_importance(temp_db_conn)
48 @pytest.mark.parametrize('osm_type', ('N', 'W', 'R'))
49 def test_invalidate_osm_object_simple(placex_table, osm_type, temp_db_conn, temp_db_cursor):
50 placex_table.add(osm_type=osm_type, osm_id=57283)
52 refresh.invalidate_osm_object(osm_type, 57283, temp_db_conn, recursive=False)
55 assert 2 == temp_db_cursor.scalar("""SELECT indexed_status FROM placex
56 WHERE osm_type = %s and osm_id = %s""",
60 def test_invalidate_osm_object_nonexisting_simple(placex_table, temp_db_conn, temp_db_cursor):
61 placex_table.add(osm_type='W', osm_id=57283)
63 refresh.invalidate_osm_object('N', 57283, temp_db_conn, recursive=False)
66 assert 0 == temp_db_cursor.scalar("""SELECT count(*) FROM placex
67 WHERE indexed_status > 0""")
70 @pytest.mark.parametrize('osm_type', ('N', 'W', 'R'))
71 def test_invalidate_osm_object_recursive(placex_table, osm_type, temp_db_conn, temp_db_cursor):
72 placex_table.add(osm_type=osm_type, osm_id=57283)
74 temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION place_force_update(placeid BIGINT)
77 UPDATE placex SET indexed_status = 522
78 WHERE place_id = placeid;
84 refresh.invalidate_osm_object(osm_type, 57283, temp_db_conn)
87 assert 522 == temp_db_cursor.scalar("""SELECT indexed_status FROM placex
88 WHERE osm_type = %s and osm_id = %s""",