From: Sarah Hoffmann Date: Thu, 30 Mar 2017 19:57:34 +0000 (+0200) Subject: adapt more BDD tests to hstore X-Git-Tag: v3.0.0~42^2~4 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/41afcaddd54e387eb5020fda5e07d08c46da91d4 adapt more BDD tests to hstore --- diff --git a/sql/functions.sql b/sql/functions.sql index 3f64d289..0ef20a9a 100644 --- a/sql/functions.sql +++ b/sql/functions.sql @@ -1001,24 +1001,24 @@ BEGIN RETURN NEW; END IF; - NEW.interpolationtype = NEW.address->'interpolation'; + -- if the line was newly inserted, split the line as necessary + IF OLD.indexed_status = 1 THEN + NEW.interpolationtype = NEW.address->'interpolation'; - IF NEW.address is not NULL THEN - IF NEW.address ? 'street' THEN - NEW.street = NEW.address->'street'; - END IF; + IF NEW.address is not NULL THEN + IF NEW.address ? 'street' THEN + NEW.street = NEW.address->'street'; + END IF; - IF NEW.address ? 'place' THEN - NEW.addr_place = NEW.address->'place'; - END IF; + IF NEW.address ? 'place' THEN + NEW.addr_place = NEW.address->'place'; + END IF; - IF NEW.address ? 'postcode' THEN - NEW.addr_place = NEW.address->'postcode'; + IF NEW.address ? 'postcode' THEN + NEW.addr_place = NEW.address->'postcode'; + END IF; END IF; - END IF; - -- if the line was newly inserted, split the line as necessary - IF OLD.indexed_status = 1 THEN select nodes from planet_osm_ways where id = NEW.osm_id INTO waynodes; IF array_upper(waynodes, 1) IS NULL THEN @@ -1222,7 +1222,7 @@ BEGIN END IF; IF NEW.address ? 'postcode' THEN - NEW.addr_place = NEW.address->'postcode'; + NEW.postcode = NEW.address->'postcode'; END IF; END IF; @@ -2146,13 +2146,13 @@ BEGIN IF NEW.class in ('place','boundary') AND NEW.type in ('postcode','postal_code') THEN - IF NEW.postcode IS NULL THEN + IF NEW.address is NULL OR NOT NEW.address ? 'postcode' THEN -- postcode was deleted, no longer retain in placex DELETE FROM placex where place_id = existingplacex.place_id; RETURN NULL; END IF; - NEW.name := hstore('ref', NEW.postcode); + NEW.name := hstore('ref', NEW.address->'postcode'); END IF; update placex set diff --git a/test/bdd/db/update/interpolation.feature b/test/bdd/db/update/interpolation.feature index 0eaa97fd..f7f7dddb 100644 --- a/test/bdd/db/update/interpolation.feature +++ b/test/bdd/db/update/interpolation.feature @@ -17,7 +17,9 @@ Feature: Update of address interpolations | osm | class | type | housenr | geometry | | N1 | place | house | 2 | :n-middle-w | | N2 | place | house | 6 | :n-middle-e | - | W10 | place | houses | even | :w-middle | + And updating places + | osm | class | type | addr+interpolation | geometry | + | W10 | place | houses | even | :w-middle | Then placex contains | object | parent_place_id | | N1 | W2 | @@ -32,6 +34,8 @@ Feature: Update of address interpolations | osm | class | type | housenr | geometry | | N1 | place | house | 2 | :n-middle-w | | N2 | place | house | 6 | :n-middle-e | + And the places + | osm | class | type | addr+interpolation | geometry | | W10 | place | houses | even | :w-middle | And the places | osm | class | type | name | geometry | @@ -49,7 +53,7 @@ Feature: Update of address interpolations | parent_place_id | start | end | | W2 | 2 | 6 | When updating places - | osm | class | type | housenr | street | geometry | + | osm | class | type | addr+interpolation | street | geometry | | W10 | place | houses | even | Cloud Street | :w-middle | Then placex contains | object | parent_place_id | @@ -65,6 +69,8 @@ Feature: Update of address interpolations | osm | class | type | housenr | geometry | | N1 | place | house | 2 | :n-middle-w | | N2 | place | house | 6 | :n-middle-e | + And the places + | osm | class | type | addr+interpolation | geometry | | W10 | place | houses | even | :w-middle | And the places | osm | class | type | name | geometry | @@ -99,6 +105,8 @@ Feature: Update of address interpolations | osm | class | type | housenr | geometry | | N1 | place | house | 2 | :n-middle-w | | N2 | place | house | 6 | :n-middle-e | + And the places + | osm | class | type | addr+interpolation | geometry | | W10 | place | houses | even | :w-middle | And the places | osm | class | type | name | geometry | @@ -129,7 +137,7 @@ Feature: Update of address interpolations | N1 | place | house | 2 | :n-middle-w | | N2 | place | house | 6 | :n-middle-e | And the places - | osm | class | type | housenr | street | geometry | + | osm | class | type | addr+interpolation | street | geometry | | W10 | place | houses | even | Cloud Street| :w-middle | And the places | osm | class | type | name | geometry | @@ -163,7 +171,7 @@ Feature: Update of address interpolations | N1 | place | house | 2 | :n-middle-w | | N2 | place | house | 6 | :n-middle-e | And the places - | osm | class | type | housenr | street | geometry | + | osm | class | type | addr+interpolation | street | geometry | | W10 | place | houses | even | Cloud Street| :w-middle | And the places | osm | class | type | name | geometry | @@ -209,7 +217,7 @@ Feature: Update of address interpolations | N1 | place | house | 2 | :n-north-w | | N2 | place | house | 6 | :n-north-e | And updating places - | osm | class | type | housenr | street | geometry | + | osm | class | type | addr+interpolation | street | geometry | | W1 | place | houses | even | Cloud Street| :w-north | Then placex has no entry for W1 And W1 expands to interpolation @@ -229,7 +237,7 @@ Feature: Update of address interpolations | id | nodes | | 1 | 1,100,101,102,2 | And the places - | osm | class | type | housenr | street | geometry | + | osm | class | type | addr+interpolation | street | geometry | | W1 | place | houses | even | Cloud Street| :w-north | When importing Then placex has no entry for W1 @@ -252,7 +260,7 @@ Feature: Update of address interpolations | id | nodes | | 1 | 1,100,101,102,2 | And the places - | osm | class | type | housenr | geometry | + | osm | class | type | addr+interpolation | geometry | | W1 | place | houses | even | :w-north | When importing Then W1 expands to no interpolation @@ -261,7 +269,7 @@ Feature: Update of address interpolations | N1 | place | house | 2 | :n-north-w | | N2 | place | house | 6 | :n-north-e | And updating places - | osm | class | type | housenr | street | geometry | + | osm | class | type | addr+interpolation | street | geometry | | W1 | place | houses | even | Cloud Street| :w-north | Then W1 expands to interpolation | parent_place_id | start | end | @@ -279,7 +287,7 @@ Feature: Update of address interpolations | id | nodes | | 2 | 3,4,5 | And the places - | osm | class | type | housenr | geometry | + | osm | class | type | addr+interpolation | geometry | | W2 | place | houses | even | 3,4,5 | And the places | osm | class | type | housenr | @@ -309,7 +317,7 @@ Feature: Update of address interpolations | id | nodes | | 2 | 3,4,5 | And the places - | osm | class | type | housenr | geometry | + | osm | class | type | addr+interpolation | geometry | | W2 | place | houses | even | 3,4,5 | And the places | osm | class | type | housenr | @@ -338,7 +346,7 @@ Feature: Update of address interpolations | id | nodes | | 2 | 3,4 | And the places - | osm | class | type | housenr | geometry | + | osm | class | type | addr+interpolation | geometry | | W2 | place | houses | even | 3,4 | And the places | osm | class | type | housenr | diff --git a/test/bdd/steps/db_ops.py b/test/bdd/steps/db_ops.py index 07b377fa..30c216a5 100644 --- a/test/bdd/steps/db_ops.py +++ b/test/bdd/steps/db_ops.py @@ -40,19 +40,24 @@ class PlaceColumn: self.columns['admin_level'] = int(value) def set_key_housenr(self, value): - self.add_hstore('address', 'housenumber', None if value == '' else value) + if value: + self.add_hstore('address', 'housenumber', value) def set_key_postcode(self, value): - self.add_hstore('address', 'postcode', None if value == '' else value) + if value: + self.add_hstore('address', 'postcode', value) def set_key_street(self, value): - self.add_hstore('address', 'street', None if value == '' else value) + if value: + self.add_hstore('address', 'street', value) def set_key_addr_place(self, value): - self.add_hstore('address', 'place', None if value == '' else value) + if value: + self.add_hstore('address', 'place', value) def set_key_country(self, value): - self.add_hstore('address', 'country', None if value == '' else value) + if value: + self.add_hstore('address', 'country', value) def set_key_geometry(self, value): self.geometry = self.context.osm.parse_geometry(value, self.context.scene) @@ -103,9 +108,10 @@ class PlaceObjName(object): if self.pid is None: return "" - self.conn.cursor().execute("""SELECT osm_type, osm_id, class - FROM placex WHERE place_id = %s""", - self.pid) + cur = self.conn.cursor() + cur.execute("""SELECT osm_type, osm_id, class + FROM placex WHERE place_id = %s""", + (self.pid, )) eq_(1, cur.rowcount, "No entry found for place id %s" % self.pid) return "%s%s:%s" % cur.fetchone() @@ -432,7 +438,8 @@ def check_search_name_contents(context): FROM word, (SELECT unnest(%s) as term) t WHERE word_token = make_standard_name(t.term)""", (terms,)) - ok_(subcur.rowcount >= len(terms)) + ok_(subcur.rowcount >= len(terms), + "No word entry found for " + row[h]) for wid in subcur: assert_in(wid[0], res[h], "Missing term for %s/%s: %s" % (pid, h, wid[1]))