]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/bdd/steps/http_responses.py
Merge pull request #2336 from lonvia/do-not-mask-error-when-loading-tokenizer
[nominatim.git] / test / bdd / steps / http_responses.py
index 161e29fd7688e8ca2d7d92ad3654e759d569e8d1..247a397bd47b1ed7c7d5e886e4c95e1811759973 100644 (file)
@@ -8,6 +8,8 @@ import xml.etree.ElementTree as ET
 
 from check_functions import Almost
 
+OSM_TYPE = {'N' : 'node', 'W' : 'way', 'R' : 'relation'}
+
 def _geojson_result_to_json_result(geojson_result):
     result = geojson_result['properties']
     result['geojson'] = geojson_result['geometry']
@@ -50,7 +52,7 @@ class GenericResponse:
         self.result = []
         self.header = dict()
 
-        if errorcode == 200:
+        if errorcode == 200 and fmt != 'debug':
             getattr(self, '_parse_' + fmt)()
 
     def _parse_json(self):
@@ -95,6 +97,29 @@ class GenericResponse:
             assert str(self.result[idx][field]) == str(value), \
                    BadRowValueAssert(self, idx, field, value)
 
+    def assert_address_field(self, idx, field, value):
+        """ Check that result rows`idx` has a field `field` with value `value`
+            in its address. If idx is None, then all results are checked.
+        """
+        if idx is None:
+            todo = range(len(self.result))
+        else:
+            todo = [int(idx)]
+
+        for idx in todo:
+            assert 'address' in self.result[idx], \
+                   "Result row {} has no field 'address'.\nFull row: {}"\
+                       .format(idx, json.dumps(self.result[idx], indent=4))
+
+            address = self.result[idx]['address']
+            assert field in address, \
+                   "Result row {} has no field '{}' in address.\nFull address: {}"\
+                       .format(idx, field, json.dumps(address, indent=4))
+
+            assert address[field] == value, \
+                   "\nBad value for row {} field '{}' in address. Expected: {}, got: {}.\nFull address: {}"""\
+                       .format(idx, field, value, address[field], json.dumps(address, indent=4))
+
     def match_row(self, row):
         """ Match the result fields against the given behave table row.
         """
@@ -108,7 +133,11 @@ class GenericResponse:
                 if name == 'ID':
                     pass
                 elif name == 'osm':
-                    self.assert_field(i, 'osm_type', value[0])
+                    assert 'osm_type' in self.result[i], \
+                           "Result row {} has no field 'osm_type'.\nFull row: {}"\
+                               .format(i, json.dumps(self.result[i], indent=4))
+                    assert self.result[i]['osm_type'] in (OSM_TYPE[value[0]], value[0]), \
+                           BadRowValueAssert(self, i, 'osm_type', value)
                     self.assert_field(i, 'osm_id', value[1:])
                 elif name == 'centroid':
                     lon, lat = value.split(' ')