2024-06-09 15:52:20 +03:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2022-01-03 18:23:58 +03:00
|
|
|
#
|
|
|
|
# This file is part of Nominatim. (https://nominatim.org)
|
|
|
|
#
|
2024-06-09 15:52:20 +03:00
|
|
|
# Copyright (C) 2024 by the Nominatim developer community.
|
2022-01-03 18:23:58 +03:00
|
|
|
# For a full list of authors see the git log.
|
2021-02-17 23:43:15 +03:00
|
|
|
"""
|
|
|
|
Tests for freeze functions (removing unused database parts).
|
|
|
|
"""
|
2024-06-09 15:52:20 +03:00
|
|
|
from nominatim_db.tools import freeze
|
2021-02-17 23:43:15 +03:00
|
|
|
|
|
|
|
NOMINATIM_RUNTIME_TABLES = [
|
|
|
|
'country_name', 'country_osm_grid',
|
|
|
|
'location_postcode', 'location_property_osmline', 'location_property_tiger',
|
|
|
|
'placex', 'place_adressline',
|
|
|
|
'search_name',
|
|
|
|
'word'
|
|
|
|
]
|
|
|
|
|
|
|
|
NOMINATIM_DROP_TABLES = [
|
|
|
|
'address_levels',
|
|
|
|
'location_area', 'location_area_country', 'location_area_large_100',
|
|
|
|
'location_road_1',
|
|
|
|
'place', 'planet_osm_nodes', 'planet_osm_rels', 'planet_osm_ways',
|
|
|
|
'search_name_111',
|
|
|
|
'wikipedia_article', 'wikipedia_redirect'
|
|
|
|
]
|
|
|
|
|
2021-05-19 13:11:04 +03:00
|
|
|
def test_drop_tables(temp_db_conn, temp_db_cursor, table_factory):
|
2021-02-17 23:43:15 +03:00
|
|
|
for table in NOMINATIM_RUNTIME_TABLES + NOMINATIM_DROP_TABLES:
|
2021-05-19 13:11:04 +03:00
|
|
|
table_factory(table)
|
2021-02-17 23:43:15 +03:00
|
|
|
|
2023-05-02 19:37:36 +03:00
|
|
|
assert not freeze.is_frozen(temp_db_conn)
|
|
|
|
|
2021-02-17 23:43:15 +03:00
|
|
|
freeze.drop_update_tables(temp_db_conn)
|
|
|
|
|
|
|
|
for table in NOMINATIM_RUNTIME_TABLES:
|
|
|
|
assert temp_db_cursor.table_exists(table)
|
|
|
|
|
|
|
|
for table in NOMINATIM_DROP_TABLES:
|
|
|
|
assert not temp_db_cursor.table_exists(table)
|
|
|
|
|
2023-05-02 19:37:36 +03:00
|
|
|
assert freeze.is_frozen(temp_db_conn)
|
|
|
|
|
2021-02-17 23:43:15 +03:00
|
|
|
def test_drop_flatnode_file_no_file():
|
2022-07-03 19:36:33 +03:00
|
|
|
freeze.drop_flatnode_file(None)
|
2021-02-17 23:43:15 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_drop_flatnode_file_file_already_gone(tmp_path):
|
2022-07-03 19:36:33 +03:00
|
|
|
freeze.drop_flatnode_file(tmp_path / 'something.store')
|
2021-02-17 23:43:15 +03:00
|
|
|
|
|
|
|
|
2023-05-02 19:37:36 +03:00
|
|
|
def test_drop_flatnode_file_delete(tmp_path):
|
2021-02-17 23:43:15 +03:00
|
|
|
flatfile = tmp_path / 'flatnode.store'
|
|
|
|
flatfile.write_text('Some content')
|
|
|
|
|
2022-07-03 19:36:33 +03:00
|
|
|
freeze.drop_flatnode_file(flatfile)
|
2021-02-17 23:43:15 +03:00
|
|
|
|
|
|
|
assert not flatfile.exists()
|