]> git.openstreetmap.org Git - nominatim.git/blob - test/python/test_db_connection.py
convert functon creation to python
[nominatim.git] / test / python / test_db_connection.py
1 """
2 Tests for specialised conenction and cursor classes.
3 """
4 import pytest
5
6 from nominatim.db.connection import connect
7
8 @pytest.fixture
9 def db(temp_db):
10     conn = connect('dbname=' + temp_db)
11     yield conn
12     conn.close()
13
14
15 def test_connection_table_exists(db, temp_db_cursor):
16     assert db.table_exists('foobar') == False
17
18     temp_db_cursor.execute('CREATE TABLE foobar (id INT)')
19
20     assert db.table_exists('foobar') == True
21
22
23 def test_cursor_scalar(db, temp_db_cursor):
24     temp_db_cursor.execute('CREATE TABLE dummy (id INT)')
25
26     with db.cursor() as cur:
27         assert cur.scalar('SELECT count(*) FROM dummy') == 0
28
29 def test_cursor_scalar_many_rows(db):
30     with db.cursor() as cur:
31         with pytest.raises(ValueError):
32             cur.scalar('SELECT * FROM pg_tables')