From: Sarah Hoffmann Date: Mon, 14 Nov 2022 15:57:31 +0000 (+0100) Subject: bdd: add osm2pgsql tests for updating interpolations X-Git-Tag: v4.2.0~13^2~1 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/d8e3ba3b54f07fcc89e5b257bf3183f21bde8a7a?ds=sidebyside;hp=a46348da3833cd6a6fe07a982a83a5bdac13f10f bdd: add osm2pgsql tests for updating interpolations --- diff --git a/test/bdd/osm2pgsql/update/interpolations.feature b/test/bdd/osm2pgsql/update/interpolations.feature new file mode 100644 index 00000000..dae5168b --- /dev/null +++ b/test/bdd/osm2pgsql/update/interpolations.feature @@ -0,0 +1,133 @@ +@DB +Feature: Updates of address interpolation objects + Test that changes to address interpolation objects are correctly + propagated. + + Background: + Given the grid + | 1 | 2 | + + + Scenario: Adding a new interpolation + When loading osm data + """ + n1 Taddr:housenumber=3 + n2 Taddr:housenumber=17 + """ + Then place contains + | object | type | + | N1:place | house | + | N2:place | house | + + When updating osm data + """ + w99 Taddr:interpolation=odd Nn1,n2 + """ + Then place contains + | object | type | + | N1:place | house | + | N2:place | house | + | W99:place | houses | + When indexing + Then placex contains exactly + | object | type | + | N1:place | house | + | N2:place | house | + Then location_property_osmline contains exactly + | object | + | 99:5 | + + + Scenario: Delete an existing interpolation + When loading osm data + """ + n1 Taddr:housenumber=2 + n2 Taddr:housenumber=7 + w99 Taddr:interpolation=odd Nn1,n2 + """ + Then place contains + | object | type | + | N1:place | house | + | N2:place | house | + | W99:place | houses | + + When updating osm data + """ + w99 v2 dD + """ + Then place contains + | object | type | + | N1:place | house | + | N2:place | house | + When indexing + Then placex contains exactly + | object | type | + | N1:place | house | + | N2:place | house | + Then location_property_osmline contains exactly + | object | indexed_status | + + + Scenario: Changing an object to an interpolation + When loading osm data + """ + n1 Taddr:housenumber=3 + n2 Taddr:housenumber=17 + w99 Thighway=residential Nn1,n2 + """ + Then place contains + | object | type | + | N1:place | house | + | N2:place | house | + | W99:highway | residential | + + When updating osm data + """ + w99 Taddr:interpolation=odd Nn1,n2 + """ + Then place contains + | object | type | + | N1:place | house | + | N2:place | house | + | W99:place | houses | + When indexing + Then placex contains exactly + | object | type | + | N1:place | house | + | N2:place | house | + And location_property_osmline contains exactly + | object | + | 99:5 | + + + Scenario: Changing an interpolation to something else + When loading osm data + """ + n1 Taddr:housenumber=3 + n2 Taddr:housenumber=17 + w99 Taddr:interpolation=odd Nn1,n2 + """ + Then place contains + | object | type | + | N1:place | house | + | N2:place | house | + | W99:place | houses | + + When updating osm data + """ + w99 Thighway=residential Nn1,n2 + """ + Then place contains + | object | type | + | N1:place | house | + | N2:place | house | + | W99:highway | residential | + When indexing + Then placex contains exactly + | object | type | + | N1:place | house | + | N2:place | house | + | W99:highway | residential | + And location_property_osmline contains exactly + | object | + diff --git a/test/bdd/steps/steps_db_ops.py b/test/bdd/steps/steps_db_ops.py index 84379cbe..14ae5d52 100644 --- a/test/bdd/steps/steps_db_ops.py +++ b/test/bdd/steps/steps_db_ops.py @@ -380,4 +380,49 @@ def check_location_property_osmline(context, oid, neg): assert not todo, f"Unmatched lines in table: {list(context.table[i] for i in todo)}" +@then("location_property_osmline contains(?P exactly)?") +def check_place_contents(context, exact): + """ Check contents of the interpolation table. Each row represents a table row + and all data must match. Data not present in the expected table, may + be arbitry. The rows are identified via the 'object' column which must + have an identifier of the form '[:]'. When multiple + rows match (for example because 'startnumber' was left out and there are + multiple entries for the given OSM object) then all must match. All + expected rows are expected to be present with at least one database row. + When 'exactly' is given, there must not be additional rows in the database. + """ + with context.db.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur: + expected_content = set() + for row in context.table: + if ':' in row['object']: + nid, start = row['object'].split(':', 2) + start = int(start) + else: + nid, start = row['object'], None + + query = """SELECT *, ST_AsText(linegeo) as geomtxt, + ST_GeometryType(linegeo) as geometrytype + FROM location_property_osmline WHERE osm_id=%s""" + + if ':' in row['object']: + query += ' and startnumber = %s' + params = [int(val) for val in row['object'].split(':', 2)] + else: + params = (int(row['object']), ) + + cur.execute(query, params) + assert cur.rowcount > 0, "No rows found for " + row['object'] + + for res in cur: + if exact: + expected_content.add((res['osm_id'], res['startnumber'])) + + DBRow(nid, res, context).assert_row(row, ['object']) + + if exact: + cur.execute('SELECT osm_id, startnumber from location_property_osmline') + actual = set([(r[0], r[1]) for r in cur]) + assert expected_content == actual, \ + f"Missing entries: {expected_content - actual}\n" \ + f"Not expected in table: {actual - expected_content}"