1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2024 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Custom mocks for testing.
12 from nominatim_db.db import properties
14 # This must always point to the mock word table for the default tokenizer.
15 from mock_icu_word_table import MockIcuWordTable as MockWordTable
17 class MockPlacexTable:
18 """ A placex table for testing.
20 def __init__(self, conn):
21 self.idseq = itertools.count(10000)
23 with conn.cursor() as cur:
24 cur.execute("""CREATE TABLE placex (
26 parent_place_id BIGINT,
27 linked_place_id BIGINT,
29 indexed_date TIMESTAMP,
30 geometry_sector INTEGER,
31 rank_address SMALLINT,
34 indexed_status SMALLINT,
44 geometry Geometry(Geometry,4326),
46 country_code varchar(2),
49 centroid GEOMETRY(Geometry, 4326))""")
50 cur.execute("CREATE SEQUENCE IF NOT EXISTS seq_place")
53 def add(self, osm_type='N', osm_id=None, cls='amenity', typ='cafe', names=None,
54 admin_level=None, address=None, extratags=None, geom='POINT(10 4)',
55 country=None, housenumber=None, rank_search=30):
56 with self.conn.cursor() as cur:
57 cur.execute("""INSERT INTO placex (place_id, osm_type, osm_id, class,
58 type, name, admin_level, address,
59 housenumber, rank_search,
60 extratags, geometry, country_code)
61 VALUES(nextval('seq_place'), %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
62 (osm_type, osm_id or next(self.idseq), cls, typ, names,
63 admin_level, address, housenumber, rank_search,
64 extratags, 'SRID=4326;' + geom,
69 class MockPropertyTable:
70 """ A property table for testing.
72 def __init__(self, conn):
76 def set(self, name, value):
77 """ Set a property in the table to the given value.
79 properties.set_property(self.conn, name, value)
83 """ Set a property in the table to the given value.
85 return properties.get_property(self.conn, name)