2 Tests for creating PL/pgSQL functions for Nominatim.
6 from nominatim.tools.refresh import create_functions
9 def sql_tmp_path(tmp_path, def_config):
10 def_config.lib_dir.sql = tmp_path
14 def conn(temp_db_conn, table_factory, monkeypatch):
15 monkeypatch.setenv('NOMINATIM_DATABASE_MODULE_PATH', '.')
16 table_factory('country_name', 'partition INT', (0, 1, 2))
20 def test_create_functions(temp_db_cursor, conn, def_config, sql_tmp_path):
21 sqlfile = sql_tmp_path / 'functions.sql'
22 sqlfile.write_text("""CREATE OR REPLACE FUNCTION test() RETURNS INTEGER
27 $$ LANGUAGE plpgsql IMMUTABLE;
30 create_functions(conn, def_config, sql_tmp_path)
32 assert temp_db_cursor.scalar('SELECT test()') == 43
35 @pytest.mark.parametrize("dbg,ret", ((True, 43), (False, 22)))
36 def test_create_functions_with_template(temp_db_cursor, conn, def_config, sql_tmp_path, dbg, ret):
37 sqlfile = sql_tmp_path / 'functions.sql'
38 sqlfile.write_text("""CREATE OR REPLACE FUNCTION test() RETURNS INTEGER
47 $$ LANGUAGE plpgsql IMMUTABLE;
50 create_functions(conn, def_config, sql_tmp_path, enable_debug=dbg)
52 assert temp_db_cursor.scalar('SELECT test()') == ret