From 80a74181e463efeb071a3904346107d05e88a7a6 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 29 Nov 2016 21:34:31 +0100 Subject: [PATCH] add osm2pgsql update tests --- test/bdd/environment.py | 4 +- test/bdd/osm2pgsql/update/relation.feature | 126 +++++++++++++++++++++ test/bdd/osm2pgsql/update/simple.feature | 26 +++++ test/bdd/steps/osm_data.py | 29 ++++- 4 files changed, 181 insertions(+), 4 deletions(-) create mode 100644 test/bdd/osm2pgsql/update/relation.feature create mode 100644 test/bdd/osm2pgsql/update/simple.feature diff --git a/test/bdd/environment.py b/test/bdd/environment.py index 29c6675c..3af3fb58 100644 --- a/test/bdd/environment.py +++ b/test/bdd/environment.py @@ -125,8 +125,8 @@ class NominatimEnvironment(object): def run_setup_script(self, *args, **kwargs): self.run_nominatim_script('setup', *args, **kwargs) - def run_update_script(self, *args): - self.run_nominatim_script('update', *args) + def run_update_script(self, *args, **kwargs): + self.run_nominatim_script('update', *args, **kwargs) def run_nominatim_script(self, script, *args, **kwargs): cmd = [os.path.join(self.build_dir, 'utils', '%s.php' % script)] diff --git a/test/bdd/osm2pgsql/update/relation.feature b/test/bdd/osm2pgsql/update/relation.feature new file mode 100644 index 00000000..88889f9a --- /dev/null +++ b/test/bdd/osm2pgsql/update/relation.feature @@ -0,0 +1,126 @@ +@DB +Feature: Update of relations by osm2pgsql + Testing relation update by osm2pgsql. + + Scenario: Remove all members of a relation + When loading osm data + """ + n1 Tamenity=prison,name=foo + n200 x0 y0 + n201 x0 y0.0001 + n202 x0.0001 y0.0001 + n203 x0.0001 y0 + w2 Tref=45' Nn200,n201,n202,n203,n200 + r1 Ttype=multipolygon,tourism=hotel,name=XZ' Mw2@ + """ + Then place contains + | object | class | type | name + | R1 | tourism | hotel | 'name' : 'XZ' + When updating osm data + """ + r1 Ttype=multipolygon,tourism=hotel,name=XZ Mn1@ + """ + Then place has no entry for R1 + + + Scenario: Change type of a relation + When loading osm data + """ + n200 x0 y0 + n201 x0 y0.0001 + n202 x0.0001 y0.0001 + n203 x0.0001 y0 + w2 Tref=45 Nn200,n201,n202,n203,n200 + r1 Ttype=multipolygon,tourism=hotel,name=XZ Mw2@ + """ + Then place contains + | object | class | type | name + | R1 | tourism | hotel | 'name' : 'XZ' + When updating osm data + """ + r1 Ttype=multipolygon,amenity=prison,name=XZ Mw2@ + """ + Then place has no entry for R1:tourism + And place contains + | object | class | type | name + | R1 | amenity | prison | 'name' : 'XZ' + + Scenario: Change name of a relation + When loading osm data + """ + n200 x0 y0 + n201 x0 y0.0001 + n202 x0.0001 y0.0001 + n203 x0.0001 y0 + w2 Tref=45 Nn200,n201,n202,n203,n200 + r1 Ttype=multipolygon,tourism=hotel,name=AB Mw2@ + """ + Then place contains + | object | class | type | name + | R1 | tourism | hotel | 'name' : 'AB' + When updating osm data + """ + r1 Ttype=multipolygon,tourism=hotel,name=XY Mw2@ + """ + Then place contains + | object | class | type | name + | R1 | tourism | hotel | 'name' : 'XZ' + + Scenario: Change type of a relation into something unknown + When loading osm data + """ + n200 x0 y0 + n201 x0 y0.0001 + n202 x0.0001 y0.0001 + n203 x0.0001 y0 + w2 Tref=45 Nn200,n201,n202,n203,n200 + r1 Ttype=multipolygon,tourism=hotel,name=XY Mw2@ + """ + Then place contains + | object | class | type | name + | R1 | tourism | hotel | 'name' : 'XZ' + When updating osm data + """ + r1 Ttype=multipolygon,amenities=prison,name=XY Mw2@ + """ + Then place has no entry for R1 + + Scenario: Type tag is removed + When loading osm data + """ + n200 x0 y0 + n201 x0 y0.0001 + n202 x0.0001 y0.0001 + n203 x0.0001 y0 + w2 Tref=45 Nn200,n201,n202,n203,n200 + r1 Ttype=multipolygon,tourism=hotel,name=XY Mw2@ + """ + Then place contains + | object | class | type | name + | R1 | tourism | hotel | 'name' : 'XZ' + When updating osm data + """ + r1 Ttourism=hotel,name=XY Mw2@ + """ + Then place has no entry for R1 + + @wip + Scenario: Type tag is renamed to something unknown + When loading osm data + """ + n200 x0 y0 + n201 x0 y0.0001 + n202 x0.0001 y0.0001 + n203 x0.0001 y0 + w2 Tref=45 Nn200,n201,n202,n203,n200 + r1 Ttype=multipolygon,tourism=hotel,name=XY Mw2@ + """ + Then place contains + | object | class | type | name + | R1 | tourism | hotel | 'name' : 'XZ' + When updating osm data + """ + r1 Ttype=multipolygonn,tourism=hotel,name=XY Mw2@ + """ + Then place has no entry for R1 + diff --git a/test/bdd/osm2pgsql/update/simple.feature b/test/bdd/osm2pgsql/update/simple.feature new file mode 100644 index 00000000..33c21039 --- /dev/null +++ b/test/bdd/osm2pgsql/update/simple.feature @@ -0,0 +1,26 @@ +@DB +Feature: Update of simple objects by osm2pgsql + Testing basic update functions of osm2pgsql. + + Scenario: Import object with two main tags + When loading osm data + """ + n1 Ttourism=hotel,amenity=restaurant,name=foo + n2 Tplace=locality,name=spotty + """ + Then place contains + | object | type | name + | N1:tourism | hotel | 'name' : 'foo' + | N1:amenity | restaurant | 'name' : 'foo' + | N2:place | locality | 'name' : 'spotty' + When updating osm data + """ + n1 dV Ttourism=hotel,name=foo + n2 dD + """ + Then place has no entry for N1:amenity + And place has no entry for N2 + And place contains + | object | class | type | name + | N1:tourism | tourism | hotel | 'name' : 'foo' + diff --git a/test/bdd/steps/osm_data.py b/test/bdd/steps/osm_data.py index aeca5637..926fb9ab 100644 --- a/test/bdd/steps/osm_data.py +++ b/test/bdd/steps/osm_data.py @@ -12,8 +12,8 @@ def load_osm_file(context): fname = fd.name for line in context.text.splitlines(): if line.startswith('n') and line.find(' x') < 0: - line += " x%d y%d" % (random.random()*360 - 180, - random.random()*180 - 90) + line += " x%d y%d" % (random.random() * 360 - 180, + random.random() * 180 - 90) fd.write(line.encode('utf-8')) fd.write(b'\n') @@ -31,3 +31,28 @@ def load_osm_file(context): os.remove(fname) +@when(u'updating osm data') +def update_from_osm_file(context): + context.nominatim.run_setup_script('create-functions', 'create-partition-functions') + + cur = context.db.cursor() + cur.execute("""insert into placex (osm_type, osm_id, class, type, name, + admin_level, housenumber, street, addr_place, isin, postcode, + country_code, extratags, geometry) select * from place""") + context.db.commit() + context.nominatim.run_setup_script('index', 'index-noanalyse') + context.nominatim.run_setup_script('create-functions', 'create-partition-functions', + 'enable-diff-updates') + + # create a OSM file in /tmp and import it + with tempfile.NamedTemporaryFile(dir='/tmp', suffix='.opl', delete=False) as fd: + fname = fd.name + for line in context.text.splitlines(): + if line.startswith('n') and line.find(' x') < 0: + line += " x%d y%d" % (random.random() * 360 - 180, + random.random() * 180 - 90) + fd.write(line.encode('utf-8')) + fd.write(b'\n') + + context.nominatim.run_update_script(import_diff=fname) + os.remove(fname) -- 2.39.5