2 Tests for command line interface wrapper.
8 def call_nominatim(*args):
9 return nominatim.cli.nominatim(module_dir='build/module',
10 osm2pgsql_path='build/osm2pgsql/osm2pgsql',
13 phpcgi_path='/usr/bin/php-cgi',
16 class MockParamCapture:
17 """ Mock that records the parameters with which a function was called
18 as well as the number of calls.
24 def __call__(self, *args, **kwargs):
27 self.last_kwargs = kwargs
28 return self.return_value
31 def mock_run_legacy(monkeypatch):
32 mock = MockParamCapture()
33 monkeypatch.setattr(nominatim.cli, 'run_legacy_script', mock)
37 def mock_run_api(monkeypatch):
38 mock = MockParamCapture()
39 monkeypatch.setattr(nominatim.cli, 'run_api_script', mock)
43 def test_cli_help(capsys):
44 """ Running nominatim tool without arguments prints help.
46 assert 1 == call_nominatim()
48 captured = capsys.readouterr()
49 assert captured.out.startswith('usage:')
51 @pytest.mark.parametrize("command,script", [
52 (('import', '--continue', 'load-data'), 'setup'),
53 (('freeze',), 'setup'),
54 (('special-phrases',), 'specialphrases'),
55 (('replication',), 'update'),
56 (('add-data', '--tiger-data', 'tiger'), 'setup'),
57 (('add-data', '--file', 'foo.osm'), 'update'),
58 (('check-database',), 'check_import_finished'),
60 (('export',), 'export')
62 def test_legacy_commands_simple(mock_run_legacy, command, script):
63 assert 0 == call_nominatim(*command)
65 assert mock_run_legacy.called == 1
66 assert mock_run_legacy.last_args[0] == script + '.php'
68 @pytest.mark.parametrize("params", [
69 ('search', '--query', 'new'),
70 ('reverse', '--lat', '0', '--lon', '0'),
71 ('lookup', '--id', 'N1'),
72 ('details', '--node', '1'),
73 ('details', '--way', '1'),
74 ('details', '--relation', '1'),
75 ('details', '--place_id', '10001'),
78 def test_api_commands_simple(mock_run_api, params):
79 assert 0 == call_nominatim(*params)
81 assert mock_run_api.called == 1
82 assert mock_run_api.last_args[0] == params[0]