2 Custom mocks for testing.
8 from nominatim.db import properties
10 # This must always point to the mock word table for the default tokenizer.
11 from mock_legacy_word_table import MockLegacyWordTable as MockWordTable
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,
39 geometry Geometry(Geometry,4326),
41 country_code varchar(2),
44 centroid GEOMETRY(Geometry, 4326))""")
45 cur.execute("CREATE SEQUENCE IF NOT EXISTS seq_place")
48 def add(self, osm_type='N', osm_id=None, cls='amenity', typ='cafe', names=None,
49 admin_level=None, address=None, extratags=None, geom='POINT(10 4)',
51 with self.conn.cursor() as cur:
52 psycopg2.extras.register_hstore(cur)
53 cur.execute("""INSERT INTO placex (place_id, osm_type, osm_id, class,
54 type, name, admin_level, address,
55 extratags, geometry, country_code)
56 VALUES(nextval('seq_place'), %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
57 (osm_type, osm_id or next(self.idseq), cls, typ, names,
58 admin_level, address, extratags, 'SRID=4326;' + geom,
63 class MockPropertyTable:
64 """ A property table for testing.
66 def __init__(self, conn):
70 def set(self, name, value):
71 """ Set a property in the table to the given value.
73 properties.set_property(self.conn, name, value)