bdd: add tests for valid debug output

This commit is contained in:
Sarah Hoffmann
2023-03-09 20:10:51 +01:00
parent db1aa4d02e
commit 2b7eb4906a
4 changed files with 39 additions and 13 deletions

View File

@@ -96,7 +96,7 @@ class HTMLLogger(BaseLogger):
.compile(conn.sync_engine, compile_kwargs={"literal_binds": True}))
if CODE_HIGHLIGHT:
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>')
else:
self._write(f'<code class="lang-sql">{sqlstr}</code>')

View File

@@ -103,3 +103,16 @@ Feature: Object details
| category | type | admin_level |
| place | postcode | 15 |
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 |

View File

@@ -132,6 +132,8 @@ Feature: Simple Reverse Tests
| Nan | 8.448 |
| 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
Then a HTTP 200 is returned
Then the result is valid html

View File

@@ -15,6 +15,7 @@ import os
import re
import logging
import asyncio
import xml.etree.ElementTree as ET
from urllib.parse import urlencode
from utils import run_script
@@ -73,8 +74,12 @@ def compare(operator, op1, op2):
def send_api_query(endpoint, params, fmt, context):
if fmt is not None and fmt.strip() != 'debug':
params['format'] = fmt.strip()
if fmt is not None:
if fmt.strip() == 'debug':
params['debug'] = '1'
else:
params['format'] = fmt.strip()
if context.table:
if context.table.headings[0] == 'param':
for line in context.table:
@@ -154,8 +159,6 @@ def website_search_request(context, fmt, query, addr):
params['q'] = query
if addr is not None:
params['addressdetails'] = '1'
if fmt and fmt.strip() == 'debug':
params['debug'] = '1'
outp, status = send_api_query('search', params, fmt, context)
@@ -168,8 +171,6 @@ def website_reverse_request(context, fmt, lat, lon):
params['lat'] = lat
if lon is not None:
params['lon'] = lon
if fmt and fmt.strip() == 'debug':
params['debug'] = '1'
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>.+)')
def website_reverse_request(context, fmt, nodeid):
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)))
@@ -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')
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)
assert compare(operator, numres, int(number)), \
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+)')
def step_impl(context, fmt):
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')
def check_page_error(context, fmt):