integrate analyse of indexing into nominatim tool

This commit is contained in:
Sarah Hoffmann
2021-02-08 22:21:57 +01:00
parent 0cbf98c020
commit d81e152804
6 changed files with 149 additions and 119 deletions

View File

@@ -153,3 +153,39 @@ def place_row(place_table, temp_db_cursor):
geom or 'SRID=4326;POINT(0 0 )'))
return _insert
@pytest.fixture
def placex_table(temp_db_with_extensions, temp_db_conn):
""" Create an empty version of the place table.
"""
with temp_db_conn.cursor() as cur:
cur.execute("""CREATE TABLE placex (
place_id BIGINT NOT NULL,
parent_place_id BIGINT,
linked_place_id BIGINT,
importance FLOAT,
indexed_date TIMESTAMP,
geometry_sector INTEGER,
rank_address SMALLINT,
rank_search SMALLINT,
partition SMALLINT,
indexed_status SMALLINT,
osm_id int8,
osm_type char(1),
class text,
type text,
name hstore,
admin_level smallint,
address hstore,
extratags hstore,
geometry Geometry(Geometry,4326),
wikipedia TEXT,
country_code varchar(2),
housenumber TEXT,
postcode TEXT,
centroid GEOMETRY(Geometry, 4326))
""")
temp_db_conn.commit()

View File

@@ -85,6 +85,13 @@ def test_admin_command_legacy(monkeypatch, params):
assert mock_run_legacy.called == 1
@pytest.mark.parametrize("func, params", [('analyse_indexing', ('--analyse-indexing', ))])
def test_admin_command_tool(monkeypatch, func, params):
mock = MockParamCapture()
monkeypatch.setattr(nominatim.tools.admin, func, mock)
assert 0 == call_nominatim('admin', *params)
assert mock.called == 1
@pytest.mark.parametrize("name,oid", [('file', 'foo.osm'), ('diff', 'foo.osc'),
('node', 12), ('way', 8), ('relation', 32)])

View File

@@ -0,0 +1,42 @@
"""
Tests for maintenance and analysis functions.
"""
import pytest
from nominatim.db.connection import connect
from nominatim.errors import UsageError
from nominatim.tools import admin
@pytest.fixture
def db(temp_db, placex_table):
conn = connect('dbname=' + temp_db)
yield conn
conn.close()
def test_analyse_indexing_no_objects(db):
with pytest.raises(UsageError):
admin.analyse_indexing(db)
@pytest.mark.parametrize("oid", ['1234', 'N123a', 'X123'])
def test_analyse_indexing_bad_osmid(db, oid):
with pytest.raises(UsageError):
admin.analyse_indexing(db, osm_id=oid)
def test_analyse_indexing_unknown_osmid(db):
with pytest.raises(UsageError):
admin.analyse_indexing(db, osm_id='W12345674')
def test_analyse_indexing_with_place_id(db, temp_db_cursor):
temp_db_cursor.execute("INSERT INTO placex (place_id) VALUES(12345)")
admin.analyse_indexing(db, place_id=12345)
def test_analyse_indexing_with_osm_id(db, temp_db_cursor):
temp_db_cursor.execute("""INSERT INTO placex (place_id, osm_type, osm_id)
VALUES(9988, 'N', 10000)""")
admin.analyse_indexing(db, osm_id='N10000')