2 Tests for DB utility functions in db.utils
7 import nominatim.db.utils as db_utils
9 def test_execute_file_success(temp_db_conn, tmp_path):
10 tmpfile = tmp_path / 'test.sql'
11 tmpfile.write_text('CREATE TABLE test (id INT);\nINSERT INTO test VALUES(56);')
13 db_utils.execute_file(temp_db_conn, tmpfile)
15 with temp_db_conn.cursor() as cur:
16 cur.execute('SELECT * FROM test')
18 assert cur.rowcount == 1
19 assert cur.fetchone()[0] == 56
21 def test_execute_file_bad_file(temp_db_conn, tmp_path):
22 with pytest.raises(FileNotFoundError):
23 db_utils.execute_file(temp_db_conn, tmp_path / 'test2.sql')
25 def test_execute_file_bad_sql(temp_db_conn, tmp_path):
26 tmpfile = tmp_path / 'test.sql'
27 tmpfile.write_text('CREATE STABLE test (id INT)')
29 with pytest.raises(psycopg2.ProgrammingError):
30 db_utils.execute_file(temp_db_conn, tmpfile)