]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tools/test_refresh.py
Merge pull request #2542 from lonvia/update-phpunit
[nominatim.git] / test / python / tools / test_refresh.py
1 """
2 Test for various refresh functions.
3 """
4 from pathlib import Path
5
6 import pytest
7
8 from nominatim.tools import refresh
9
10 def test_refresh_import_wikipedia_not_existing(dsn):
11     assert refresh.import_wikipedia_articles(dsn, Path('.')) == 1
12
13
14 @pytest.mark.parametrize("replace", (True, False))
15 def test_refresh_import_wikipedia(dsn, src_dir, table_factory, temp_db_cursor, replace):
16     if replace:
17         table_factory('wikipedia_article')
18         table_factory('wikipedia_redirect')
19
20     # use the small wikipedia file for the API testdb
21     assert refresh.import_wikipedia_articles(dsn, src_dir / 'test' / 'testdb') == 0
22
23     assert temp_db_cursor.table_rows('wikipedia_article') > 0
24     assert temp_db_cursor.table_rows('wikipedia_redirect') > 0
25
26
27 def test_recompute_importance(placex_table, table_factory, temp_db_conn, temp_db_cursor):
28     temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION compute_importance(extratags HSTORE,
29                                               country_code varchar(2),
30                                               osm_type varchar(1), osm_id BIGINT,
31                                               OUT importance FLOAT,
32                                               OUT wikipedia TEXT)
33                                AS $$ SELECT 0.1::float, 'foo'::text $$ LANGUAGE SQL""")
34
35     refresh.recompute_importance(temp_db_conn)