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 refresh.setup_website(envdir, envdir / 'php', config)
30 proc = subprocess.run(['/usr/bin/env', 'php', '-Cq',
31 envdir / 'search.php'], check=False)
33 return proc.returncode
36 @pytest.mark.parametrize("setting,retval", (('yes', 10), ('no', 20)))
37 def test_setup_website_check_bool(def_config, monkeypatch, envdir, test_script,
39 monkeypatch.setenv('NOMINATIM_CORS_NOACCESSCONTROL', setting)
41 test_script('exit(CONST_NoAccessControl ? 10 : 20);')
43 assert run_website_script(envdir, def_config) == retval
46 @pytest.mark.parametrize("setting", (0, 10, 99067))
47 def test_setup_website_check_int(def_config, monkeypatch, envdir, test_script, setting):
48 monkeypatch.setenv('NOMINATIM_LOOKUP_MAX_COUNT', str(setting))
50 test_script('exit(CONST_Places_Max_ID_count == {} ? 10 : 20);'.format(setting))
52 assert run_website_script(envdir, def_config) == 10
55 def test_setup_website_check_empty_str(def_config, monkeypatch, envdir, test_script):
56 monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', '')
58 test_script('exit(CONST_Default_Language === false ? 10 : 20);')
60 assert run_website_script(envdir, def_config) == 10
63 def test_setup_website_check_str(def_config, monkeypatch, envdir, test_script):
64 monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', 'ffde 2')
66 test_script('exit(CONST_Default_Language === "ffde 2" ? 10 : 20);')
68 assert run_website_script(envdir, def_config) == 10