Select all entrances for results in one query

This commit is contained in:
Emily Love Watson
2025-08-21 11:35:23 -05:00
parent e916d27b7c
commit d0ad65f696
9 changed files with 72 additions and 92 deletions

View File

@@ -247,6 +247,23 @@ def check_result_for_field_absence(nominatim_result, attributes):
assert all(a not in nominatim_result.result for a in attributes)
@then(step_parse(
r'the result contains array field (?P<field>\S+) where element (?P<num>\d+) contains'),
converters={'num': int})
def check_result_array_field_for_attributes(nominatim_result, datatable, field, num):
assert nominatim_result.is_simple()
if datatable[0] == ['param', 'value']:
pairs = datatable[1:]
else:
pairs = zip(datatable[0], datatable[1])
prefix = f"{field}+{num}+"
for k, v in pairs:
assert ResultAttr(nominatim_result.result, prefix + k) == v
@then(step_parse('the result set contains(?P<exact> exactly)?'))
def check_result_list_match(nominatim_result, datatable, exact):
assert not nominatim_result.is_simple()

View File

@@ -36,7 +36,9 @@ Feature: Object details
| W | 429210603 | 1 |
Then a HTTP 200 is returned
And the result is valid json
And the result has attributes entrances
And the result contains array field entrances where element 0 contains
| osm_id | type | lat | lon |
| 6580031131 | yes | 47.2489382 | 9.5284033 |
Scenario: Details with linkedplaces
When sending v1/details

View File

@@ -9,8 +9,8 @@ Feature: Entrance nodes are recorded
| osm | class | type | geometry |
| W1 | building | yes | (1,2,3,4,1) |
And the ways
| id | nodes |
| 1 | 10,20,30,40 |
| id | nodes |
| 1 | 1, 2, 3, 4, 1 |
When importing
Then placex contains exactly
| object | place_id |
@@ -18,63 +18,68 @@ Feature: Entrance nodes are recorded
Then place_entrance contains exactly
| place_id | entrances |
When updating places
| osm | class | type | geometry |
| N10 | entrance | main | 1 |
| osm | class | type | geometry |
| N1 | entrance | main | 1 |
| W1 | building | yes | (1,2,3,4,1) |
Then placex contains exactly
| object | place_id |
| W1 | 1 |
And place_entrance contains exactly
| place_id | entrances |
| 1 | [{'lat': 0, 'lon': 0, 'type': 'main', 'osm_id': 10, 'extratags': None}] |
| 1 | [{'lat': 0, 'lon': 0, 'type': 'main', 'osm_id': 1, 'extratags': None}] |
Scenario: A building with a updated entrance node
Given the grid
| 1 | 2 |
| 4 | 3 |
Given the places
| osm | class | type | geometry |
| W1 | building | yes | (1,2,3,4,1) |
| N10 | barrier | gate | 1 |
| osm | class | type | geometry |
| N1 | barrier | gate | 1 |
| W1 | building | yes | (1,2,3,4,1) |
And the ways
| id | nodes |
| 1 | 10,20,30,40 |
| id | nodes |
| 1 | 1, 2, 3, 4, 1 |
When importing
Then placex contains exactly
| object | place_id |
| W1 | 1 |
| N10 | 2 |
| N1 | 1 |
| W1 | 2 |
Then place_entrance contains exactly
| place_id | entrances |
When updating places
| osm | class | type | geometry |
| N10 | entrance | main | 1 |
| osm | class | type | geometry |
| N1 | entrance | main | 1 |
| W1 | building | yes | (1,2,3,4,1) |
Then placex contains exactly
| object | place_id |
| W1 | 1 |
| N10 | 2 |
| N1 | 1 |
| W1 | 2 |
And place_entrance contains exactly
| place_id | entrances |
| 1 | [{'lat': 0, 'lon': 0, 'type': 'main', 'osm_id': 10, 'extratags': None}] |
| 2 | [{'lat': 0, 'lon': 0, 'type': 'main', 'osm_id': 1, 'extratags': None}] |
Scenario: A building with a removed entrance
Given the grid
| 1 | 2 |
| 4 | 3 |
Given the places
| osm | class | type | geometry |
| W1 | building | yes | (1,2,3,4,1) |
| N10 | entrance | main | 1 |
| osm | class | type | geometry |
| N1 | entrance | main | 1 |
| W1 | building | yes | (1,2,3,4,1) |
And the ways
| id | nodes |
| 1 | 10,20,30,40 |
| id | nodes |
| 1 | 1, 2, 3, 4, 1 |
When importing
Then placex contains exactly
| object | place_id |
| W1 | 1 |
And place_entrance contains exactly
| place_id | entrances |
| 1 | [{'lat': 0, 'lon': 0, 'type': 'main', 'osm_id': 10, 'extratags': None}] |
When marking for delete N10
| 1 | [{'lat': 0, 'lon': 0, 'type': 'main', 'osm_id': 1, 'extratags': None}] |
When marking for delete N1
And updating places
| osm | class | type | geometry |
| W1 | building | yes | (2,3,4,2) |
Then placex contains exactly
| object | place_id |
| W1 | 1 |

View File

@@ -7,6 +7,7 @@
"""
Helper functions to compare expected values.
"""
import collections.abc
import json
import re
import math
@@ -102,8 +103,13 @@ class ResultAttr:
self.subobj = self.obj
for sub in self.key.split('+'):
done += f"[{sub}]"
assert sub in self.subobj, \
f"Missing attribute {done}. Full object:\n{_pretty(self.obj)}"
if isinstance(self.subobj, collections.abc.Sequence) and sub.isdigit():
sub = int(sub)
assert sub < len(self.subobj), \
f"Out of bound index {done}. Full object:\n{_pretty(self.obj)}"
else:
assert sub in self.subobj, \
f"Missing attribute {done}. Full object:\n{_pretty(self.obj)}"
self.subobj = self.subobj[sub]
def __eq__(self, other):