Skip to content

Commit

Permalink
enable BDD tests for sqlite databases
Browse files Browse the repository at this point in the history
The database must currently be created by hand and the name handed
in via -DAPI_TEST_DB='sqlite:...'.
  • Loading branch information
lonvia committed Oct 13, 2023
1 parent 04fad9f commit 2f53ba9
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion nominatim/api/reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ async def _lookup_area_others(self) -> Optional[SaRow]:
.where(t.c.indexed_status == 0)\
.where(t.c.linked_place_id == None)\
.where(self._filter_by_layer(t))\
.where(t.c.geometry.intersects(sa.func.ST_Expand(WKT_PARAM, 0.001)))\
.where(t.c.geometry.intersects(sa.func.ST_Expand(WKT_PARAM, 0.007)))\
.order_by(sa.desc(t.c.rank_search))\
.order_by('distance')\
.limit(50)\
Expand Down
1 change: 1 addition & 0 deletions test/bdd/api/details/language.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: Localization of search results

Expand Down
7 changes: 7 additions & 0 deletions test/bdd/api/details/params.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Feature: Object details
Testing different parameter options for details API.

@SQLITE
Scenario: JSON Details
When sending json details query for W297699560
Then the result is valid json
Expand All @@ -11,6 +12,7 @@ Feature: Object details
| type |
| Point |

@SQLITE
Scenario: JSON Details with pretty printing
When sending json details query for W297699560
| pretty |
Expand All @@ -19,27 +21,31 @@ Feature: Object details
And result has attributes geometry
And result has not attributes keywords,address,linked_places,parentof

@SQLITE
Scenario: JSON Details with addressdetails
When sending json details query for W297699560
| addressdetails |
| 1 |
Then the result is valid json
And result has attributes address

@SQLITE
Scenario: JSON Details with linkedplaces
When sending json details query for R123924
| linkedplaces |
| 1 |
Then the result is valid json
And result has attributes linked_places

@SQLITE
Scenario: JSON Details with hierarchy
When sending json details query for W297699560
| hierarchy |
| 1 |
Then the result is valid json
And result has attributes hierarchy

@SQLITE
Scenario: JSON Details with grouped hierarchy
When sending json details query for W297699560
| hierarchy | group_hierarchy |
Expand Down Expand Up @@ -69,6 +75,7 @@ Feature: Object details
Then the result is valid json
And result has attributes keywords

@SQLITE
Scenario Outline: JSON details with full geometry
When sending json details query for <osmid>
| polygon_geojson |
Expand Down
1 change: 1 addition & 0 deletions test/bdd/api/details/simple.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: Object details
Check details page for correctness
Expand Down
1 change: 1 addition & 0 deletions test/bdd/api/errors/formats.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: Places by osm_type and osm_id Tests
Simple tests for errors in various response formats.
Expand Down
1 change: 1 addition & 0 deletions test/bdd/api/lookup/simple.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: Places by osm_type and osm_id Tests
Simple tests for response format.
Expand Down
7 changes: 4 additions & 3 deletions test/bdd/api/reverse/geometry.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: Geometries for reverse geocoding
Tests for returning geometries with reverse
Expand All @@ -9,7 +10,7 @@ Feature: Geometries for reverse geocoding
| 1 |
Then results contain
| geotext |
| POLYGON((9.5225302 47.138066,9.5225348 47.1379282,9.5226142 47.1379294,9.5226143 47.1379257,9.522615 47.137917,9.5226225 47.1379098,9.5226334 47.1379052,9.5226461 47.1379037,9.5226588 47.1379056,9.5226693 47.1379107,9.5226762 47.1379181,9.5226762 47.1379268,9.5226761 47.1379308,9.5227366 47.1379317,9.5227352 47.1379753,9.5227608 47.1379757,9.5227595 47.1380148,9.5227355 47.1380145,9.5227337 47.1380692,9.5225302 47.138066)) |
| ^POLYGON\(\(9.5225302 47.138066, ?9.5225348 47.1379282, ?9.5226142 47.1379294, ?9.5226143 47.1379257, ?9.522615 47.137917, ?9.5226225 47.1379098, ?9.5226334 47.1379052, ?9.5226461 47.1379037, ?9.5226588 47.1379056, ?9.5226693 47.1379107, ?9.5226762 47.1379181, ?9.5226762 47.1379268, ?9.5226761 47.1379308, ?9.5227366 47.1379317, ?9.5227352 47.1379753, ?9.5227608 47.1379757, ?9.5227595 47.1380148, ?9.5227355 47.1380145, ?9.5227337 47.1380692, ?9.5225302 47.138066\)\) |


Scenario: Polygons can be slightly simplified
Expand All @@ -18,7 +19,7 @@ Feature: Geometries for reverse geocoding
| 1 | 0.00001 |
Then results contain
| geotext |
| POLYGON((9.5225302 47.138066,9.5225348 47.1379282,9.5226142 47.1379294,9.5226225 47.1379098,9.5226588 47.1379056,9.5226761 47.1379308,9.5227366 47.1379317,9.5227352 47.1379753,9.5227608 47.1379757,9.5227595 47.1380148,9.5227355 47.1380145,9.5227337 47.1380692,9.5225302 47.138066)) |
| ^POLYGON\(\(9.5225302 47.138066, ?9.5225348 47.1379282, ?9.5226142 47.1379294, ?9.5226225 47.1379098, ?9.5226588 47.1379056, ?9.5226761 47.1379308, ?9.5227366 47.1379317, ?9.5227352 47.1379753, ?9.5227608 47.1379757, ?9.5227595 47.1380148, ?9.5227355 47.1380145, ?9.5227337 47.1380692, ?9.5225302 47.138066\)\) |


Scenario: Polygons can be much simplified
Expand All @@ -27,7 +28,7 @@ Feature: Geometries for reverse geocoding
| 1 | 0.9 |
Then results contain
| geotext |
| POLYGON((9.5225302 47.138066,9.5225348 47.1379282,9.5227608 47.1379757,9.5227337 47.1380692,9.5225302 47.138066)) |
| ^POLYGON\(\(9.5225302 47.138066, ?9.5225348 47.1379282, ?9.5227608 47.1379757, ?9.5227337 47.1380692, ?9.5225302 47.138066\)\) |


Scenario: For polygons return the centroid as center point
Expand Down
1 change: 1 addition & 0 deletions test/bdd/api/reverse/language.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: Localization of reverse search results

Expand Down
7 changes: 4 additions & 3 deletions test/bdd/api/reverse/layers.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: Layer parameter in reverse geocoding
Testing correct function of layer selection while reverse geocoding
Expand Down Expand Up @@ -57,7 +58,7 @@ Feature: Layer parameter in reverse geocoding

@v1-api-python-only
Scenario Outline: Search for mountain peaks begins at level 12
When sending v1/reverse at 47.08221,9.56769
When sending v1/reverse at 47.08293,9.57109
| layer | zoom |
| natural | <zoom> |
Then results contain
Expand All @@ -71,7 +72,7 @@ Feature: Layer parameter in reverse geocoding


@v1-api-python-only
Scenario Outline: Reverse serach with manmade layers
Scenario Outline: Reverse search with manmade layers
When sending v1/reverse at 32.46904,-86.44439
| layer |
| <layer> |
Expand All @@ -84,5 +85,5 @@ Feature: Layer parameter in reverse geocoding
| manmade | leisure | park |
| address | highway | residential |
| poi | leisure | pitch |
| natural | waterway | stream |
| natural | waterway | river |
| natural,manmade | leisure | park |
1 change: 1 addition & 0 deletions test/bdd/api/reverse/queries.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: Reverse geocoding
Testing the reverse function
Expand Down
1 change: 1 addition & 0 deletions test/bdd/api/reverse/v1_geocodejson.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: Geocodejson for Reverse API
Testing correctness of geocodejson output (API version v1).
Expand Down
1 change: 1 addition & 0 deletions test/bdd/api/reverse/v1_geojson.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: Geojson for Reverse API
Testing correctness of geojson output (API version v1).
Expand Down
3 changes: 2 additions & 1 deletion test/bdd/api/reverse/v1_json.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: Json output for Reverse API
Testing correctness of json and jsonv2 output (API version v1).
Expand Down Expand Up @@ -93,7 +94,7 @@ Feature: Json output for Reverse API
| polygon_text | 1 |
Then results contain
| geotext |
| LINESTRING(9.5039353 47.0657546,9.5040437 47.0657781,9.5040808 47.065787,9.5054298 47.0661407) |
| ^LINESTRING\(9.5039353 47.0657546, ?9.5040437 47.0657781, ?9.5040808 47.065787, ?9.5054298 47.0661407\) |

Examples:
| format |
Expand Down
1 change: 1 addition & 0 deletions test/bdd/api/reverse/v1_params.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: v1/reverse Parameter Tests
Tests for parameter inputs for the v1 reverse endpoint.
Expand Down
3 changes: 2 additions & 1 deletion test/bdd/api/reverse/v1_xml.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: XML output for Reverse API
Testing correctness of xml output (API version v1).
Expand Down Expand Up @@ -66,7 +67,7 @@ Feature: XML output for Reverse API
| polygon_text | 1 |
Then results contain
| geotext |
| LINESTRING(9.5039353 47.0657546,9.5040437 47.0657781,9.5040808 47.065787,9.5054298 47.0661407) |
| ^LINESTRING\(9.5039353 47.0657546, ?9.5040437 47.0657781, ?9.5040808 47.065787, ?9.5054298 47.0661407\) |


Scenario: Output of SVG
Expand Down
1 change: 1 addition & 0 deletions test/bdd/api/status/simple.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SQLITE
@APIDB
Feature: Status queries
Testing status query
Expand Down
5 changes: 4 additions & 1 deletion test/bdd/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def before_all(context):


def before_scenario(context, scenario):
if 'DB' in context.tags:
if not 'SQLITE' in context.tags \
and context.config.userdata['API_TEST_DB'].startswith('sqlite:'):
context.scenario.skip("Not usable with Sqlite database.")
elif 'DB' in context.tags:
context.nominatim.setup_db(context)
elif 'APIDB' in context.tags:
context.nominatim.setup_api_db()
Expand Down
8 changes: 7 additions & 1 deletion test/bdd/steps/nominatim_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def write_nominatim_config(self, dbname):
be picked up by dotenv and creates a project directory with the
appropriate website scripts.
"""
dsn = 'pgsql:dbname={}'.format(dbname)
if dbname.startswith('sqlite:'):
dsn = 'sqlite:dbname={}'.format(dbname[7:])
else:
dsn = 'pgsql:dbname={}'.format(dbname)
if self.db_host:
dsn += ';host=' + self.db_host
if self.db_port:
Expand Down Expand Up @@ -197,6 +200,9 @@ def setup_api_db(self):
"""
self.write_nominatim_config(self.api_test_db)

if self.api_test_db.startswith('sqlite:'):
return

if not self.api_db_done:
self.api_db_done = True

Expand Down

0 comments on commit 2f53ba9

Please sign in to comment.