'TEMPLATE_DB' : 'test_template_nominatim',
'TEST_DB' : 'test_nominatim',
'API_TEST_DB' : 'test_api_nominatim',
- 'TEST_SETTINGS_FILE' : '/tmp/nominatim_settings.php',
'SERVER_MODULE_PATH' : None,
'PHPCOV' : False, # set to output directory to enable code coverage
}
self.test_db = config['TEST_DB']
self.api_test_db = config['API_TEST_DB']
self.server_module_path = config['SERVER_MODULE_PATH']
- self.local_settings_file = config['TEST_SETTINGS_FILE']
self.reuse_template = not config['REMOVE_TEMPLATE']
self.keep_scenario_db = config['KEEP_TEST_DB']
self.code_coverage_path = config['PHPCOV']
self.code_coverage_id = 1
self.test_env = None
- os.environ['NOMINATIM_SETTINGS'] = self.local_settings_file
self.template_db_done = False
+ self.website_dir = None
def connect_database(self, dbname):
dbargs = {'database': dbname}
(';user=' + self.db_user) if self.db_user else '',
(';password=' + self.db_pass) if self.db_pass else ''
)
+
+ if self.website_dir is not None \
+ and self.test_env is not None \
+ and dsn == self.test_env['NOMINATIM_DATABASE_DSN']:
+ return # environment already set uo
+
self.test_env = os.environ
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'
- f = open(self.local_settings_file, 'w')
- # https://secure.php.net/manual/en/ref.pdo-pgsql.connection.php
- f.write("<?php\n @define('CONST_Database_DSN', '{}');\n".format(dsn))
- f.write("@define('CONST_Osm2pgsql_Flatnode_File', null);\n")
- f.write("@define('CONST_Import_Style', CONST_DataDir.'/settings/import-full.style');\n")
- f.write("@define('CONST_Use_US_Tiger_Data', true);\n")
- f.close()
+ if self.website_dir is not None:
+ self.website_dir.cleanup()
+ self.website_dir = tempfile.TemporaryDirectory()
+ self.run_setup_script('setup-website')
- def cleanup(self):
- try:
- os.remove(self.local_settings_file)
- except OSError:
- pass # ignore missing file
def db_drop_database(self, name):
conn = self.connect_database('postgres')
cmd.extend(['--%s' % x for x in args])
for k, v in kwargs.items():
cmd.extend(('--' + k.replace('_', '-'), str(v)))
- proc = subprocess.Popen(cmd, cwd=self.build_dir, env=self.test_env,
+
+ if self.website_dir is not None:
+ cwd = self.website_dir.name
+ else:
+ cwd = self.build_dir
+
+ proc = subprocess.Popen(cmd, cwd=cwd, env=self.test_env,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(outp, outerr) = proc.communicate()
outerr = outerr.decode('utf-8').replace('\\n', '\n')
context.nominatim = NominatimEnvironment(context.config.userdata)
context.osm = OSMDataFactory()
-def after_all(context):
- context.nominatim.cleanup()
-
def before_scenario(context, scenario):
if 'DB' in context.tags:
env['SCRIPT_NAME'] = '/%s.php' % endpoint
env['REQUEST_URI'] = '%s?%s' % (env['SCRIPT_NAME'], env['QUERY_STRING'])
- env['CONTEXT_DOCUMENT_ROOT'] = os.path.join(context.nominatim.build_dir, 'website')
+ env['CONTEXT_DOCUMENT_ROOT'] = os.path.join(context.nominatim.website_dir.name, 'website')
env['SCRIPT_FILENAME'] = os.path.join(env['CONTEXT_DOCUMENT_ROOT'],
'%s.php' % endpoint)
- env['NOMINATIM_SETTINGS'] = context.nominatim.local_settings_file
logger.debug("Environment:" + json.dumps(env, sort_keys=True, indent=2))
for k,v in params.items():
cmd.append("%s=%s" % (k, v))
- proc = subprocess.Popen(cmd, cwd=context.nominatim.build_dir, env=env,
+ proc = subprocess.Popen(cmd, cwd=context.nominatim.website_dir.name, env=env,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(outp, err) = proc.communicate()