2 Tests for creating PL/pgSQL functions for Nominatim.
4 from pathlib import Path
7 from nominatim.db.connection import connect
8 from nominatim.tools.refresh import _get_standard_function_sql, _get_partition_function_sql
10 SQL_DIR = (Path(__file__) / '..' / '..' / '..' / 'sql').resolve()
14 conn = connect('dbname=' + temp_db)
19 def db_with_tables(db):
20 with db.cursor() as cur:
21 for table in ('place', 'placex', 'location_postcode'):
22 cur.execute('CREATE TABLE {} (place_id BIGINT)'.format(table))
27 def test_standard_functions_replace_module_default(db, def_config):
28 def_config.project_dir = Path('.')
29 sql = _get_standard_function_sql(db, def_config, SQL_DIR, False, False)
32 assert sql.find('{modulepath}') < 0
33 assert sql.find("'{}'".format(Path('module/nominatim.so').resolve())) >= 0
36 def test_standard_functions_replace_module_custom(monkeypatch, db, def_config):
37 monkeypatch.setenv('NOMINATIM_DATABASE_MODULE_PATH', 'custom')
38 sql = _get_standard_function_sql(db, def_config, SQL_DIR, False, False)
41 assert sql.find('{modulepath}') < 0
42 assert sql.find("'custom/nominatim.so'") >= 0
45 @pytest.mark.parametrize("enabled", (True, False))
46 def test_standard_functions_enable_diff(db_with_tables, def_config, enabled):
47 def_config.project_dir = Path('.')
48 sql = _get_standard_function_sql(db_with_tables, def_config, SQL_DIR, enabled, False)
51 assert (sql.find('%DIFFUPDATES%') < 0) == enabled
54 @pytest.mark.parametrize("enabled", (True, False))
55 def test_standard_functions_enable_debug(db_with_tables, def_config, enabled):
56 def_config.project_dir = Path('.')
57 sql = _get_standard_function_sql(db_with_tables, def_config, SQL_DIR, False, enabled)
60 assert (sql.find('--DEBUG') < 0) == enabled
63 @pytest.mark.parametrize("enabled", (True, False))
64 def test_standard_functions_enable_limit_reindexing(monkeypatch, db_with_tables, def_config, enabled):
65 def_config.project_dir = Path('.')
66 monkeypatch.setenv('NOMINATIM_LIMIT_REINDEXING', 'yes' if enabled else 'no')
67 sql = _get_standard_function_sql(db_with_tables, def_config, SQL_DIR, False, False)
70 assert (sql.find('--LIMIT INDEXING') < 0) == enabled
73 @pytest.mark.parametrize("enabled", (True, False))
74 def test_standard_functions_enable_tiger(monkeypatch, db_with_tables, def_config, enabled):
75 def_config.project_dir = Path('.')
76 monkeypatch.setenv('NOMINATIM_USE_US_TIGER_DATA', 'yes' if enabled else 'no')
77 sql = _get_standard_function_sql(db_with_tables, def_config, SQL_DIR, False, False)
80 assert (sql.find('%NOTIGERDATA%') >= 0) == enabled
83 @pytest.mark.parametrize("enabled", (True, False))
84 def test_standard_functions_enable_aux(monkeypatch, db_with_tables, def_config, enabled):
85 def_config.project_dir = Path('.')
86 monkeypatch.setenv('NOMINATIM_USE_AUX_LOCATION_DATA', 'yes' if enabled else 'no')
87 sql = _get_standard_function_sql(db_with_tables, def_config, SQL_DIR, False, False)
90 assert (sql.find('%NOAUXDATA%') >= 0) == enabled
93 def test_partition_function(temp_db_cursor, db, def_config):
94 temp_db_cursor.execute("CREATE TABLE country_name (partition SMALLINT)")
96 sql = _get_partition_function_sql(db, SQL_DIR)
99 assert sql.find('-partition-') < 0