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' / 'search.php'
22 outfile.write_text('<?php\n{}\n'.format(code), 'utf-8')
27 def run_website_script(envdir, config):
28 config.lib_dir.php = envdir / 'php'
29 refresh.setup_website(envdir, config)
31 proc = subprocess.run(['/usr/bin/env', 'php', '-Cq',
32 envdir / 'search.php'], check=False)
34 return proc.returncode
37 @pytest.mark.parametrize("setting,retval", (('yes', 10), ('no', 20)))
38 def test_setup_website_check_bool(def_config, monkeypatch, envdir, test_script,
40 monkeypatch.setenv('NOMINATIM_CORS_NOACCESSCONTROL', setting)
42 test_script('exit(CONST_NoAccessControl ? 10 : 20);')
44 assert run_website_script(envdir, def_config) == retval
47 @pytest.mark.parametrize("setting", (0, 10, 99067))
48 def test_setup_website_check_int(def_config, monkeypatch, envdir, test_script, setting):
49 monkeypatch.setenv('NOMINATIM_LOOKUP_MAX_COUNT', str(setting))
51 test_script('exit(CONST_Places_Max_ID_count == {} ? 10 : 20);'.format(setting))
53 assert run_website_script(envdir, def_config) == 10
56 def test_setup_website_check_empty_str(def_config, monkeypatch, envdir, test_script):
57 monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', '')
59 test_script('exit(CONST_Default_Language === false ? 10 : 20);')
61 assert run_website_script(envdir, def_config) == 10
64 def test_setup_website_check_str(def_config, monkeypatch, envdir, test_script):
65 monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', 'ffde 2')
67 test_script('exit(CONST_Default_Language === "ffde 2" ? 10 : 20);')
69 assert run_website_script(envdir, def_config) == 10