]> git.openstreetmap.org Git - nominatim.git/commitdiff
bdd: complete coverage for API tests
authorSarah Hoffmann <lonvia@denofr.de>
Sat, 16 Jan 2021 21:20:23 +0000 (22:20 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 17 Jan 2021 15:12:06 +0000 (16:12 +0100)
Also removes some functions that are no longer used and
fixes debug output where the tests found an issue.

lib/SearchDescription.php
test/bdd/api/reverse/params.feature
test/bdd/api/reverse/simple.feature
test/bdd/api/search/queries.feature
test/bdd/api/search/simple.feature
test/bdd/steps/http_responses.py
test/bdd/steps/steps_api_queries.py

index f010606355144c418de9162747c8fbf104671c56..2053082f6bbff4a13bd6a5ba6c08bc89366e0c38 100644 (file)
@@ -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 '<tr>';
index 374272d0594f37526f85ca17a1e9dabff0ba5186..d6ef3794bfd514d6ec3861a5ed0dd0d0a39a7b11 100644 (file)
@@ -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 |
+          | <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 <format> reverse coordinates 47.1395013150811,9.522098077031046
           | extratags |
index 78bd47a7e6db6858aa9686ed41ab7806626589c7..4da311e78a9270b9250ffabe5400b1d68fa2e6df 100644 (file)
@@ -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
index 3a62c5811831b88930a023e6e1b8b0c2ab7fae4e..ea353f4568ad46f83f8d62d7511ef400e7234e67 100644 (file)
@@ -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 |
+          | <cc> |
+        Then result addresses contain
+          | country_code |
+          | <cc> |
+
+    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
index fca7faf5d2c155b2399b66c37e041fe234e6d1be..b9323c5a62d695734cf354176a661bd7b4b2f801 100644 (file)
@@ -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 "<query>"
+        Then a HTTP 200 is returned
+
+    Examples:
+        | query |
+        | Liechtenstein |
+        | Triesen |
+        | Pfarrkirche |
+        | Landstr 27 Steinort, Triesenberg, 9495 |
+        | 9497 |
+        | restaurant in triesen |
index 1e7da93d69bfd7dfc58060ae139065c802543063..beafcd9e1ee16773294f8279d8dd26ce080a3d6e 100644 (file)
@@ -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):
index 00941e79c137bed2ec5f439c9de3a3f830f36b44..ad4a8515af55d39ea62a9570d76d91084f69fa22 100644 (file)
@@ -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<status>\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<text>.+)"')
 def check_page_content_equals(context, text):