Skip to content

Commit

Permalink
Merge pull request #3499 from mtmail/add-data-warn-if-frozen
Browse files Browse the repository at this point in the history
Add data warn if frozen
  • Loading branch information
lonvia authored Aug 7, 2024
2 parents e104115 + f0390cf commit 738e99c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ ignored-classes=NominatimArgs,closing
disable=too-few-public-methods,duplicate-code,too-many-ancestors,bad-option-value,no-self-use,not-context-manager,use-dict-literal,chained-comparison,attribute-defined-outside-init,too-many-boolean-expressions,contextmanager-generator-missing-cleanup

good-names=i,j,x,y,m,t,fd,db,cc,x1,x2,y1,y2,pt,k,v,nr

[DESIGN]

max-returns=7
2 changes: 1 addition & 1 deletion docs/admin/Advanced-Installations.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,6 @@ If you are using the legacy tokenizer you might also have to switch to the
PostgreSQL module that was compiled on your target machine. If you get errors
that PostgreSQL cannot find or access `nominatim.so` then rerun

nominatim refresh --functions
nominatim refresh --functions

on the target machine to update the the location of the module.
9 changes: 8 additions & 1 deletion src/nominatim_db/clicmd/add_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import psutil

from .args import NominatimArgs
from ..db.connection import connect
from ..tools.freeze import is_frozen

# Do not repeat documentation of subcommand classes.
# pylint: disable=C0111
Expand All @@ -36,7 +38,7 @@ class UpdateAddData:
The command can also be used to add external non-OSM data to the
database. At the moment the only supported format is TIGER housenumber
data. See the online documentation at
https://nominatim.org/release-docs/latest/admin/Import/#installing-tiger-housenumber-data-for-the-us
https://nominatim.org/release-docs/latest/customize/Tiger/
for more information.
"""

Expand Down Expand Up @@ -67,6 +69,11 @@ def add_args(self, parser: argparse.ArgumentParser) -> None:
def run(self, args: NominatimArgs) -> int:
from ..tools import add_osm_data

with connect(args.config.get_libpq_dsn()) as conn:
if is_frozen(conn):
print('Database is marked frozen. New data can\'t be added.')
return 1

if args.tiger_data:
return asyncio.run(self._add_tiger_data(args))

Expand Down
48 changes: 25 additions & 23 deletions test/python/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,49 @@ def test_cli_version(cli_call, capsys):
captured = capsys.readouterr()
assert captured.out.startswith('Nominatim version')

@pytest.mark.parametrize("name,oid", [('file', 'foo.osm'), ('diff', 'foo.osc')])
def test_cli_add_data_file_command(cli_call, mock_func_factory, name, oid):
mock_run_legacy = mock_func_factory(nominatim_db.tools.add_osm_data, 'add_data_from_file')
assert cli_call('add-data', '--' + name, str(oid)) == 0

assert mock_run_legacy.called == 1
def test_cli_serve_php(cli_call, mock_func_factory):
func = mock_func_factory(nominatim_db.cli, 'run_php_server')

cli_call('serve', '--engine', 'php') == 0

@pytest.mark.parametrize("name,oid", [('node', 12), ('way', 8), ('relation', 32)])
def test_cli_add_data_object_command(cli_call, mock_func_factory, name, oid):
mock_run_legacy = mock_func_factory(nominatim_db.tools.add_osm_data, 'add_osm_object')
assert cli_call('add-data', '--' + name, str(oid)) == 0
assert func.called == 1

assert mock_run_legacy.called == 1


class TestCliWithDb:

def test_cli_add_data_tiger_data(cli_call, cli_tokenizer_mock, async_mock_func_factory):
mock = async_mock_func_factory(nominatim_db.tools.tiger_data, 'add_tiger_data')
@pytest.fixture(autouse=True)
def setup_cli_call(self, cli_call, temp_db, cli_tokenizer_mock, table_factory):
self.call_nominatim = cli_call
self.tokenizer_mock = cli_tokenizer_mock
# Make sure tools.freeze.is_frozen doesn't report database as frozen. Monkeypatching failed
table_factory('place')

assert cli_call('add-data', '--tiger-data', 'somewhere') == 0

assert mock.called == 1
@pytest.mark.parametrize("name,oid", [('file', 'foo.osm'), ('diff', 'foo.osc')])
def test_cli_add_data_file_command(self, cli_call, mock_func_factory, name, oid):
mock_run_legacy = mock_func_factory(nominatim_db.tools.add_osm_data, 'add_data_from_file')
assert cli_call('add-data', '--' + name, str(oid)) == 0

assert mock_run_legacy.called == 1

def test_cli_serve_php(cli_call, mock_func_factory):
func = mock_func_factory(nominatim_db.cli, 'run_php_server')

cli_call('serve', '--engine', 'php') == 0
@pytest.mark.parametrize("name,oid", [('node', 12), ('way', 8), ('relation', 32)])
def test_cli_add_data_object_command(self, cli_call, mock_func_factory, name, oid):
mock_run_legacy = mock_func_factory(nominatim_db.tools.add_osm_data, 'add_osm_object')
assert cli_call('add-data', '--' + name, str(oid)) == 0

assert func.called == 1
assert mock_run_legacy.called == 1



class TestCliWithDb:
def test_cli_add_data_tiger_data(self, cli_call, cli_tokenizer_mock, async_mock_func_factory):
mock = async_mock_func_factory(nominatim_db.tools.tiger_data, 'add_tiger_data')

@pytest.fixture(autouse=True)
def setup_cli_call(self, cli_call, temp_db, cli_tokenizer_mock):
self.call_nominatim = cli_call
self.tokenizer_mock = cli_tokenizer_mock
assert cli_call('add-data', '--tiger-data', 'somewhere') == 0

assert mock.called == 1

def test_freeze_command(self, mock_func_factory):
mock_drop = mock_func_factory(nominatim_db.tools.freeze, 'drop_update_tables')
Expand Down

0 comments on commit 738e99c

Please sign in to comment.