X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/b90e719da595b6760b39b7cd64ee29447de2d5e8..4da4cbfe27a576ae011430b2de205c74435e241b:/test/python/tools/test_refresh_setup_website.py?ds=sidebyside diff --git a/test/python/tools/test_refresh_setup_website.py b/test/python/tools/test_refresh_setup_website.py index 8946bd1f..fe29dd52 100644 --- a/test/python/tools/test_refresh_setup_website.py +++ b/test/python/tools/test_refresh_setup_website.py @@ -1,3 +1,9 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This file is part of Nominatim. (https://nominatim.org) +# +# Copyright (C) 2024 by the Nominatim developer community. +# For a full list of authors see the git log. """ Tests for setting up the website scripts. """ @@ -5,7 +11,7 @@ import subprocess import pytest -from nominatim.tools import refresh +from nominatim_db.tools import refresh @pytest.fixture def test_script(tmp_path): @@ -22,12 +28,11 @@ def test_script(tmp_path): @pytest.fixture -def run_website_script(tmp_path, def_config, temp_db_conn): - def_config.lib_dir.php = tmp_path / 'php' - def_config.project_dir = tmp_path +def run_website_script(tmp_path, project_env, temp_db_conn): + project_env.lib_dir.php = tmp_path / 'php' def _runner(): - refresh.setup_website(tmp_path, def_config, temp_db_conn) + refresh.setup_website(tmp_path, project_env, temp_db_conn) proc = subprocess.run(['/usr/bin/env', 'php', '-Cq', tmp_path / 'search.php'], check=False) @@ -37,6 +42,16 @@ def run_website_script(tmp_path, def_config, temp_db_conn): return _runner +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() + + @pytest.mark.parametrize("setting,retval", (('yes', 10), ('no', 20))) def test_setup_website_check_bool(monkeypatch, test_script, run_website_script, setting, retval): @@ -70,3 +85,20 @@ def test_setup_website_check_str(monkeypatch, test_script, run_website_script): test_script('exit(CONST_Default_Language === "ffde 2" ? 10 : 20);') assert run_website_script() == 10 + + +def test_relative_log_file(project_env, monkeypatch, test_script, run_website_script): + monkeypatch.setenv('NOMINATIM_LOG_FILE', 'access.log') + + expected_file = str(project_env.project_dir / 'access.log') + test_script(f'exit(CONST_Log_File === "{expected_file}" ? 10 : 20);') + + assert run_website_script() == 10 + +def test_variable_with_bracket(project_env, monkeypatch, test_script, run_website_script): + monkeypatch.setenv('NOMINATIM_DATABASE_DSN', 'pgsql:dbname=nominatim;user=foo;password=4{5') + + test_script('exit(CONST_Database_DSN === "pgsql:dbname=nominatim;user=foo;password=4{5" ? 10 : 20);') + + assert run_website_script() == 10 +