1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Tests for creating PL/pgSQL functions for Nominatim.
12 from nominatim.tools.refresh import create_functions
14 class TestCreateFunctions:
15 @pytest.fixture(autouse=True)
16 def init_env(self, sql_preprocessor, temp_db_conn, def_config, tmp_path):
17 self.conn = temp_db_conn
18 self.config = def_config
19 def_config.lib_dir.sql = tmp_path
22 def write_functions(self, content):
23 sqlfile = self.config.lib_dir.sql / 'functions.sql'
24 sqlfile.write_text(content)
27 def test_create_functions(self, temp_db_cursor):
28 self.write_functions("""CREATE OR REPLACE FUNCTION test() RETURNS INTEGER
33 $$ LANGUAGE plpgsql IMMUTABLE;
36 create_functions(self.conn, self.config)
38 assert temp_db_cursor.scalar('SELECT test()') == 43
41 @pytest.mark.parametrize("dbg,ret", ((True, 43), (False, 22)))
42 def test_create_functions_with_template(self, temp_db_cursor, dbg, ret):
43 self.write_functions("""CREATE OR REPLACE FUNCTION test() RETURNS INTEGER
52 $$ LANGUAGE plpgsql IMMUTABLE;
55 create_functions(self.conn, self.config, enable_debug=dbg)
57 assert temp_db_cursor.scalar('SELECT test()') == ret