]> git.openstreetmap.org Git - nominatim.git/blob - test/python/tools/test_admin.py
reenable logging of details calls
[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 from nominatim.tokenizer import factory
15
16 @pytest.fixture(autouse=True)
17 def create_placex_table(project_env, tokenizer_mock, temp_db_cursor, placex_table):
18     """ All tests in this module require the placex table to be set up.
19     """
20     temp_db_cursor.execute("DROP TYPE IF EXISTS prepare_update_info CASCADE")
21     temp_db_cursor.execute("""CREATE TYPE prepare_update_info AS (
22                              name HSTORE,
23                              address HSTORE,
24                              rank_address SMALLINT,
25                              country_code TEXT,
26                              class TEXT,
27                              type TEXT,
28                              linked_place_id BIGINT
29                            )""")
30     temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION placex_indexing_prepare(p placex,
31                                                      OUT result prepare_update_info)
32                            AS $$
33                            BEGIN
34                              result.address := p.address;
35                              result.name := p.name;
36                              result.class := p.class;
37                              result.type := p.type;
38                              result.country_code := p.country_code;
39                              result.rank_address := p.rank_address;
40                            END;
41                            $$ LANGUAGE plpgsql STABLE;
42                         """)
43     factory.create_tokenizer(project_env)
44
45
46 def test_analyse_indexing_no_objects(project_env):
47     with pytest.raises(UsageError):
48         admin.analyse_indexing(project_env)
49
50
51 @pytest.mark.parametrize("oid", ['1234', 'N123a', 'X123'])
52 def test_analyse_indexing_bad_osmid(project_env, oid):
53     with pytest.raises(UsageError):
54         admin.analyse_indexing(project_env, osm_id=oid)
55
56
57 def test_analyse_indexing_unknown_osmid(project_env):
58     with pytest.raises(UsageError):
59         admin.analyse_indexing(project_env, osm_id='W12345674')
60
61
62 def test_analyse_indexing_with_place_id(project_env, temp_db_cursor):
63     temp_db_cursor.execute("INSERT INTO placex (place_id) VALUES(12345)")
64
65     admin.analyse_indexing(project_env, place_id=12345)
66
67
68 def test_analyse_indexing_with_osm_id(project_env, temp_db_cursor):
69     temp_db_cursor.execute("""INSERT INTO placex (place_id, osm_type, osm_id)
70                               VALUES(9988, 'N', 10000)""")
71
72     admin.analyse_indexing(project_env, osm_id='N10000')