2 Tests for setting up the website scripts.
4 from pathlib import Path
9 from nominatim.tools import refresh
13 (tmpdir / 'php').mkdir()
14 (tmpdir / 'php' / 'website').mkdir()
19 def test_script(envdir):
20 def _create_file(code):
21 outfile = envdir / 'php' / 'website' / 'reverse-only-search.php'
22 outfile.write_text('<?php\n{}\n'.format(code), 'utf-8')
27 def run_website_script(envdir, config, conn):
28 config.lib_dir.php = envdir / 'php'
29 config.project_dir = envdir
30 refresh.setup_website(envdir, config, conn)
32 proc = subprocess.run(['/usr/bin/env', 'php', '-Cq',
33 envdir / 'search.php'], check=False)
35 return proc.returncode
38 @pytest.mark.parametrize("setting,retval", (('yes', 10), ('no', 20)))
39 def test_setup_website_check_bool(def_config, monkeypatch, envdir, test_script,
40 setting, retval, temp_db_conn):
41 monkeypatch.setenv('NOMINATIM_CORS_NOACCESSCONTROL', setting)
43 test_script('exit(CONST_NoAccessControl ? 10 : 20);')
45 assert run_website_script(envdir, def_config, temp_db_conn) == retval
48 @pytest.mark.parametrize("setting", (0, 10, 99067))
49 def test_setup_website_check_int(def_config, monkeypatch, envdir, test_script, setting,
51 monkeypatch.setenv('NOMINATIM_LOOKUP_MAX_COUNT', str(setting))
53 test_script('exit(CONST_Places_Max_ID_count == {} ? 10 : 20);'.format(setting))
55 assert run_website_script(envdir, def_config, temp_db_conn) == 10
58 def test_setup_website_check_empty_str(def_config, monkeypatch, envdir, test_script,
60 monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', '')
62 test_script('exit(CONST_Default_Language === false ? 10 : 20);')
64 assert run_website_script(envdir, def_config, temp_db_conn) == 10
67 def test_setup_website_check_str(def_config, monkeypatch, envdir, test_script,
69 monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', 'ffde 2')
71 test_script('exit(CONST_Default_Language === "ffde 2" ? 10 : 20);')
73 assert run_website_script(envdir, def_config, temp_db_conn) == 10