1 # SPDX-License-Identifier: GPL-3.0-or-later
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2023 by the Nominatim developer community.
 
   6 # For a full list of authors see the git log.
 
   8 Tests for export CLI function.
 
  15 def run_export(tmp_path, capsys):
 
  17         assert 0 == nominatim.cli.nominatim(module_dir='MODULE NOT AVAILABLE',
 
  18                                             osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
 
  19                                             cli_args=['export', '--project-dir', str(tmp_path)]
 
  21         return capsys.readouterr().out.split('\r\n')
 
  26 @pytest.fixture(autouse=True)
 
  27 def setup_database_with_context(apiobj):
 
  28     apiobj.add_placex(place_id=332, osm_type='W', osm_id=4,
 
  29                      class_='highway', type='residential',  name='Street',
 
  30                      country_code='pl', postcode='55674',
 
  31                      rank_search=27, rank_address=26)
 
  32     apiobj.add_address_placex(332, fromarea=False, isaddress=False,
 
  34                               place_id=1000, osm_type='N', osm_id=3333,
 
  35                               class_='place', type='suburb', name='Smallplace',
 
  36                               country_code='pl', admin_level=13,
 
  37                               rank_search=24, rank_address=23)
 
  38     apiobj.add_address_placex(332, fromarea=True, isaddress=True,
 
  39                               place_id=1001, osm_type='N', osm_id=3334,
 
  40                               class_='place', type='city', name='Bigplace',
 
  42                               rank_search=17, rank_address=16)
 
  45 def test_export_default(run_export):
 
  48     assert csv == ['street,suburb,city,county,state,country', 'Street,,Bigplace,,,', '']
 
  51 def test_export_output_type(run_export):
 
  52     csv = run_export(['--output-type', 'city'])
 
  54     assert csv == ['street,suburb,city,county,state,country', ',,Bigplace,,,', '']
 
  57 def test_export_output_format(run_export):
 
  58     csv = run_export(['--output-format', 'placeid;street;nothing;postcode'])
 
  60     assert csv == ['placeid,street,nothing,postcode', '332,Street,,55674', '']
 
  63 def test_export_restrict_to_node_good(run_export):
 
  64     csv = run_export(['--restrict-to-osm-node', '3334'])
 
  66     assert csv == ['street,suburb,city,county,state,country', 'Street,,Bigplace,,,', '']
 
  69 def test_export_restrict_to_node_not_address(run_export):
 
  70     csv = run_export(['--restrict-to-osm-node', '3333'])
 
  72     assert csv == ['street,suburb,city,county,state,country', '']