]> git.openstreetmap.org Git - nominatim.git/blob - test/python/api/test_export.py
get bbox of postcode areas into results
[nominatim.git] / test / python / api / test_export.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2024 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for export CLI function.
9 """
10 import pytest
11
12 import nominatim_db.cli
13
14 @pytest.fixture
15 def run_export(tmp_path, capsys):
16     def _exec(args):
17         assert 0 == nominatim_db.cli.nominatim(osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
18                                                cli_args=['export', '--project-dir', str(tmp_path)]
19                                                         + args)
20         return capsys.readouterr().out.split('\r\n')
21
22     return _exec
23
24
25 @pytest.fixture(autouse=True)
26 def setup_database_with_context(apiobj):
27     apiobj.add_placex(place_id=332, osm_type='W', osm_id=4,
28                      class_='highway', type='residential',  name='Street',
29                      country_code='pl', postcode='55674',
30                      rank_search=27, rank_address=26)
31     apiobj.add_address_placex(332, fromarea=False, isaddress=False,
32                               distance=0.0034,
33                               place_id=1000, osm_type='N', osm_id=3333,
34                               class_='place', type='suburb', name='Smallplace',
35                               country_code='pl', admin_level=13,
36                               rank_search=24, rank_address=23)
37     apiobj.add_address_placex(332, fromarea=True, isaddress=True,
38                               place_id=1001, osm_type='N', osm_id=3334,
39                               class_='place', type='city', name='Bigplace',
40                               country_code='pl',
41                               rank_search=17, rank_address=16)
42
43
44 def test_export_default(run_export):
45     csv = run_export([])
46
47     assert csv == ['street,suburb,city,county,state,country', 'Street,,Bigplace,,,', '']
48
49
50 def test_export_output_type(run_export):
51     csv = run_export(['--output-type', 'city'])
52
53     assert csv == ['street,suburb,city,county,state,country', ',,Bigplace,,,', '']
54
55
56 def test_export_output_format(run_export):
57     csv = run_export(['--output-format', 'placeid;street;nothing;postcode'])
58
59     assert csv == ['placeid,street,nothing,postcode', '332,Street,,55674', '']
60
61
62 def test_export_restrict_to_node_good(run_export):
63     csv = run_export(['--restrict-to-osm-node', '3334'])
64
65     assert csv == ['street,suburb,city,county,state,country', 'Street,,Bigplace,,,', '']
66
67
68 def test_export_restrict_to_node_not_address(run_export):
69     csv = run_export(['--restrict-to-osm-node', '3333'])
70
71     assert csv == ['street,suburb,city,county,state,country', '']