1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2025 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Custom mocks for testing.
13 class MockPlacexTable:
14 """ A placex table for testing.
16 def __init__(self, conn):
17 self.idseq = itertools.count(10000)
19 with conn.cursor() as cur:
20 cur.execute("""CREATE TABLE placex (
22 parent_place_id BIGINT,
23 linked_place_id BIGINT,
25 indexed_date TIMESTAMP,
26 geometry_sector INTEGER,
27 rank_address SMALLINT,
30 indexed_status SMALLINT,
40 geometry Geometry(Geometry,4326),
42 country_code varchar(2),
45 centroid GEOMETRY(Geometry, 4326))""")
46 cur.execute("CREATE SEQUENCE IF NOT EXISTS seq_place")
49 def add(self, osm_type='N', osm_id=None, cls='amenity', typ='cafe', names=None,
50 admin_level=None, address=None, extratags=None, geom='POINT(10 4)',
51 country=None, housenumber=None, rank_search=30, centroid=None):
52 with self.conn.cursor() as cur:
53 cur.execute("""INSERT INTO placex (place_id, osm_type, osm_id, class,
54 type, name, admin_level, address,
55 housenumber, rank_search,
56 extratags, centroid, geometry, country_code)
57 VALUES(nextval('seq_place'), %s, %s, %s, %s, %s, %s,
58 %s, %s, %s, %s, %s, %s, %s)
59 RETURNING place_id""",
60 (osm_type, osm_id or next(self.idseq), cls, typ, names,
61 admin_level, address, housenumber, rank_search,
62 extratags, centroid, 'SRID=4326;' + geom,
64 place_id = cur.fetchone()[0]