1 # SPDX-License-Identifier: GPL-2.0-only
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2022 by the Nominatim developer community.
 
   6 # For a full list of authors see the git log.
 
   8 Tests for freeze functions (removing unused database parts).
 
  10 from nominatim.tools import freeze
 
  12 NOMINATIM_RUNTIME_TABLES = [
 
  13     'country_name', 'country_osm_grid',
 
  14     'location_postcode', 'location_property_osmline', 'location_property_tiger',
 
  15     'placex', 'place_adressline',
 
  20 NOMINATIM_DROP_TABLES = [
 
  22     'location_area', 'location_area_country', 'location_area_large_100',
 
  25     'place', 'planet_osm_nodes', 'planet_osm_rels', 'planet_osm_ways',
 
  27     'wikipedia_article', 'wikipedia_redirect'
 
  30 def test_drop_tables(temp_db_conn, temp_db_cursor, table_factory):
 
  31     for table in NOMINATIM_RUNTIME_TABLES + NOMINATIM_DROP_TABLES:
 
  34     freeze.drop_update_tables(temp_db_conn)
 
  36     for table in NOMINATIM_RUNTIME_TABLES:
 
  37         assert temp_db_cursor.table_exists(table)
 
  39     for table in NOMINATIM_DROP_TABLES:
 
  40         assert not temp_db_cursor.table_exists(table)
 
  42 def test_drop_flatnode_file_no_file():
 
  43     freeze.drop_flatnode_file(None)
 
  46 def test_drop_flatnode_file_file_already_gone(tmp_path):
 
  47     freeze.drop_flatnode_file(tmp_path / 'something.store')
 
  50 def test_drop_flatnode_file_delte(tmp_path):
 
  51     flatfile = tmp_path / 'flatnode.store'
 
  52     flatfile.write_text('Some content')
 
  54     freeze.drop_flatnode_file(flatfile)
 
  56     assert not flatfile.exists()