1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Custom mocks for testing.
12 import psycopg2.extras
14 from nominatim.db import properties
16 # This must always point to the mock word table for the default tokenizer.
17 from mock_legacy_word_table import MockLegacyWordTable as MockWordTable
19 class MockPlacexTable:
20 """ A placex table for testing.
22 def __init__(self, conn):
23 self.idseq = itertools.count(10000)
25 with conn.cursor() as cur:
26 cur.execute("""CREATE TABLE placex (
28 parent_place_id BIGINT,
29 linked_place_id BIGINT,
31 indexed_date TIMESTAMP,
32 geometry_sector INTEGER,
33 rank_address SMALLINT,
36 indexed_status SMALLINT,
45 geometry Geometry(Geometry,4326),
47 country_code varchar(2),
50 centroid GEOMETRY(Geometry, 4326))""")
51 cur.execute("CREATE SEQUENCE IF NOT EXISTS seq_place")
54 def add(self, osm_type='N', osm_id=None, cls='amenity', typ='cafe', names=None,
55 admin_level=None, address=None, extratags=None, geom='POINT(10 4)',
56 country=None, housenumber=None):
57 with self.conn.cursor() as cur:
58 psycopg2.extras.register_hstore(cur)
59 cur.execute("""INSERT INTO placex (place_id, osm_type, osm_id, class,
60 type, name, admin_level, address,
62 extratags, geometry, country_code)
63 VALUES(nextval('seq_place'), %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
64 (osm_type, osm_id or next(self.idseq), cls, typ, names,
65 admin_level, address, housenumber, extratags, 'SRID=4326;' + geom,
70 class MockPropertyTable:
71 """ A property table for testing.
73 def __init__(self, conn):
77 def set(self, name, value):
78 """ Set a property in the table to the given value.
80 properties.set_property(self.conn, name, value)
84 """ Set a property in the table to the given value.
86 return properties.get_property(self.conn, name)