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 MockParamCapture:
14 """ Mock that records the parameters with which a function was called
15 as well as the number of calls.
17 def __init__(self, retval=0):
19 self.return_value = retval
21 self.last_kwargs = None
23 def __call__(self, *args, **kwargs):
26 self.last_kwargs = kwargs
27 return self.return_value
30 class MockPlacexTable:
31 """ A placex table for testing.
33 def __init__(self, conn):
34 self.idseq = itertools.count(10000)
36 with conn.cursor() as cur:
37 cur.execute("""CREATE TABLE placex (
39 parent_place_id BIGINT,
40 linked_place_id BIGINT,
42 indexed_date TIMESTAMP,
43 geometry_sector INTEGER,
44 rank_address SMALLINT,
47 indexed_status SMALLINT,
56 geometry Geometry(Geometry,4326),
58 country_code varchar(2),
61 centroid GEOMETRY(Geometry, 4326))""")
62 cur.execute("CREATE SEQUENCE IF NOT EXISTS seq_place")
65 def add(self, osm_type='N', osm_id=None, cls='amenity', typ='cafe', names=None,
66 admin_level=None, address=None, extratags=None, geom='POINT(10 4)',
68 with self.conn.cursor() as cur:
69 psycopg2.extras.register_hstore(cur)
70 cur.execute("""INSERT INTO placex (place_id, osm_type, osm_id, class,
71 type, name, admin_level, address,
72 extratags, geometry, country_code)
73 VALUES(nextval('seq_place'), %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
74 (osm_type, osm_id or next(self.idseq), cls, typ, names,
75 admin_level, address, extratags, 'SRID=4326;' + geom,
80 class MockPropertyTable:
81 """ A property table for testing.
83 def __init__(self, conn):
87 def set(self, name, value):
88 """ Set a property in the table to the given value.
90 properties.set_property(self.conn, name, value)