]> git.openstreetmap.org Git - nominatim.git/blob - test/python/test_tools_admin.py
port setup-website to python
[nominatim.git] / test / python / test_tools_admin.py
1 """
2 Tests for maintenance and analysis functions.
3 """
4 import pytest
5
6 from nominatim.db.connection import connect
7 from nominatim.errors import UsageError
8 from nominatim.tools import admin
9
10 @pytest.fixture
11 def db(temp_db, placex_table):
12     conn = connect('dbname=' + temp_db)
13     yield conn
14     conn.close()
15
16 def test_analyse_indexing_no_objects(db):
17     with pytest.raises(UsageError):
18         admin.analyse_indexing(db)
19
20
21 @pytest.mark.parametrize("oid", ['1234', 'N123a', 'X123'])
22 def test_analyse_indexing_bad_osmid(db, oid):
23     with pytest.raises(UsageError):
24         admin.analyse_indexing(db, osm_id=oid)
25
26
27 def test_analyse_indexing_unknown_osmid(db):
28     with pytest.raises(UsageError):
29         admin.analyse_indexing(db, osm_id='W12345674')
30
31
32 def test_analyse_indexing_with_place_id(db, temp_db_cursor):
33     temp_db_cursor.execute("INSERT INTO placex (place_id) VALUES(12345)")
34
35     admin.analyse_indexing(db, place_id=12345)
36
37
38 def test_analyse_indexing_with_osm_id(db, temp_db_cursor):
39     temp_db_cursor.execute("""INSERT INTO placex (place_id, osm_type, osm_id)
40                               VALUES(9988, 'N', 10000)""")
41
42     admin.analyse_indexing(db, osm_id='N10000')