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(sql_preprocessor, temp_db_conn):
 
  18 def test_create_functions(temp_db_cursor, conn, def_config, sql_tmp_path):
 
  19     sqlfile = sql_tmp_path / 'functions.sql'
 
  20     sqlfile.write_text("""CREATE OR REPLACE FUNCTION test() RETURNS INTEGER
 
  25                           $$ LANGUAGE plpgsql IMMUTABLE;
 
  28     create_functions(conn, def_config)
 
  30     assert temp_db_cursor.scalar('SELECT test()') == 43
 
  33 @pytest.mark.parametrize("dbg,ret", ((True, 43), (False, 22)))
 
  34 def test_create_functions_with_template(temp_db_cursor, conn, def_config, sql_tmp_path,
 
  36     sqlfile = sql_tmp_path / 'functions.sql'
 
  37     sqlfile.write_text("""CREATE OR REPLACE FUNCTION test() RETURNS INTEGER
 
  46                           $$ LANGUAGE plpgsql IMMUTABLE;
 
  49     create_functions(conn, def_config, enable_debug=dbg)
 
  51     assert temp_db_cursor.scalar('SELECT test()') == ret