]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/bdd/steps/queries.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / test / bdd / steps / queries.py
index 7d3dec69e2e56ffac2e17daa3deb54f9a55f8505..443342b0d1b86f79d634f42c1daaf01972f8c281 100644 (file)
@@ -8,6 +8,7 @@ import json
 import os
 import io
 import re
 import os
 import io
 import re
+import logging
 from tidylib import tidy_document
 import xml.etree.ElementTree as ET
 import subprocess
 from tidylib import tidy_document
 import xml.etree.ElementTree as ET
 import subprocess
@@ -15,6 +16,8 @@ from urllib.parse import urlencode
 from collections import OrderedDict
 from nose.tools import * # for assert functions
 
 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',
 BASE_SERVER_ENV = {
     'HTTP_HOST' : 'localhost',
     'HTTP_USER_AGENT' : 'Mozilla/5.0 (X11; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0',
@@ -264,7 +267,7 @@ def send_api_query(endpoint, params, fmt, context):
             for h in context.table.headings:
                 params[h] = context.table[0][h]
 
             for h in context.table.headings:
                 params[h] = context.table[0][h]
 
-    env = BASE_SERVER_ENV
+    env = dict(BASE_SERVER_ENV)
     env['QUERY_STRING'] = urlencode(params)
 
     env['SCRIPT_NAME'] = '/%s.php' % endpoint
     env['QUERY_STRING'] = urlencode(params)
 
     env['SCRIPT_NAME'] = '/%s.php' % endpoint
@@ -274,10 +277,23 @@ def send_api_query(endpoint, params, fmt, context):
                                           '%s.php' % endpoint)
     env['NOMINATIM_SETTINGS'] = context.nominatim.local_settings_file
 
                                           '%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)
 
     if hasattr(context, 'http_headers'):
         env.update(context.http_headers)
 
-    cmd = ['/usr/bin/php-cgi', env['SCRIPT_FILENAME']]
+    cmd = ['/usr/bin/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))
 
     for k,v in params.items():
         cmd.append("%s=%s" % (k, v))
 
@@ -285,14 +301,16 @@ def send_api_query(endpoint, params, fmt, context):
                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
     (outp, err) = proc.communicate()
                             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))
 
     assert_equals(0, len(err), "Unexpected PHP error: %s" % (err))
 
 
     assert_equals(0, proc.returncode,
                   "query.php failed with message: %s\noutput: %s" % (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:
     if outp.startswith('Status: '):
         status = int(outp[8:11])
     else: