From: Sarah Hoffmann Date: Tue, 5 Jan 2021 09:17:59 +0000 (+0100) Subject: bdd: move output format computation into response X-Git-Tag: v3.7.0~59^2~9 X-Git-Url: https://git.openstreetmap.org/nominatim.git/commitdiff_plain/12ae8a4ed38ecf61d375e12ea699bf265737ba2b?hp=8a93f8ed94d04fed67824366b1691aa62b2c8a1d bdd: move output format computation into response --- diff --git a/test/bdd/steps/http_responses.py b/test/bdd/steps/http_responses.py index c3cd4f52..161e29fd 100644 --- a/test/bdd/steps/http_responses.py +++ b/test/bdd/steps/http_responses.py @@ -40,6 +40,10 @@ class GenericResponse: """ Common base class for all API responses. """ def __init__(self, page, fmt, errorcode=200): + fmt = fmt.strip() + if fmt == 'jsonv2': + fmt = 'json' + self.page = page self.format = fmt self.errorcode = errorcode diff --git a/test/bdd/steps/steps_api_queries.py b/test/bdd/steps/steps_api_queries.py index ebda5ec6..47dc8ac3 100644 --- a/test/bdd/steps/steps_api_queries.py +++ b/test/bdd/steps/steps_api_queries.py @@ -148,12 +148,7 @@ def website_search_request(context, fmt, query, addr): outp, status = send_api_query('search', params, fmt, context) - if fmt is None or fmt == 'jsonv2 ': - outfmt = 'json' - else: - outfmt = fmt.strip() - - context.response = SearchResponse(outp, outfmt, status) + context.response = SearchResponse(outp, fmt or 'json', status) @when(u'sending (?P\S+ )?reverse coordinates (?P.+)?,(?P.+)?') def website_reverse_request(context, fmt, lat, lon): @@ -165,14 +160,7 @@ def website_reverse_request(context, fmt, lat, lon): outp, status = send_api_query('reverse', params, fmt, context) - if fmt is None: - outfmt = 'xml' - elif fmt == 'jsonv2 ': - outfmt = 'json' - else: - outfmt = fmt.strip() - - context.response = ReverseResponse(outp, outfmt, status) + context.response = ReverseResponse(outp, fmt or 'xml', status) @when(u'sending (?P\S+ )?details query for (?P.*)') def website_details_request(context, fmt, query): @@ -184,42 +172,21 @@ def website_details_request(context, fmt, query): params['place_id'] = query outp, status = send_api_query('details', params, fmt, context) - if fmt is None: - outfmt = 'json' - else: - outfmt = fmt.strip() - - context.response = GenericResponse(outp, outfmt, status) + context.response = GenericResponse(outp, fmt or 'json', status) @when(u'sending (?P\S+ )?lookup query for (?P.*)') def website_lookup_request(context, fmt, query): params = { 'osm_ids' : query } outp, status = send_api_query('lookup', params, fmt, context) - if fmt == 'json ': - outfmt = 'json' - elif fmt == 'jsonv2 ': - outfmt = 'json' - elif fmt == 'geojson ': - outfmt = 'geojson' - elif fmt == 'geocodejson ': - outfmt = 'geocodejson' - else: - outfmt = 'xml' - - context.response = SearchResponse(outp, outfmt, status) + context.response = SearchResponse(outp, fmt or 'xml', status) @when(u'sending (?P\S+ )?status query') def website_status_request(context, fmt): params = {} outp, status = send_api_query('status', params, fmt, context) - if fmt is None: - outfmt = 'text' - else: - outfmt = fmt.strip() - - context.response = StatusResponse(outp, outfmt, status) + context.response = StatusResponse(outp, fmt or 'text', status) @step(u'(?Pless than|more than|exactly|at least|at most) (?P\d+) results? (?:is|are) returned') def validate_result_number(context, operator, number):