mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-14 18:37:58 +00:00
feat: Added reverse-only-search validation
This commit is contained in:
@@ -9,6 +9,7 @@ sys.path.insert(1, str((Path(__file__) / '..' / '..' / '..' / '..').resolve()))
|
||||
|
||||
from nominatim import cli
|
||||
from nominatim.config import Configuration
|
||||
from nominatim.db.connection import _Connection
|
||||
from nominatim.tools import refresh
|
||||
from nominatim.tokenizer import factory as tokenizer_factory
|
||||
from steps.utils import run_script
|
||||
@@ -54,7 +55,7 @@ class NominatimEnvironment:
|
||||
dbargs['user'] = self.db_user
|
||||
if self.db_pass:
|
||||
dbargs['password'] = self.db_pass
|
||||
conn = psycopg2.connect(**dbargs)
|
||||
conn = psycopg2.connect(connection_factory=_Connection, **dbargs)
|
||||
return conn
|
||||
|
||||
def next_code_coverage_file(self):
|
||||
@@ -110,8 +111,13 @@ class NominatimEnvironment:
|
||||
self.website_dir.cleanup()
|
||||
|
||||
self.website_dir = tempfile.TemporaryDirectory()
|
||||
|
||||
try:
|
||||
conn = self.connect_database(dbname)
|
||||
except:
|
||||
conn = False
|
||||
refresh.setup_website(Path(self.website_dir.name) / 'website',
|
||||
self.get_test_config())
|
||||
self.get_test_config(), conn)
|
||||
|
||||
|
||||
def get_test_config(self):
|
||||
@@ -231,13 +237,13 @@ class NominatimEnvironment:
|
||||
""" Setup a test against a fresh, empty test database.
|
||||
"""
|
||||
self.setup_template_db()
|
||||
self.write_nominatim_config(self.test_db)
|
||||
conn = self.connect_database(self.template_db)
|
||||
conn.set_isolation_level(0)
|
||||
cur = conn.cursor()
|
||||
cur.execute('DROP DATABASE IF EXISTS {}'.format(self.test_db))
|
||||
cur.execute('CREATE DATABASE {} TEMPLATE = {}'.format(self.test_db, self.template_db))
|
||||
conn.close()
|
||||
self.write_nominatim_config(self.test_db)
|
||||
context.db = self.connect_database(self.test_db)
|
||||
context.db.autocommit = True
|
||||
psycopg2.extras.register_hstore(context.db, globally=False)
|
||||
|
||||
@@ -18,16 +18,16 @@ def envdir(tmpdir):
|
||||
@pytest.fixture
|
||||
def test_script(envdir):
|
||||
def _create_file(code):
|
||||
outfile = envdir / 'php' / 'website' / 'search.php'
|
||||
outfile = envdir / 'php' / 'website' / 'reverse-only-search.php'
|
||||
outfile.write_text('<?php\n{}\n'.format(code), 'utf-8')
|
||||
|
||||
return _create_file
|
||||
|
||||
|
||||
def run_website_script(envdir, config):
|
||||
def run_website_script(envdir, config, conn):
|
||||
config.lib_dir.php = envdir / 'php'
|
||||
config.project_dir = envdir
|
||||
refresh.setup_website(envdir, config)
|
||||
refresh.setup_website(envdir, config, conn)
|
||||
|
||||
proc = subprocess.run(['/usr/bin/env', 'php', '-Cq',
|
||||
envdir / 'search.php'], check=False)
|
||||
@@ -37,36 +37,39 @@ def run_website_script(envdir, config):
|
||||
|
||||
@pytest.mark.parametrize("setting,retval", (('yes', 10), ('no', 20)))
|
||||
def test_setup_website_check_bool(def_config, monkeypatch, envdir, test_script,
|
||||
setting, retval):
|
||||
setting, retval, temp_db_conn):
|
||||
monkeypatch.setenv('NOMINATIM_CORS_NOACCESSCONTROL', setting)
|
||||
|
||||
test_script('exit(CONST_NoAccessControl ? 10 : 20);')
|
||||
|
||||
assert run_website_script(envdir, def_config) == retval
|
||||
assert run_website_script(envdir, def_config, temp_db_conn) == retval
|
||||
|
||||
|
||||
@pytest.mark.parametrize("setting", (0, 10, 99067))
|
||||
def test_setup_website_check_int(def_config, monkeypatch, envdir, test_script, setting):
|
||||
def test_setup_website_check_int(def_config, monkeypatch, envdir, test_script, setting,
|
||||
temp_db_conn):
|
||||
monkeypatch.setenv('NOMINATIM_LOOKUP_MAX_COUNT', str(setting))
|
||||
|
||||
test_script('exit(CONST_Places_Max_ID_count == {} ? 10 : 20);'.format(setting))
|
||||
|
||||
assert run_website_script(envdir, def_config) == 10
|
||||
assert run_website_script(envdir, def_config, temp_db_conn) == 10
|
||||
|
||||
|
||||
def test_setup_website_check_empty_str(def_config, monkeypatch, envdir, test_script):
|
||||
def test_setup_website_check_empty_str(def_config, monkeypatch, envdir, test_script,
|
||||
temp_db_conn):
|
||||
monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', '')
|
||||
|
||||
test_script('exit(CONST_Default_Language === false ? 10 : 20);')
|
||||
|
||||
assert run_website_script(envdir, def_config) == 10
|
||||
assert run_website_script(envdir, def_config, temp_db_conn) == 10
|
||||
|
||||
|
||||
def test_setup_website_check_str(def_config, monkeypatch, envdir, test_script):
|
||||
def test_setup_website_check_str(def_config, monkeypatch, envdir, test_script,
|
||||
temp_db_conn):
|
||||
monkeypatch.setenv('NOMINATIM_DEFAULT_LANGUAGE', 'ffde 2')
|
||||
|
||||
test_script('exit(CONST_Default_Language === "ffde 2" ? 10 : 20);')
|
||||
|
||||
assert run_website_script(envdir, def_config) == 10
|
||||
assert run_website_script(envdir, def_config, temp_db_conn) == 10
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user