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)',
50 country=None, housenumber=None):
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,
56 extratags, geometry, country_code)
57 VALUES(nextval('seq_place'), %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
58 (osm_type, osm_id or next(self.idseq), cls, typ, names,
59 admin_level, address, housenumber, extratags, 'SRID=4326;' + geom,
64 class MockPropertyTable:
65 """ A property table for testing.
67 def __init__(self, conn):
71 def set(self, name, value):
72 """ Set a property in the table to the given value.
74 properties.set_property(self.conn, name, value)
78 """ Set a property in the table to the given value.
80 return properties.get_property(self.conn, name)