]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/bdd/steps/db_ops.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / test / bdd / steps / db_ops.py
index 885c2df914def30968ea36a3b9e1460648ca696c..2b012c41d9be286717b385310780083001cc1602 100644 (file)
@@ -110,6 +110,9 @@ class PlaceObjName(object):
         if self.pid is None:
             return "<null>"
 
         if self.pid is None:
             return "<null>"
 
+        if self.pid == 0:
+            return "place ID 0"
+
         cur = self.conn.cursor()
         cur.execute("""SELECT osm_type, osm_id, class
                        FROM placex WHERE place_id = %s""",
         cur = self.conn.cursor()
         cur.execute("""SELECT osm_type, osm_id, class
                        FROM placex WHERE place_id = %s""",
@@ -197,10 +200,18 @@ def assert_db_column(row, column, value, context):
         return
 
     if column.startswith('centroid'):
         return
 
     if column.startswith('centroid'):
-        fac = float(column[9:]) if column.startswith('centroid*') else 1.0
-        x, y = value.split(' ')
-        assert_almost_equal(float(x) * fac, row['cx'], "Bad x coordinate")
-        assert_almost_equal(float(y) * fac, row['cy'], "Bad y coordinate")
+        if value == 'in geometry':
+            query = """SELECT ST_Within(ST_SetSRID(ST_Point({}, {}), 4326),
+                                        ST_SetSRID('{}'::geometry, 4326))""".format(
+                      row['cx'], row['cy'], row['geomtxt'])
+            cur = context.db.cursor()
+            cur.execute(query)
+            eq_(cur.fetchone()[0], True, "(Row %s failed: %s)" % (column, query))
+        else:
+            fac = float(column[9:]) if column.startswith('centroid*') else 1.0
+            x, y = value.split(' ')
+            assert_almost_equal(float(x) * fac, row['cx'], msg="Bad x coordinate")
+            assert_almost_equal(float(y) * fac, row['cy'], msg="Bad y coordinate")
     elif column == 'geometry':
         geom = context.osm.parse_geometry(value, context.scene)
         cur = context.db.cursor()
     elif column == 'geometry':
         geom = context.osm.parse_geometry(value, context.scene)
         cur = context.db.cursor()
@@ -459,15 +470,25 @@ def check_search_name_contents(context, exclude):
         for res in cur:
             for h in row.headings:
                 if h in ('name_vector', 'nameaddress_vector'):
         for res in cur:
             for h in row.headings:
                 if h in ('name_vector', 'nameaddress_vector'):
-                    terms = [x.strip().replace('#', ' ') for x in row[h].split(',')]
+                    terms = [x.strip() for x in row[h].split(',') if not x.strip().startswith('#')]
+                    words = [x.strip()[1:] for x in row[h].split(',') if x.strip().startswith('#')]
                     subcur = context.db.cursor()
                     subcur = context.db.cursor()
-                    subcur.execute("""SELECT word_id, word_token
-                                      FROM word, (SELECT unnest(%s) as term) t
-                                      WHERE word_token = make_standard_name(t.term)""",
-                                   (terms,))
+                    subcur.execute(""" SELECT word_id, word_token
+                                       FROM word, (SELECT unnest(%s::TEXT[]) as term) t
+                                       WHERE word_token = make_standard_name(t.term)
+                                             and class is null and country_code is null
+                                             and operator is null
+                                      UNION
+                                       SELECT word_id, word_token
+                                       FROM word, (SELECT unnest(%s::TEXT[]) as term) t
+                                       WHERE word_token = ' ' || make_standard_name(t.term)
+                                             and class is null and country_code is null
+                                             and operator is null
+                                   """,
+                                   (terms, words))
                     if not exclude:
                     if not exclude:
-                        ok_(subcur.rowcount >= len(terms),
-                            "No word entry found for " + row[h])
+                        ok_(subcur.rowcount >= len(terms) + len(words),
+                            "No word entry found for " + row[h] + ". Entries found: " + str(subcur.rowcount))
                     for wid in subcur:
                         if exclude:
                             assert_not_in(wid[0], res[h],
                     for wid in subcur:
                         if exclude:
                             assert_not_in(wid[0], res[h],