]> git.openstreetmap.org Git - nominatim.git/blob - test/bdd/steps/osm_data.py
aeca56372d6177387119d163dbdc4496d60687fb
[nominatim.git] / test / bdd / steps / osm_data.py
1 import subprocess
2 import tempfile
3 import random
4 import os
5 from nose.tools import * # for assert functions
6
7 @when(u'loading osm data')
8 def load_osm_file(context):
9
10     # create a OSM file in /tmp and import it
11     with tempfile.NamedTemporaryFile(dir='/tmp', suffix='.opl', delete=False) as fd:
12         fname = fd.name
13         for line in context.text.splitlines():
14             if line.startswith('n') and line.find(' x') < 0:
15                     line += " x%d y%d" % (random.random()*360 - 180,
16                                           random.random()*180 - 90)
17             fd.write(line.encode('utf-8'))
18             fd.write(b'\n')
19
20     context.nominatim.run_setup_script('import-data', osm_file=fname,
21                                        osm2pgsql_cache=300)
22
23     ### reintroduce the triggers/indexes we've lost by having osm2pgsql set up place again
24     cur = context.db.cursor()
25     cur.execute("""CREATE TRIGGER place_before_delete BEFORE DELETE ON place
26                     FOR EACH ROW EXECUTE PROCEDURE place_delete()""")
27     cur.execute("""CREATE TRIGGER place_before_insert BEFORE INSERT ON place
28                    FOR EACH ROW EXECUTE PROCEDURE place_insert()""")
29     cur.execute("""CREATE UNIQUE INDEX idx_place_osm_unique on place using btree(osm_id,osm_type,class,type)""")
30     context.db.commit()
31
32     os.remove(fname)
33