From 0d338fa4c06f922f30fae30af3062da57af69d53 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Wed, 21 Jun 2023 11:33:42 +0200 Subject: [PATCH 1/3] bdd: fix faking HTTP headers for python web frameworks --- nominatim/api/v1/helpers.py | 2 +- test/bdd/steps/steps_api_queries.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nominatim/api/v1/helpers.py b/nominatim/api/v1/helpers.py index ea7c125d..325e5bc6 100644 --- a/nominatim/api/v1/helpers.py +++ b/nominatim/api/v1/helpers.py @@ -83,7 +83,7 @@ def extend_query_parts(queryparts: Dict[str, Any], details: Dict[str, Any], if parsed.countries: queryparts['countrycodes'] = ','.join(parsed.countries) queryparts['exclude_place_ids'] = \ - ','.join(chain(excluded, map(str, parsed.excluded))) + ','.join(chain(excluded, map(str, (e for e in parsed.excluded if e > 0)))) if parsed.viewbox: queryparts['viewbox'] = ','.join(f"{c:.7g}" for c in parsed.viewbox.coords) if parsed.bounded_viewbox: diff --git a/test/bdd/steps/steps_api_queries.py b/test/bdd/steps/steps_api_queries.py index 55bb2084..3d3b16c7 100644 --- a/test/bdd/steps/steps_api_queries.py +++ b/test/bdd/steps/steps_api_queries.py @@ -111,7 +111,8 @@ def send_api_query_php(endpoint, params, context): LOG.debug("Environment:" + json.dumps(env, sort_keys=True, indent=2)) if hasattr(context, 'http_headers'): - env.update(context.http_headers) + for k, v in context.http_headers.items(): + env['HTTP_' + k.upper().replace('-', '_')] = v cmd = ['/usr/bin/env', 'php-cgi', '-f'] if context.nominatim.code_coverage_path: @@ -148,8 +149,7 @@ def add_http_header(context): context.http_headers = {} for h in context.table.headings: - envvar = 'HTTP_' + h.upper().replace('-', '_') - context.http_headers[envvar] = context.table[0][h] + context.http_headers[h] = context.table[0][h] @when(u'sending (?P\S+ )?search query "(?P.*)"(?P with address)?') From 2d05ff01905df13c9a365a4b4e36b432b43828d0 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 22 Jun 2023 16:51:59 +0200 Subject: [PATCH 2/3] slightly adapt postcode tests --- test/bdd/db/query/normalization.feature | 6 +++--- test/bdd/db/update/naming.feature | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/bdd/db/query/normalization.feature b/test/bdd/db/query/normalization.feature index 5e94cd3e..47906133 100644 --- a/test/bdd/db/query/normalization.feature +++ b/test/bdd/db/query/normalization.feature @@ -160,10 +160,10 @@ Feature: Import and search of names | | 2 | | | 1 | | 3 | Given the places - | osm | class | type | postcode | geometry | - | R1 | boundary | postal_code | 12345 | (1,2,3,1) | + | osm | class | type | postcode | geometry | + | R1 | boundary | postal_code | 123-45 | (1,2,3,1) | When importing - When sending search query "12345" + When sending search query "123-45" Then results contain | ID | osm | | 0 | R1 | diff --git a/test/bdd/db/update/naming.feature b/test/bdd/db/update/naming.feature index c6ff1388..6c1a817b 100644 --- a/test/bdd/db/update/naming.feature +++ b/test/bdd/db/update/naming.feature @@ -8,9 +8,9 @@ Feature: Update of names in place objects | 4 | 3 | Given the places | osm | class | type | postcode | geometry | - | R1 | boundary | postal_code | 12345 | (1,2,3,4,1) | + | R1 | boundary | postal_code | 123-45 | (1,2,3,4,1) | When importing - And sending search query "12345" + And sending search query "123-45" Then results contain | ID | osm | | 0 | R1 | From ed19340af042cfd81f619ee60776052c411d86d4 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 22 Jun 2023 17:29:44 +0200 Subject: [PATCH 3/3] add python frontend tests to CI --- .github/workflows/ci-tests.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index a22a89c0..48de6e0d 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -186,6 +186,39 @@ jobs: working-directory: Nominatim/test/bdd + python-api-test: + needs: create-archive + runs-on: ubuntu-22.04 + + steps: + - uses: actions/download-artifact@v3 + with: + name: full-source + + - name: Unpack Nominatim + run: tar xf nominatim-src.tar.bz2 + + - uses: ./Nominatim/.github/actions/setup-postgresql + with: + postgresql-version: 15 + postgis-version: 3 + + - uses: ./Nominatim/.github/actions/build-nominatim + with: + flavour: 'ubuntu-22' + + - name: Install test prerequsites + run: sudo apt-get install -y -qq python3-behave + + - name: Install Python webservers + run: pip3 install starlette asgi_lifespan httpx + + - name: BDD tests (starlette) + run: | + python3 -m behave -DREMOVE_TEMPLATE=1 -DBUILDDIR=$GITHUB_WORKSPACE/build -DAPI_ENGINE=starlette --format=progress3 + working-directory: Nominatim/test/bdd + + install: runs-on: ubuntu-latest needs: create-archive