]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/bdd/steps/nominatim_environment.py
use DataDir constant for data only
[nominatim.git] / test / bdd / steps / nominatim_environment.py
index bc59076c2bfb8ccd9198ce7073cf2df80e1a6794..dd76dee3fbcced1ee9688d7ffae53d75c2d65718 100644 (file)
@@ -1,10 +1,13 @@
-import os
 from pathlib import Path
+import sys
 import tempfile
 
 import psycopg2
 import psycopg2.extras
 
+sys.path.insert(1, str((Path(__file__) / '..' / '..' / '..' / '..').resolve()))
+
+from nominatim.config import Configuration
 from steps.utils import run_script
 
 class NominatimEnvironment:
@@ -28,6 +31,7 @@ class NominatimEnvironment:
         self.code_coverage_path = config['PHPCOV']
         self.code_coverage_id = 1
 
+        self.default_config = Configuration(None, self.src_dir / 'settings').get_os_env()
         self.test_env = None
         self.template_db_done = False
         self.api_db_done = False
@@ -78,14 +82,23 @@ class NominatimEnvironment:
            and dsn == self.test_env['NOMINATIM_DATABASE_DSN']:
             return # environment already set uo
 
-        self.test_env = os.environ
+        self.test_env = dict(self.default_config)
         self.test_env['NOMINATIM_DATABASE_DSN'] = dsn
         self.test_env['NOMINATIM_FLATNODE_FILE'] = ''
         self.test_env['NOMINATIM_IMPORT_STYLE'] = 'full'
         self.test_env['NOMINATIM_USE_US_TIGER_DATA'] = 'yes'
+        self.test_env['NOMINATIM_DATADIR'] = self.src_dir / 'data'
+        self.test_env['NOMINATIM_SQLDIR'] = self.src_dir / 'lib-sql'
+        self.test_env['NOMINATIM_CONFIGDIR'] = self.src_dir / 'settings'
+        self.test_env['NOMINATIM_DATABASE_MODULE_SRC_PATH'] = self.build_dir / 'module'
+        self.test_env['NOMINATIM_OSM2PGSQL_BINARY'] = self.build_dir / 'osm2pgsql' / 'osm2pgsql'
+        self.test_env['NOMINATIM_NOMINATIM_TOOL'] = self.build_dir / 'nominatim'
 
         if self.server_module_path:
             self.test_env['NOMINATIM_DATABASE_MODULE_PATH'] = self.server_module_path
+        else:
+            # avoid module being copied into the temporary environment
+            self.test_env['NOMINATIM_DATABASE_MODULE_PATH'] = self.build_dir / 'module'
 
         if self.website_dir is not None:
             self.website_dir.cleanup()
@@ -167,8 +180,11 @@ class NominatimEnvironment:
         self.test_env['NOMINATIM_WIKIPEDIA_DATA_PATH'] = str(testdata.resolve())
 
         try:
-            self.run_setup_script('all', 'import-tiger-data',
-                                  osm_file=self.api_test_file)
+            self.run_setup_script('all', osm_file=self.api_test_file)
+            self.run_setup_script('import-tiger-data')
+
+            phrase_file = str((testdata / 'specialphrases_testdb.sql').resolve())
+            run_script(['psql', '-d', self.api_test_db, '-f', phrase_file])
         except:
             self.db_drop_database(self.api_test_db)
             raise
@@ -250,7 +266,7 @@ class NominatimEnvironment:
         """ Run one of the Nominatim utility scripts with the given arguments.
         """
         cmd = ['/usr/bin/env', 'php', '-Cq']
-        cmd.append((Path(self.build_dir) / 'utils' / '{}.php'.format(script)).resolve())
+        cmd.append((Path(self.src_dir) / 'lib-php' / 'admin' / '{}.php'.format(script)).resolve())
         cmd.extend(['--' + x for x in args])
         for k, v in kwargs.items():
             cmd.extend(('--' + k.replace('_', '-'), str(v)))
@@ -258,7 +274,7 @@ class NominatimEnvironment:
         if self.website_dir is not None:
             cwd = self.website_dir.name
         else:
-            cwd = self.build_dir
+            cwd = None
 
         run_script(cmd, cwd=cwd, env=self.test_env)