From 340e7f7210fca8095fc07ebaf3fb0e95cd0db518 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sat, 16 Jan 2021 22:20:23 +0100 Subject: [PATCH] bdd: complete coverage for API tests Also removes some functions that are no longer used and fixes debug output where the tests found an issue. --- lib/SearchDescription.php | 16 ++------------ test/bdd/api/reverse/params.feature | 33 ++++++++++++++++++++++++++++ test/bdd/api/reverse/simple.feature | 4 ++++ test/bdd/api/search/queries.feature | 34 +++++++++++++++++++++++++++++ test/bdd/api/search/simple.feature | 13 +++++++++++ test/bdd/steps/http_responses.py | 2 +- test/bdd/steps/steps_api_queries.py | 9 ++++++-- 7 files changed, 94 insertions(+), 17 deletions(-) diff --git a/lib/SearchDescription.php b/lib/SearchDescription.php index f0106063..2053082f 100644 --- a/lib/SearchDescription.php +++ b/lib/SearchDescription.php @@ -86,18 +86,6 @@ class SearchDescription $this->sType = $sType; } - /** - * Check if this might be a full address search. - * - * @return bool True if the search contains name, address and housenumber. - */ - public function looksLikeFullAddress() - { - return (!empty($this->aName)) - && (!empty($this->aAddress) || $this->sCountryCode) - && preg_match('/[0-9]+/', $this->sHouseNumber); - } - /** * Check if any operator is set. * @@ -1027,7 +1015,7 @@ class SearchDescription 'Name terms (stop words)' => $this->aNameNonSearch, 'Address terms' => $this->aAddress, 'Address terms (stop words)' => $this->aAddressNonSearch, - 'Address terms (full words)' => $this->aFullNameAddress, + 'Address terms (full words)' => $this->aFullNameAddress ?? '', 'Special search' => $this->iOperator, 'Class' => $this->sClass, 'Type' => $this->sType, @@ -1039,7 +1027,7 @@ class SearchDescription public function dumpAsHtmlTableRow(&$aWordIDs) { $kf = function ($k) use (&$aWordIDs) { - return $aWordIDs[$k]; + return $aWordIDs[$k] ?? '['.$k.']'; }; echo ''; diff --git a/test/bdd/api/reverse/params.feature b/test/bdd/api/reverse/params.feature index 374272d0..d6ef3794 100644 --- a/test/bdd/api/reverse/params.feature +++ b/test/bdd/api/reverse/params.feature @@ -25,6 +25,39 @@ Feature: Parameters for Reverse API | -45.3,; | | gkjd,50 | + Scenario Outline: Zoom levels between 4 and 18 are allowed + When sending reverse coordinates 47.14122383,9.52169581334 + | zoom | + | | + Then exactly 1 result is returned + And result addresses contain + | country_code | + | li | + + Examples: + | zoom | + | 4 | + | 5 | + | 6 | + | 7 | + | 8 | + | 9 | + | 10 | + | 11 | + | 12 | + | 13 | + | 14 | + | 15 | + | 16 | + | 17 | + | 18 | + + Scenario: Non-numerical zoom levels return an error + When sending reverse coordinates 47.14122383,9.52169581334 + | zoom | + | adfe | + Then a HTTP 400 is returned + Scenario Outline: Reverse Geocoding with extratags When sending reverse coordinates 47.1395013150811,9.522098077031046 | extratags | diff --git a/test/bdd/api/reverse/simple.feature b/test/bdd/api/reverse/simple.feature index 78bd47a7..4da311e7 100644 --- a/test/bdd/api/reverse/simple.feature +++ b/test/bdd/api/reverse/simple.feature @@ -131,3 +131,7 @@ Feature: Simple Reverse Tests | 48.966 | 8.448.2 | | Nan | 8.448 | | 48.966 | Nan | + + Scenario: Reverse Debug output returns no errors + When sending debug reverse coordinates 47.11,9.57 + Then a HTTP 200 is returned diff --git a/test/bdd/api/search/queries.feature b/test/bdd/api/search/queries.feature index 3a62c581..ea353f45 100644 --- a/test/bdd/api/search/queries.feature +++ b/test/bdd/api/search/queries.feature @@ -80,6 +80,15 @@ Feature: Search queries | class | type | | amenity | restaurant | + Scenario: Search with specific amenity also work in country + When sending json search query "restaurants in liechtenstein" with address + Then result addresses contain + | country | + | Liechtenstein | + And results contain + | class | type | + | amenity | restaurant | + Scenario: Search with key-value amenity When sending json search query "[club=scout] Vaduz" Then results contain @@ -114,6 +123,19 @@ Feature: Search queries | class | type | | leisure | firepit | + Scenario Outline: Key/value search near given coordinate can be restricted to country + When sending json search query "[natural=peak] 47.06512,9.53965" with address + | countrycodes | + | | + Then result addresses contain + | country_code | + | | + + Examples: + | cc | + | li | + | ch | + Scenario: Name search near given coordinate When sending json search query "sporry" with address Then result addresses contain @@ -146,6 +168,14 @@ Feature: Search queries | li | Then exactly 0 results are returned + Scenario: Country searches only return results for the given country + When sending search query "Ans Trail" with address + | countrycodes | + | li | + Then result addresses contain + | country_code | + | li | + # https://trac.openstreetmap.org/ticket/5094 Scenario: housenumbers are ordered by complete match first When sending json search query "Austrasse 11, Vaduz" with address @@ -182,3 +212,7 @@ Feature: Search queries Then result addresses contain | ID | town | | 0 | Vaduz | + + Scenario: Search can handle complex query word sets + When sending search query "aussenstelle universitat lichtenstein wachterhaus aussenstelle universitat lichtenstein wachterhaus aussenstelle universitat lichtenstein wachterhaus aussenstelle universitat lichtenstein wachterhaus" + Then a HTTP 200 is returned diff --git a/test/bdd/api/search/simple.feature b/test/bdd/api/search/simple.feature index fca7faf5..b9323c5a 100644 --- a/test/bdd/api/search/simple.feature +++ b/test/bdd/api/search/simple.feature @@ -195,3 +195,16 @@ Feature: Simple Tests Then result header contains | attr | value | | more_url | .*&countrycodes=pl%2Cbo&.* | + + Scenario Outline: Search debug output does not return errors + When sending debug search query "" + Then a HTTP 200 is returned + + Examples: + | query | + | Liechtenstein | + | Triesen | + | Pfarrkirche | + | Landstr 27 Steinort, Triesenberg, 9495 | + | 9497 | + | restaurant in triesen | diff --git a/test/bdd/steps/http_responses.py b/test/bdd/steps/http_responses.py index 1e7da93d..beafcd9e 100644 --- a/test/bdd/steps/http_responses.py +++ b/test/bdd/steps/http_responses.py @@ -50,7 +50,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): diff --git a/test/bdd/steps/steps_api_queries.py b/test/bdd/steps/steps_api_queries.py index 00941e79..ad4a8515 100644 --- a/test/bdd/steps/steps_api_queries.py +++ b/test/bdd/steps/steps_api_queries.py @@ -79,7 +79,7 @@ def query_cmd(context, query, dups): context.response = SearchResponse(outp, 'json') def send_api_query(endpoint, params, fmt, context): - if fmt is not None: + if fmt is not None and fmt.strip() != 'debug': params['format'] = fmt.strip() if context.table: if context.table.headings[0] == 'param': @@ -148,6 +148,8 @@ def website_search_request(context, fmt, query, addr): params['q'] = query if addr is not None: params['addressdetails'] = '1' + if fmt and fmt.strip() == 'debug': + params['debug'] = '1' outp, status = send_api_query('search', params, fmt, context) @@ -160,6 +162,8 @@ def website_reverse_request(context, fmt, lat, lon): params['lat'] = lat if lon is not None: params['lon'] = lon + if fmt and fmt.strip() == 'debug': + params['debug'] = '1' outp, status = send_api_query('reverse', params, fmt, context) @@ -203,7 +207,8 @@ def validate_result_number(context, operator, number): @then(u'a HTTP (?P\d+) is returned') def check_http_return_status(context, status): - assert context.response.errorcode == int(status) + assert context.response.errorcode == int(status), \ + "Return HTTP status is {}.".format(context.response.errorcode) @then(u'the page contents equals "(?P.+)"') def check_page_content_equals(context, text): -- 2.39.5