2022-01-03 18:23:58 +03:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
#
|
|
|
|
# This file is part of Nominatim. (https://nominatim.org)
|
|
|
|
#
|
|
|
|
# Copyright (C) 2022 by the Nominatim developer community.
|
|
|
|
# For a full list of authors see the git log.
|
2021-02-09 00:21:57 +03:00
|
|
|
"""
|
|
|
|
Tests for maintenance and analysis functions.
|
|
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from nominatim.errors import UsageError
|
|
|
|
from nominatim.tools import admin
|
|
|
|
|
2021-05-19 13:11:04 +03:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def create_placex_table(placex_table):
|
|
|
|
""" All tests in this module require the placex table to be set up.
|
|
|
|
"""
|
2021-02-09 00:21:57 +03:00
|
|
|
|
2021-05-19 13:11:04 +03:00
|
|
|
|
|
|
|
def test_analyse_indexing_no_objects(temp_db_conn):
|
2021-02-09 00:21:57 +03:00
|
|
|
with pytest.raises(UsageError):
|
2021-05-19 13:11:04 +03:00
|
|
|
admin.analyse_indexing(temp_db_conn)
|
2021-02-09 00:21:57 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("oid", ['1234', 'N123a', 'X123'])
|
2021-05-19 13:11:04 +03:00
|
|
|
def test_analyse_indexing_bad_osmid(temp_db_conn, oid):
|
2021-02-09 00:21:57 +03:00
|
|
|
with pytest.raises(UsageError):
|
2021-05-19 13:11:04 +03:00
|
|
|
admin.analyse_indexing(temp_db_conn, osm_id=oid)
|
2021-02-09 00:21:57 +03:00
|
|
|
|
|
|
|
|
2021-05-19 13:11:04 +03:00
|
|
|
def test_analyse_indexing_unknown_osmid(temp_db_conn):
|
2021-02-09 00:21:57 +03:00
|
|
|
with pytest.raises(UsageError):
|
2021-05-19 13:11:04 +03:00
|
|
|
admin.analyse_indexing(temp_db_conn, osm_id='W12345674')
|
2021-02-09 00:21:57 +03:00
|
|
|
|
|
|
|
|
2021-05-19 13:11:04 +03:00
|
|
|
def test_analyse_indexing_with_place_id(temp_db_conn, temp_db_cursor):
|
2021-02-09 00:21:57 +03:00
|
|
|
temp_db_cursor.execute("INSERT INTO placex (place_id) VALUES(12345)")
|
|
|
|
|
2021-05-19 13:11:04 +03:00
|
|
|
admin.analyse_indexing(temp_db_conn, place_id=12345)
|
2021-02-09 00:21:57 +03:00
|
|
|
|
|
|
|
|
2021-05-19 13:11:04 +03:00
|
|
|
def test_analyse_indexing_with_osm_id(temp_db_conn, temp_db_cursor):
|
2021-02-09 00:21:57 +03:00
|
|
|
temp_db_cursor.execute("""INSERT INTO placex (place_id, osm_type, osm_id)
|
|
|
|
VALUES(9988, 'N', 10000)""")
|
|
|
|
|
2021-05-19 13:11:04 +03:00
|
|
|
admin.analyse_indexing(temp_db_conn, osm_id='N10000')
|