X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/c56c09e2c03a4e48116aef06fad005a4f21b98d7..c20f8b13a57f25ce9dff25cf17666f5ddb790812:/test/bdd/steps/queries.py diff --git a/test/bdd/steps/queries.py b/test/bdd/steps/queries.py index d9187928..acb7ee91 100644 --- a/test/bdd/steps/queries.py +++ b/test/bdd/steps/queries.py @@ -4,14 +4,47 @@ or via the HTTP interface. """ +import json import os import subprocess +from collections import OrderedDict +from nose.tools import * # for assert functions class SearchResponse(object): - def __init__(response, + def __init__(self, page, fmt='json', errorcode=200): + self.page = page + self.format = fmt + self.errorcode = errorcode + getattr(self, 'parse_' + fmt)() -@when(u'searching for "(?P.*)"( with params)?$') + def parse_json(self): + self.result = json.JSONDecoder(object_pairs_hook=OrderedDict).decode(self.page) + + def match_row(self, row): + if 'ID' in row.headings: + todo = [int(row['ID'])] + else: + todo = range(len(self.result)) + + for i in todo: + res = self.result[i] + for h in row.headings: + if h == 'ID': + pass + elif h == 'osm': + assert_equal(res['osm_type'], row[h][0]) + assert_equal(res['osm_id'], row[h][1:]) + elif h == 'centroid': + x, y = row[h].split(' ') + assert_almost_equal(float(y), float(res['lat'])) + assert_almost_equal(float(x), float(res['lon'])) + else: + assert_in(h, res) + assert_equal(str(res[h]), str(row[h])) + + +@when(u'searching for "(?P.*)"') def query_cmd(context, query): """ Query directly via PHP script. """ @@ -28,11 +61,6 @@ def query_cmd(context, query): stdout=subprocess.PIPE, stderr=subprocess.PIPE) (outp, err) = proc.communicate() - assert_equals (0, proc.returncode), "query.php failed with message: %s" % err - - context. - world.page = outp - world.response_format = 'json' - world.request_type = 'search' - world.returncode = 200 + assert_equals (0, proc.returncode, "query.php failed with message: %s" % err) + context.response = SearchResponse(outp.decode('utf-8'), 'json')