import os
import io
import re
+import logging
from tidylib import tidy_document
import xml.etree.ElementTree as ET
import subprocess
from collections import OrderedDict
from nose.tools import * # for assert functions
+logger = logging.getLogger(__name__)
+
BASE_SERVER_ENV = {
'HTTP_HOST' : 'localhost',
'HTTP_USER_AGENT' : 'Mozilla/5.0 (X11; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0',
options={'char-encoding' : 'utf8'})
self.result = {}
+ def parse_json(self):
+ self.result = [json.JSONDecoder(object_pairs_hook=OrderedDict).decode(self.page)]
+
+
@when(u'searching for "(?P<query>.*)"(?P<dups> with dups)?')
def query_cmd(context, query, dups):
""" Query directly via PHP script.
"""
- cmd = [os.path.join(context.nominatim.build_dir, 'utils', 'query.php'),
- '--search', query]
+ cmd = ['/usr/bin/env', 'php']
+ cmd.append(os.path.join(context.nominatim.build_dir, 'utils', 'query.php'))
+ cmd.extend(['--search', query])
# add more parameters in table form
if context.table:
for h in context.table.headings:
'%s.php' % endpoint)
env['NOMINATIM_SETTINGS'] = context.nominatim.local_settings_file
+ logger.debug("Environment:" + json.dumps(env, sort_keys=True, indent=2))
+
if hasattr(context, 'http_headers'):
env.update(context.http_headers)
- cmd = ['/usr/bin/php-cgi', env['SCRIPT_FILENAME']]
+ cmd = ['/usr/bin/env', 'php-cgi', '-f']
+ if context.nominatim.code_coverage_path:
+ env['COV_SCRIPT_FILENAME'] = env['SCRIPT_FILENAME']
+ env['COV_PHP_DIR'] = os.path.join(context.nominatim.src_dir, "lib")
+ env['COV_TEST_NAME'] = '%s:%s' % (context.scenario.filename, context.scenario.line)
+ env['SCRIPT_FILENAME'] = \
+ os.path.join(os.path.split(__file__)[0], 'cgi-with-coverage.php')
+ cmd.append(env['SCRIPT_FILENAME'])
+ env['PHP_CODE_COVERAGE_FILE'] = context.nominatim.next_code_coverage_file()
+ else:
+ cmd.append(env['SCRIPT_FILENAME'])
+
for k,v in params.items():
cmd.append("%s=%s" % (k, v))
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(outp, err) = proc.communicate()
+ outp = outp.decode('utf-8')
+
+ logger.debug("Result: \n===============================\n"
+ + outp + "\n===============================\n")
assert_equals(0, proc.returncode,
- "query.php failed with message: %s\noutput: %s" % (err, outp))
+ "%s failed with message: %s\noutput: %s" % (env['SCRIPT_FILENAME'], err, outp))
assert_equals(0, len(err), "Unexpected PHP error: %s" % (err))
- outp = outp.decode('utf-8')
-
if outp.startswith('Status: '):
status = int(outp[8:11])
else:
context.response = SearchResponse(outp, outfmt, status)
-@when(u'sending (?P<fmt>\S+ )?reverse coordinates (?P<lat>[0-9.-]+)?,(?P<lon>[0-9.-]+)?')
+@when(u'sending (?P<fmt>\S+ )?reverse coordinates (?P<lat>.+)?,(?P<lon>.+)?')
def website_reverse_request(context, fmt, lat, lon):
params = {}
if lat is not None:
params['place_id'] = query
outp, status = send_api_query('details', params, fmt, context)
- context.response = DetailsResponse(outp, 'html', status)
+ if fmt is None:
+ outfmt = 'html'
+ else:
+ outfmt = fmt.strip()
+
+ context.response = DetailsResponse(outp, outfmt, status)
@when(u'sending (?P<fmt>\S+ )?lookup query for (?P<query>.*)')
def website_lookup_request(context, fmt, query):
context.response = SearchResponse(outp, outfmt, status)
-
@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):
eq_(context.response.errorcode, 200)