]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tools/test_admin.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / test / python / tools / test_admin.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for maintenance and analysis functions.
9 """
10 import pytest
11
12 from nominatim.errors import UsageError
13 from nominatim.tools import admin
14
15 @pytest.fixture(autouse=True)
16 def create_placex_table(placex_table):
17     """ All tests in this module require the placex table to be set up.
18     """
19
20
21 def test_analyse_indexing_no_objects(temp_db_conn):
22     with pytest.raises(UsageError):
23         admin.analyse_indexing(temp_db_conn)
24
25
26 @pytest.mark.parametrize("oid", ['1234', 'N123a', 'X123'])
27 def test_analyse_indexing_bad_osmid(temp_db_conn, oid):
28     with pytest.raises(UsageError):
29         admin.analyse_indexing(temp_db_conn, osm_id=oid)
30
31
32 def test_analyse_indexing_unknown_osmid(temp_db_conn):
33     with pytest.raises(UsageError):
34         admin.analyse_indexing(temp_db_conn, osm_id='W12345674')
35
36
37 def test_analyse_indexing_with_place_id(temp_db_conn, temp_db_cursor):
38     temp_db_cursor.execute("INSERT INTO placex (place_id) VALUES(12345)")
39
40     admin.analyse_indexing(temp_db_conn, place_id=12345)
41
42
43 def test_analyse_indexing_with_osm_id(temp_db_conn, temp_db_cursor):
44     temp_db_cursor.execute("""INSERT INTO placex (place_id, osm_type, osm_id)
45                               VALUES(9988, 'N', 10000)""")
46
47     admin.analyse_indexing(temp_db_conn, osm_id='N10000')