def _runner():
        refresh.setup_website(tmp_path, def_config, temp_db_conn)

        proc = subprocess.run(['/usr/bin/env', 'php', '-Cq',
                               tmp_path / 'search.php'], check=False)

        return proc.returncode
Beispiel #2
0
def run_website_script(envdir, config):
    refresh.setup_website(envdir, envdir / 'php', config)

    proc = subprocess.run(
        ['/usr/bin/env', 'php', '-Cq', envdir / 'search.php'], check=False)

    return proc.returncode
Beispiel #3
0
def test_basedir_created(tmp_path, project_env, temp_db_conn):
    webdir = tmp_path / 'website'

    assert not webdir.exists()

    refresh.setup_website(webdir, project_env, temp_db_conn)

    assert webdir.exists()
    def write_nominatim_config(self, dbname):
        """ Set up a custom test configuration that connects to the given
            database. This sets up the environment variables so that they can
            be picked up by dotenv and creates a project directory with the
            appropriate website scripts.
        """
        dsn = 'pgsql:dbname={}'.format(dbname)
        if self.db_host:
            dsn += ';host=' + self.db_host
        if self.db_port:
            dsn += ';port=' + self.db_port
        if self.db_user:
            dsn += ';user='******';password='******'NOMINATIM_DATABASE_DSN']:
            return  # environment already set uo

        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'] = str(
            (self.src_dir / 'data').resolve())
        self.test_env['NOMINATIM_SQLDIR'] = str(
            (self.src_dir / 'lib-sql').resolve())
        self.test_env['NOMINATIM_CONFIGDIR'] = str(
            (self.src_dir / 'settings').resolve())
        self.test_env['NOMINATIM_DATABASE_MODULE_SRC_PATH'] = str(
            (self.build_dir / 'module').resolve())
        self.test_env['NOMINATIM_OSM2PGSQL_BINARY'] = str(
            (self.build_dir / 'osm2pgsql' / 'osm2pgsql').resolve())
        self.test_env['NOMINATIM_NOMINATIM_TOOL'] = str(
            (self.build_dir / 'nominatim').resolve())

        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'] = str(
                (self.build_dir / 'module').resolve())

        if self.website_dir is not None:
            self.website_dir.cleanup()

        self.website_dir = tempfile.TemporaryDirectory()
        cfg = Configuration(None,
                            self.src_dir / 'settings',
                            environ=self.test_env)
        refresh.setup_website(
            Path(self.website_dir.name) / 'website', self.src_dir / 'lib-php',
            cfg)