]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tools/test_refresh.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / test / python / tools / test_refresh.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Test for various refresh functions.
9 """
10 from pathlib import Path
11
12 import pytest
13
14 from nominatim.tools import refresh
15
16 def test_refresh_import_wikipedia_not_existing(dsn):
17     assert refresh.import_wikipedia_articles(dsn, Path('.')) == 1
18
19
20 @pytest.mark.parametrize("replace", (True, False))
21 def test_refresh_import_wikipedia(dsn, src_dir, table_factory, temp_db_cursor, replace):
22     if replace:
23         table_factory('wikipedia_article')
24         table_factory('wikipedia_redirect')
25
26     # use the small wikipedia file for the API testdb
27     assert refresh.import_wikipedia_articles(dsn, src_dir / 'test' / 'testdb') == 0
28
29     assert temp_db_cursor.table_rows('wikipedia_article') > 0
30     assert temp_db_cursor.table_rows('wikipedia_redirect') > 0
31
32
33 def test_recompute_importance(placex_table, table_factory, temp_db_conn, temp_db_cursor):
34     temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION compute_importance(extratags HSTORE,
35                                               country_code varchar(2),
36                                               osm_type varchar(1), osm_id BIGINT,
37                                               OUT importance FLOAT,
38                                               OUT wikipedia TEXT)
39                                AS $$ SELECT 0.1::float, 'foo'::text $$ LANGUAGE SQL""")
40
41     refresh.recompute_importance(temp_db_conn)