From 589825d37ecac89c459aa19de544b7f99f7879a3 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 23 Oct 2025 16:03:36 +0200 Subject: [PATCH] adapt tests for extra place_entrance table --- test/bdd/features/db/import/entrances.feature | 6 ++-- test/bdd/features/db/update/entrances.feature | 32 ++++++++++------- test/bdd/test_db.py | 35 +++++++++++++++++++ test/bdd/utils/place_inserter.py | 22 ++++++------ 4 files changed, 71 insertions(+), 24 deletions(-) diff --git a/test/bdd/features/db/import/entrances.feature b/test/bdd/features/db/import/entrances.feature index d2a3e3fc..9a956eb1 100644 --- a/test/bdd/features/db/import/entrances.feature +++ b/test/bdd/features/db/import/entrances.feature @@ -8,8 +8,10 @@ Feature: Entrance nodes are recorded Given the places | osm | class | type | geometry | extratags | | W1 | building | yes | (1,2,3,4,1) | | - | N1 | entrance | main | 1 | 'wheelchair': 'yes' | - | N2 | entrance | yes | 3 | | + And the entrances + | osm | type | geometry | extratags | + | N1 | main | 1 | 'wheelchair': 'yes' | + | N2 | yes | 3 | | And the ways | id | nodes | | 1 | 1,2,3,4,1 | diff --git a/test/bdd/features/db/update/entrances.feature b/test/bdd/features/db/update/entrances.feature index adadee9a..bef0daf5 100644 --- a/test/bdd/features/db/update/entrances.feature +++ b/test/bdd/features/db/update/entrances.feature @@ -17,10 +17,12 @@ Feature: Entrance nodes are recorded | W1 | 1 | Then placex_entrance contains exactly | place_id | osm_id | type | location!wkt | extratags | - When updating places - | osm | class | type | geometry | - | N1 | entrance | main | 1 | - | W1 | building | yes | (1,2,3,4,1) | + When updating entrances + | osm | type | geometry | + | N1 | main | 1 | + And updating places + | osm | class | type | geometry | + | W1 | building | yes | (1,2,3,4,1) | Then placex contains exactly | object | place_id | | W1 | 1 | @@ -46,13 +48,15 @@ Feature: Entrance nodes are recorded | W1 | 2 | Then placex_entrance contains exactly | place_id | osm_id | type | location!wkt | extratags | - When updating places + When marking for delete N1 + And updating entrances + | osm | type | geometry | + | N1 | main | 1 | + And updating places | osm | class | type | geometry | - | N1 | entrance | main | 1 | | W1 | building | yes | (1,2,3,4,1) | Then placex contains exactly | object | place_id | - | N1 | 1 | | W1 | 2 | And placex_entrance contains exactly | place_id | osm_id | type | location!wkt | extratags | @@ -64,8 +68,10 @@ Feature: Entrance nodes are recorded | 4 | 3 | Given the places | osm | class | type | geometry | - | N1 | entrance | main | 1 | | W1 | building | yes | (1,2,3,4,1) | + And the entrances + | osm | type | geometry | + | N1 | main | 1 | And the ways | id | nodes | | 1 | 1, 2, 3, 4, 1 | @@ -79,7 +85,7 @@ Feature: Entrance nodes are recorded When marking for delete N1 And updating places | osm | class | type | geometry | - | W1 | building | yes | (2,3,4,2) | + | W1 | building | yes | (1,2,3,4,1) | Then placex contains exactly | object | place_id | | W1 | 1 | @@ -92,9 +98,11 @@ Feature: Entrance nodes are recorded | 4 | 3 | Given the places | osm | class | type | geometry | - | N1 | entrance | main | 1 | - | N3 | entrance | yes | 3 | | W1 | building | yes | (1,2,3,4,1) | + Given the entrances + | osm | type | geometry | + | N1 | main | 1 | + | N3 | yes | 3 | And the ways | id | nodes | | 1 | 1, 2, 3, 4, 1 | @@ -109,7 +117,7 @@ Feature: Entrance nodes are recorded When marking for delete N1 And updating places | osm | class | type | geometry | - | W1 | building | yes | (2,3,4,2) | + | W1 | building | yes | (1,2,3,4,1) | Then placex contains exactly | object | place_id | | W1 | 1 | diff --git a/test/bdd/test_db.py b/test/bdd/test_db.py index 01cec9e3..339618f3 100644 --- a/test/bdd/test_db.py +++ b/test/bdd/test_db.py @@ -82,6 +82,21 @@ def import_places(db_conn, named, datatable, node_grid): PlaceColumn(node_grid).add_row(datatable[0], row, named is not None).db_insert(cur) +@given(step_parse('the entrances'), target_fixture=None) +def import_place_entrances(db_conn, datatable, node_grid): + """ Insert todo rows into the place_entrance table. + """ + with db_conn.cursor() as cur: + for row in datatable[1:]: + data = PlaceColumn(node_grid).add_row(datatable[0], row, False) + assert data.columns['osm_type'] == 'N' + + cur.execute("""INSERT INTO place_entrance (osm_id, type, extratags, geometry) + VALUES (%s, %s, %s, {})""".format(data.get_wkt()), + (data.columns['osm_id'], data.columns['type'], + data.columns.get('extratags'))) + + @given('the ways', target_fixture=None) def import_ways(db_conn, datatable): """ Import raw ways into the osm2pgsql way middle table. @@ -151,6 +166,23 @@ def do_update(db_conn, update_config, node_grid, datatable): return _collect_place_ids(db_conn) +@when('updating entrances', target_fixture=None) +def update_place_entrances(db_conn, datatable, node_grid): + """ Insert todo rows into the place_entrance table. + """ + with db_conn.cursor() as cur: + for row in datatable[1:]: + data = PlaceColumn(node_grid).add_row(datatable[0], row, False) + assert data.columns['osm_type'] == 'N' + + cur.execute("DELETE FROM place_entrance WHERE osm_id = %s", + (data.columns['osm_id'],)) + cur.execute("""INSERT INTO place_entrance (osm_id, type, extratags, geometry) + VALUES (%s, %s, %s, {})""".format(data.get_wkt()), + (data.columns['osm_id'], data.columns['type'], + data.columns.get('extratags'))) + + @when('updating postcodes') def do_postcode_update(update_config): """ Recompute the postcode centroids. @@ -168,6 +200,9 @@ def do_delete_place(db_conn, update_config, node_grid, otype, oid): cur.execute('DELETE FROM place WHERE osm_type = %s and osm_id = %s', (otype, oid)) cur.execute('SELECT flush_deleted_places()') + if otype == 'N': + cur.execute('DELETE FROM place_entrance WHERE osm_id = %s', + (oid, )) db_conn.commit() cli.nominatim(['index', '-q'], update_config.environ) diff --git a/test/bdd/utils/place_inserter.py b/test/bdd/utils/place_inserter.py index a330c3ac..a3ddf5c7 100644 --- a/test/bdd/utils/place_inserter.py +++ b/test/bdd/utils/place_inserter.py @@ -118,6 +118,17 @@ class PlaceColumn: else: self.columns[column] = {key: value} + def get_wkt(self): + if self.columns['osm_type'] == 'N' and self.geometry is None: + pt = self.grid.get(str(self.columns['osm_id'])) if self.grid else None + if pt is None: + pt = (random.uniform(-180, 180), random.uniform(-90, 90)) + + return "ST_SetSRID(ST_Point({}, {}), 4326)".format(*pt) + + assert self.geometry is not None, "Geometry missing" + return self.geometry + def db_delete(self, cursor): """ Issue a delete for the given OSM object. """ @@ -127,17 +138,8 @@ class PlaceColumn: def db_insert(self, cursor): """ Insert the collected data into the database. """ - if self.columns['osm_type'] == 'N' and self.geometry is None: - pt = self.grid.get(str(self.columns['osm_id'])) if self.grid else None - if pt is None: - pt = (random.uniform(-180, 180), random.uniform(-90, 90)) - - self.geometry = "ST_SetSRID(ST_Point({}, {}), 4326)".format(*pt) - else: - assert self.geometry is not None, "Geometry missing" - query = 'INSERT INTO place ({}, geometry) values({}, {})'.format( ','.join(self.columns.keys()), ','.join(['%s' for x in range(len(self.columns))]), - self.geometry) + self.get_wkt()) cursor.execute(query, list(self.columns.values())) -- 2.39.5