LazyFmt("Bad place id in column %s. Expected: %s, got: %s.",
column, expected, PlaceObjName(result, context.db)))
+def check_database_integrity(context):
+ """ Check some generic constraints on the tables.
+ """
+ # place_addressline should not have duplicate (place_id, address_place_id)
+ cur = context.db.cursor()
+ cur.execute("""SELECT count(*) FROM
+ (SELECT place_id, address_place_id, count(*) as c
+ FROM place_addressline GROUP BY place_id, address_place_id) x
+ WHERE c > 1""")
+ eq_(0, cur.fetchone()[0], "Duplicates found in place_addressline")
+
+
class NominatimID:
""" Splits a unique identifier for places into its components.
As place_ids cannot be used for testing, we use a unique
and ST_GeometryType(geometry) = 'ST_LineString'""")
context.db.commit()
context.nominatim.run_setup_script('calculate-postcodes', 'index', 'index-noanalyse')
+ check_database_integrity(context)
@when("updating places")
def update_place_table(context):
if cur.rowcount == 0:
break
+ check_database_integrity(context)
+
@when("marking for delete (?P<oids>.*)")
def delete_places(context, oids):
context.nominatim.run_setup_script(
context.db.commit()
+@then("place_addressline doesn't contain")
+def check_place_addressline_exclude(context):
+ cur = context.db.cursor(cursor_factory=psycopg2.extras.DictCursor)
+
+ for row in context.table:
+ pid = NominatimID(row['object']).get_place_id(cur)
+ apid = NominatimID(row['address']).get_place_id(cur)
+ cur.execute(""" SELECT * FROM place_addressline
+ WHERE place_id = %s AND address_place_id = %s""",
+ (pid, apid))
+ eq_(0, cur.rowcount,
+ "Row found for place %s and address %s" % (row['object'], row['address']))
+
+ context.db.commit()
+
@then("(?P<oid>\w+) expands to(?P<neg> no)? interpolation")
def check_location_property_osmline(context, oid, neg):
cur = context.db.cursor(cursor_factory=psycopg2.extras.DictCursor)