mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 02:58:13 +00:00
bdd: add tests for valid debug output
This commit is contained in:
@@ -96,7 +96,7 @@ class HTMLLogger(BaseLogger):
|
|||||||
.compile(conn.sync_engine, compile_kwargs={"literal_binds": True}))
|
.compile(conn.sync_engine, compile_kwargs={"literal_binds": True}))
|
||||||
if CODE_HIGHLIGHT:
|
if CODE_HIGHLIGHT:
|
||||||
sqlstr = highlight(sqlstr, PostgresLexer(),
|
sqlstr = highlight(sqlstr, PostgresLexer(),
|
||||||
HtmlFormatter(nowrap=True, lineseparator='<br>'))
|
HtmlFormatter(nowrap=True, lineseparator='<br />'))
|
||||||
self._write(f'<div class="highlight"><code class="lang-sql">{sqlstr}</code></div>')
|
self._write(f'<div class="highlight"><code class="lang-sql">{sqlstr}</code></div>')
|
||||||
else:
|
else:
|
||||||
self._write(f'<code class="lang-sql">{sqlstr}</code>')
|
self._write(f'<code class="lang-sql">{sqlstr}</code>')
|
||||||
|
|||||||
@@ -103,3 +103,16 @@ Feature: Object details
|
|||||||
| category | type | admin_level |
|
| category | type | admin_level |
|
||||||
| place | postcode | 15 |
|
| place | postcode | 15 |
|
||||||
And result has not attributes osm_type,osm_id
|
And result has not attributes osm_type,osm_id
|
||||||
|
|
||||||
|
|
||||||
|
@v1-api-python-only
|
||||||
|
Scenario Outline: Details debug output returns no errors
|
||||||
|
When sending debug details query for <feature>
|
||||||
|
Then the result is valid html
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
| feature |
|
||||||
|
| N5484325405 |
|
||||||
|
| W1 |
|
||||||
|
| 112820 |
|
||||||
|
| 112871 |
|
||||||
|
|||||||
@@ -132,6 +132,8 @@ Feature: Simple Reverse Tests
|
|||||||
| Nan | 8.448 |
|
| Nan | 8.448 |
|
||||||
| 48.966 | Nan |
|
| 48.966 | Nan |
|
||||||
|
|
||||||
Scenario: Reverse Debug output returns no errors
|
|
||||||
|
@v1-api-python-only
|
||||||
|
Scenario: Reverse Debug output returns no errors
|
||||||
When sending debug reverse coordinates 47.11,9.57
|
When sending debug reverse coordinates 47.11,9.57
|
||||||
Then a HTTP 200 is returned
|
Then the result is valid html
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
from utils import run_script
|
from utils import run_script
|
||||||
@@ -73,8 +74,12 @@ def compare(operator, op1, op2):
|
|||||||
|
|
||||||
|
|
||||||
def send_api_query(endpoint, params, fmt, context):
|
def send_api_query(endpoint, params, fmt, context):
|
||||||
if fmt is not None and fmt.strip() != 'debug':
|
if fmt is not None:
|
||||||
params['format'] = fmt.strip()
|
if fmt.strip() == 'debug':
|
||||||
|
params['debug'] = '1'
|
||||||
|
else:
|
||||||
|
params['format'] = fmt.strip()
|
||||||
|
|
||||||
if context.table:
|
if context.table:
|
||||||
if context.table.headings[0] == 'param':
|
if context.table.headings[0] == 'param':
|
||||||
for line in context.table:
|
for line in context.table:
|
||||||
@@ -154,8 +159,6 @@ def website_search_request(context, fmt, query, addr):
|
|||||||
params['q'] = query
|
params['q'] = query
|
||||||
if addr is not None:
|
if addr is not None:
|
||||||
params['addressdetails'] = '1'
|
params['addressdetails'] = '1'
|
||||||
if fmt and fmt.strip() == 'debug':
|
|
||||||
params['debug'] = '1'
|
|
||||||
|
|
||||||
outp, status = send_api_query('search', params, fmt, context)
|
outp, status = send_api_query('search', params, fmt, context)
|
||||||
|
|
||||||
@@ -168,8 +171,6 @@ def website_reverse_request(context, fmt, lat, lon):
|
|||||||
params['lat'] = lat
|
params['lat'] = lat
|
||||||
if lon is not None:
|
if lon is not None:
|
||||||
params['lon'] = lon
|
params['lon'] = lon
|
||||||
if fmt and fmt.strip() == 'debug':
|
|
||||||
params['debug'] = '1'
|
|
||||||
|
|
||||||
outp, status = send_api_query('reverse', params, fmt, context)
|
outp, status = send_api_query('reverse', params, fmt, context)
|
||||||
|
|
||||||
@@ -178,8 +179,6 @@ def website_reverse_request(context, fmt, lat, lon):
|
|||||||
@when(u'sending (?P<fmt>\S+ )?reverse point (?P<nodeid>.+)')
|
@when(u'sending (?P<fmt>\S+ )?reverse point (?P<nodeid>.+)')
|
||||||
def website_reverse_request(context, fmt, nodeid):
|
def website_reverse_request(context, fmt, nodeid):
|
||||||
params = {}
|
params = {}
|
||||||
if fmt and fmt.strip() == 'debug':
|
|
||||||
params['debug'] = '1'
|
|
||||||
params['lon'], params['lat'] = (f'{c:f}' for c in context.osm.grid_node(int(nodeid)))
|
params['lon'], params['lat'] = (f'{c:f}' for c in context.osm.grid_node(int(nodeid)))
|
||||||
|
|
||||||
|
|
||||||
@@ -220,7 +219,7 @@ def website_status_request(context, fmt):
|
|||||||
|
|
||||||
@step(u'(?P<operator>less than|more than|exactly|at least|at most) (?P<number>\d+) results? (?:is|are) returned')
|
@step(u'(?P<operator>less than|more than|exactly|at least|at most) (?P<number>\d+) results? (?:is|are) returned')
|
||||||
def validate_result_number(context, operator, number):
|
def validate_result_number(context, operator, number):
|
||||||
assert context.response.errorcode == 200
|
context.execute_steps("Then a HTTP 200 is returned")
|
||||||
numres = len(context.response.result)
|
numres = len(context.response.result)
|
||||||
assert compare(operator, numres, int(number)), \
|
assert compare(operator, numres, int(number)), \
|
||||||
f"Bad number of results: expected {operator} {number}, got {numres}."
|
f"Bad number of results: expected {operator} {number}, got {numres}."
|
||||||
@@ -237,7 +236,19 @@ def check_page_content_equals(context, text):
|
|||||||
@then(u'the result is valid (?P<fmt>\w+)')
|
@then(u'the result is valid (?P<fmt>\w+)')
|
||||||
def step_impl(context, fmt):
|
def step_impl(context, fmt):
|
||||||
context.execute_steps("Then a HTTP 200 is returned")
|
context.execute_steps("Then a HTTP 200 is returned")
|
||||||
assert context.response.format == fmt
|
if fmt.strip() == 'html':
|
||||||
|
try:
|
||||||
|
tree = ET.fromstring(context.response.page)
|
||||||
|
except Exception as ex:
|
||||||
|
assert False, f"Could not parse page:\n{context.response.page}"
|
||||||
|
|
||||||
|
assert tree.tag == 'html'
|
||||||
|
body = tree.find('./body')
|
||||||
|
assert body is not None
|
||||||
|
assert body.find('.//script') is None
|
||||||
|
else:
|
||||||
|
assert context.response.format == fmt
|
||||||
|
|
||||||
|
|
||||||
@then(u'a (?P<fmt>\w+) user error is returned')
|
@then(u'a (?P<fmt>\w+) user error is returned')
|
||||||
def check_page_error(context, fmt):
|
def check_page_error(context, fmt):
|
||||||
|
|||||||
Reference in New Issue
Block a user