1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2024 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_db.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_secondary_importance_non_existing(dsn):
21 assert refresh.import_secondary_importance(dsn, Path('.')) == 1
23 def test_refresh_import_secondary_importance_testdb(dsn, src_dir, temp_db_conn, temp_db_cursor):
24 temp_db_cursor.execute('CREATE EXTENSION postgis')
26 if temp_db_conn.postgis_version_tuple()[0] < 3:
27 assert refresh.import_secondary_importance(dsn, src_dir / 'test' / 'testdb') > 0
29 temp_db_cursor.execute('CREATE EXTENSION postgis_raster')
30 assert refresh.import_secondary_importance(dsn, src_dir / 'test' / 'testdb') == 0
32 assert temp_db_conn.table_exists('secondary_importance')
35 @pytest.mark.parametrize("replace", (True, False))
36 def test_refresh_import_wikipedia(dsn, src_dir, table_factory, temp_db_cursor, replace):
38 table_factory('wikimedia_importance')
40 # use the small wikipedia file for the API testdb
41 assert refresh.import_wikipedia_articles(dsn, src_dir / 'test' / 'testdb') == 0
43 assert temp_db_cursor.table_rows('wikipedia_article') > 0
44 assert temp_db_cursor.table_rows('wikipedia_redirect') > 0
47 def test_recompute_importance(placex_table, table_factory, temp_db_conn, temp_db_cursor):
48 temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION compute_importance(extratags HSTORE,
49 country_code varchar(2),
54 AS $$ SELECT 0.1::float, 'foo'::text $$ LANGUAGE SQL""")
56 refresh.recompute_importance(temp_db_conn)
59 @pytest.mark.parametrize('osm_type', ('N', 'W', 'R'))
60 def test_invalidate_osm_object_simple(placex_table, osm_type, temp_db_conn, temp_db_cursor):
61 placex_table.add(osm_type=osm_type, osm_id=57283)
63 refresh.invalidate_osm_object(osm_type, 57283, temp_db_conn, recursive=False)
66 assert 2 == temp_db_cursor.scalar("""SELECT indexed_status FROM placex
67 WHERE osm_type = %s and osm_id = %s""",
71 def test_invalidate_osm_object_nonexisting_simple(placex_table, temp_db_conn, temp_db_cursor):
72 placex_table.add(osm_type='W', osm_id=57283)
74 refresh.invalidate_osm_object('N', 57283, temp_db_conn, recursive=False)
77 assert 0 == temp_db_cursor.scalar("""SELECT count(*) FROM placex
78 WHERE indexed_status > 0""")
81 @pytest.mark.parametrize('osm_type', ('N', 'W', 'R'))
82 def test_invalidate_osm_object_recursive(placex_table, osm_type, temp_db_conn, temp_db_cursor):
83 placex_table.add(osm_type=osm_type, osm_id=57283)
85 temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION place_force_update(placeid BIGINT)
88 UPDATE placex SET indexed_status = 522
89 WHERE place_id = placeid;
95 refresh.invalidate_osm_object(osm_type, 57283, temp_db_conn)
98 assert 522 == temp_db_cursor.scalar("""SELECT indexed_status FROM placex
99 WHERE osm_type = %s and osm_id = %s""",