]> git.openstreetmap.org Git - nominatim.git/blob - test/python/test_tools_refresh_setup_website.py
US TIGER data 2021 released
[nominatim.git] / test / python / test_tools_refresh_setup_website.py
1 """
2 Tests for setting up the website scripts.
3 """
4 import subprocess
5
6 import pytest
7
8 from nominatim.tools import refresh
9
10 @pytest.fixture
11 def test_script(tmp_path):
12     (tmp_path / 'php').mkdir()
13
14     website_dir = (tmp_path / 'php' / 'website')
15     website_dir.mkdir()
16
17     def _create_file(code):
18         outfile = website_dir / 'reverse-only-search.php'
19         outfile.write_text('<?php\n{}\n'.format(code), 'utf-8')
20
21     return _create_file
22
23
24 @pytest.fixture
25 def run_website_script(tmp_path, def_config, temp_db_conn):
26     def_config.lib_dir.php = tmp_path / 'php'
27     def_config.project_dir = tmp_path
28
29     def _runner():
30         refresh.setup_website(tmp_path, def_config, temp_db_conn)
31
32         proc = subprocess.run(['/usr/bin/env', 'php', '-Cq',
33                                tmp_path / 'search.php'], check=False)
34
35         return proc.returncode
36
37     return _runner
38
39
40 @pytest.mark.parametrize("setting,retval", (('yes', 10), ('no', 20)))
41 def test_setup_website_check_bool(monkeypatch, test_script, run_website_script,
42                                   setting, retval):
43     monkeypatch.setenv('NOMINATIM_CORS_NOACCESSCONTROL', setting)
44
45     test_script('exit(CONST_NoAccessControl ? 10 : 20);')
46
47     assert run_website_script() == retval
48
49
50 @pytest.mark.parametrize("setting", (0, 10, 99067))
51 def test_setup_website_check_int(monkeypatch, test_script, run_website_script, setting):
52     monkeypatch.setenv('NOMINATIM_LOOKUP_MAX_COUNT', str(setting))
53
54     test_script('exit(CONST_Places_Max_ID_count == {} ? 10 : 20);'.format(setting))
55
56     assert run_website_script() == 10
57
58
59 def test_setup_website_check_empty_str(monkeypatch, test_script, run_website_script):
60     monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', '')
61
62     test_script('exit(CONST_Default_Language === false ? 10 : 20);')
63
64     assert run_website_script() == 10
65
66
67 def test_setup_website_check_str(monkeypatch, test_script, run_website_script):
68     monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', 'ffde 2')
69
70     test_script('exit(CONST_Default_Language === "ffde 2" ? 10 : 20);')
71
72     assert run_website_script() == 10