2 Tests for specialised conenction and cursor classes.
6 from nominatim.db.connection import connect
10 with connect('dbname=' + temp_db) as conn:
14 def test_connection_table_exists(db, temp_db_cursor):
15 assert db.table_exists('foobar') == False
17 temp_db_cursor.execute('CREATE TABLE foobar (id INT)')
19 assert db.table_exists('foobar') == True
22 def test_connection_index_exists(db, temp_db_cursor):
23 assert db.index_exists('some_index') == False
25 temp_db_cursor.execute('CREATE TABLE foobar (id INT)')
26 temp_db_cursor.execute('CREATE INDEX some_index ON foobar(id)')
28 assert db.index_exists('some_index') == True
29 assert db.index_exists('some_index', table='foobar') == True
30 assert db.index_exists('some_index', table='bar') == False
33 def test_connection_server_version_tuple(db):
34 ver = db.server_version_tuple()
36 assert isinstance(ver, tuple)
40 def test_cursor_scalar(db, temp_db_cursor):
41 temp_db_cursor.execute('CREATE TABLE dummy (id INT)')
43 with db.cursor() as cur:
44 assert cur.scalar('SELECT count(*) FROM dummy') == 0
47 def test_cursor_scalar_many_rows(db):
48 with db.cursor() as cur:
49 with pytest.raises(RuntimeError):
50 cur.scalar('SELECT * FROM pg_tables')