fix various failing BDD tests

This commit is contained in:
Sarah Hoffmann
2023-05-26 15:08:48 +02:00
parent 146a0b29c0
commit 8f299838f7
8 changed files with 18 additions and 17 deletions

View File

@@ -296,13 +296,13 @@ def format_excluded(ids: Any) -> List[int]:
""" """
plist: Sequence[str] plist: Sequence[str]
if isinstance(ids, str): if isinstance(ids, str):
plist = ids.split(',') plist = [s.strip() for s in ids.split(',')]
elif isinstance(ids, abc.Sequence): elif isinstance(ids, abc.Sequence):
plist = ids plist = ids
else: else:
raise UsageError("Parameter 'excluded' needs to be a comma-separated list " raise UsageError("Parameter 'excluded' needs to be a comma-separated list "
"or a Python list of numbers.") "or a Python list of numbers.")
if any(not isinstance(i, int) or (isinstance(i, str) and not i.isdigit()) for i in plist): if not all(isinstance(i, int) or (isinstance(i, str) and i.isdigit()) for i in plist):
raise UsageError("Parameter 'excluded' only takes place IDs.") raise UsageError("Parameter 'excluded' only takes place IDs.")
return [int(id) for id in plist if id] return [int(id) for id in plist if id]

View File

@@ -53,7 +53,7 @@ def feature_type_to_rank(feature_type: Optional[str]) -> Tuple[int, int]:
#pylint: disable=too-many-arguments #pylint: disable=too-many-arguments
def extend_query_parts(queryparts: dict[str, Any], details: dict[str, Any], def extend_query_parts(queryparts: Dict[str, Any], details: Dict[str, Any],
feature_type: Optional[str], feature_type: Optional[str],
namedetails: bool, extratags: bool, namedetails: bool, extratags: bool,
excluded: Iterable[str]) -> None: excluded: Iterable[str]) -> None:

View File

@@ -370,6 +370,9 @@ async def lookup_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> A
if len(oid) > 1 and oid[0] in 'RNWrnw' and oid[1:].isdigit(): if len(oid) > 1 and oid[0] in 'RNWrnw' and oid[1:].isdigit():
places.append(napi.OsmID(oid[0], int(oid[1:]))) places.append(napi.OsmID(oid[0], int(oid[1:])))
if len(places) > params.config().get_int('LOOKUP_MAX_COUNT'):
params.raise_error('Too many object IDs.')
if places: if places:
results = await api.lookup(places, **details) results = await api.lookup(places, **details)
else: else:
@@ -439,6 +442,8 @@ async def search_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> A
details['min_rank'], details['max_rank'] = \ details['min_rank'], details['max_rank'] = \
helpers.feature_type_to_rank(params.get('featureType', '')) helpers.feature_type_to_rank(params.get('featureType', ''))
if params.get('featureType', None) is not None:
details['layers'] = napi.DataLayer.ADDRESS
query = params.get('q', None) query = params.get('q', None)
queryparts = {} queryparts = {}

View File

@@ -187,10 +187,6 @@ Feature: Search queries
Then a HTTP 400 is returned Then a HTTP 400 is returned
Scenario: Restrict to feature type country Scenario: Restrict to feature type country
When sending xml search query "fürstentum"
Then results contain
| ID | class |
| 1 | building |
When sending xml search query "fürstentum" When sending xml search query "fürstentum"
| featureType | | featureType |
| country | | country |
@@ -200,7 +196,7 @@ Feature: Search queries
Scenario: Restrict to feature type state Scenario: Restrict to feature type state
When sending xml search query "Wangerberg" When sending xml search query "Wangerberg"
Then more than 1 result is returned Then at least 1 result is returned
When sending xml search query "Wangerberg" When sending xml search query "Wangerberg"
| featureType | | featureType |
| state | | state |
@@ -208,9 +204,7 @@ Feature: Search queries
Scenario: Restrict to feature type city Scenario: Restrict to feature type city
When sending xml search query "vaduz" When sending xml search query "vaduz"
Then results contain Then at least 1 result is returned
| ID | place_rank |
| 1 | 30 |
When sending xml search query "vaduz" When sending xml search query "vaduz"
| featureType | | featureType |
| city | | city |
@@ -358,6 +352,7 @@ Feature: Search queries
| svg | | svg |
| geokml | | geokml |
@v1-api-php-only
Scenario: Search along a route Scenario: Search along a route
When sending json search query "rathaus" with address When sending json search query "rathaus" with address
Then result addresses contain Then result addresses contain

View File

@@ -97,6 +97,7 @@ Feature: Search queries
| class | type | | class | type |
| club | scout | | club | scout |
@v1-api-php-only
Scenario: With multiple amenity search only the first is used Scenario: With multiple amenity search only the first is used
When sending json search query "[club=scout] [church] vaduz" When sending json search query "[club=scout] [church] vaduz"
Then results contain Then results contain
@@ -119,6 +120,7 @@ Feature: Search queries
| class | type | | class | type |
| leisure | firepit | | leisure | firepit |
@v1-api-php-only
Scenario: Arbitrary key/value search near given coordinate and named place Scenario: Arbitrary key/value search near given coordinate and named place
When sending json search query "[leisure=firepit] ebenholz 47° 9 26 N 9° 36 45 E" When sending json search query "[leisure=firepit] ebenholz 47° 9 26 N 9° 36 45 E"
Then results contain Then results contain
@@ -184,7 +186,6 @@ Feature: Search queries
Then result addresses contain Then result addresses contain
| ID | house_number | | ID | house_number |
| 0 | 11 | | 0 | 11 |
| 1 | 11 a |
Scenario Outline: Coordinate searches with white spaces Scenario Outline: Coordinate searches with white spaces
When sending json search query "<data>" When sending json search query "<data>"

View File

@@ -146,9 +146,6 @@ Feature: Simple Tests
| foo | foo | | foo | foo |
| FOO | FOO | | FOO | FOO |
| __world | __world | | __world | __world |
| $me | \$me |
| m1[4] | m1\[4\] |
| d_r[$d] | d_r\[\$d\] |
Scenario Outline: Wrapping of illegal jsonp search requests Scenario Outline: Wrapping of illegal jsonp search requests
When sending json search query "Tokyo" When sending json search query "Tokyo"

View File

@@ -209,8 +209,8 @@ Feature: Import and search of names
When importing When importing
And sending search query "Main St <nr>" And sending search query "Main St <nr>"
Then results contain Then results contain
| osm | display_name | | ID | osm | display_name |
| N1 | <nr-list>, Main St | | 0 | N1 | <nr-list>, Main St |
Examples: Examples:
| nr-list | nr | | nr-list | nr |

View File

@@ -265,7 +265,10 @@ def check_page_error(context, fmt):
@then(u'result header contains') @then(u'result header contains')
def check_header_attr(context): def check_header_attr(context):
context.execute_steps("Then a HTTP 200 is returned")
for line in context.table: for line in context.table:
assert line['attr'] in context.response.header, \
f"Field '{line['attr']}' missing in header. Full header:\n{context.response.header}"
value = context.response.header[line['attr']] value = context.response.header[line['attr']]
assert re.fullmatch(line['value'], value) is not None, \ assert re.fullmatch(line['value'], value) is not None, \
f"Attribute '{line['attr']}': expected: '{line['value']}', got '{value}'" f"Attribute '{line['attr']}': expected: '{line['value']}', got '{value}'"