2 Tests for creating PL/pgSQL functions for Nominatim.
6 from nominatim.tools.refresh import create_functions
8 class TestCreateFunctions:
9 @pytest.fixture(autouse=True)
10 def init_env(self, sql_preprocessor, temp_db_conn, def_config, tmp_path):
11 self.conn = temp_db_conn
12 self.config = def_config
13 def_config.lib_dir.sql = tmp_path
16 def write_functions(self, content):
17 sqlfile = self.config.lib_dir.sql / 'functions.sql'
18 sqlfile.write_text(content)
21 def test_create_functions(self, temp_db_cursor):
22 self.write_functions("""CREATE OR REPLACE FUNCTION test() RETURNS INTEGER
27 $$ LANGUAGE plpgsql IMMUTABLE;
30 create_functions(self.conn, self.config)
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(self, temp_db_cursor, dbg, ret):
37 self.write_functions("""CREATE OR REPLACE FUNCTION test() RETURNS INTEGER
46 $$ LANGUAGE plpgsql IMMUTABLE;
49 create_functions(self.conn, self.config, enable_debug=dbg)
51 assert temp_db_cursor.scalar('SELECT test()') == ret