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