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     config.project_dir = envdir
 
  30     refresh.setup_website(envdir, config)
 
  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,
 
  41     monkeypatch.setenv('NOMINATIM_CORS_NOACCESSCONTROL', setting)
 
  43     test_script('exit(CONST_NoAccessControl ? 10 : 20);')
 
  45     assert run_website_script(envdir, def_config) == retval
 
  48 @pytest.mark.parametrize("setting", (0, 10, 99067))
 
  49 def test_setup_website_check_int(def_config, monkeypatch, envdir, test_script, setting):
 
  50     monkeypatch.setenv('NOMINATIM_LOOKUP_MAX_COUNT', str(setting))
 
  52     test_script('exit(CONST_Places_Max_ID_count == {} ? 10 : 20);'.format(setting))
 
  54     assert run_website_script(envdir, def_config) == 10
 
  57 def test_setup_website_check_empty_str(def_config, monkeypatch, envdir, test_script):
 
  58     monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', '')
 
  60     test_script('exit(CONST_Default_Language === false ? 10 : 20);')
 
  62     assert run_website_script(envdir, def_config) == 10
 
  65 def test_setup_website_check_str(def_config, monkeypatch, envdir, test_script):
 
  66     monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', 'ffde 2')
 
  68     test_script('exit(CONST_Default_Language === "ffde 2" ? 10 : 20);')
 
  70     assert run_website_script(envdir, def_config) == 10