2 Tests for setting up the website scripts.
8 from nominatim.tools import refresh
11 def test_script(tmp_path):
12 (tmp_path / 'php').mkdir()
14 website_dir = (tmp_path / 'php' / 'website')
17 def _create_file(code):
18 outfile = website_dir / 'reverse-only-search.php'
19 outfile.write_text('<?php\n{}\n'.format(code), 'utf-8')
25 def run_website_script(tmp_path, project_env, temp_db_conn):
26 project_env.lib_dir.php = tmp_path / 'php'
29 refresh.setup_website(tmp_path, project_env, temp_db_conn)
31 proc = subprocess.run(['/usr/bin/env', 'php', '-Cq',
32 tmp_path / 'search.php'], check=False)
34 return proc.returncode
39 @pytest.mark.parametrize("setting,retval", (('yes', 10), ('no', 20)))
40 def test_setup_website_check_bool(monkeypatch, test_script, run_website_script,
42 monkeypatch.setenv('NOMINATIM_CORS_NOACCESSCONTROL', setting)
44 test_script('exit(CONST_NoAccessControl ? 10 : 20);')
46 assert run_website_script() == retval
49 @pytest.mark.parametrize("setting", (0, 10, 99067))
50 def test_setup_website_check_int(monkeypatch, test_script, run_website_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() == 10
58 def test_setup_website_check_empty_str(monkeypatch, test_script, run_website_script):
59 monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', '')
61 test_script('exit(CONST_Default_Language === false ? 10 : 20);')
63 assert run_website_script() == 10
66 def test_setup_website_check_str(monkeypatch, test_script, run_website_script):
67 monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', 'ffde 2')
69 test_script('exit(CONST_Default_Language === "ffde 2" ? 10 : 20);')
71 assert run_website_script() == 10