]> git.openstreetmap.org Git - nominatim.git/blob - test/python/test_tools_freeze.py
Clean and update tests for postcodes
[nominatim.git] / test / python / test_tools_freeze.py
1 """
2 Tests for freeze functions (removing unused database parts).
3 """
4 from nominatim.tools import freeze
5
6 NOMINATIM_RUNTIME_TABLES = [
7     'country_name', 'country_osm_grid',
8     'location_postcode', 'location_property_osmline', 'location_property_tiger',
9     'placex', 'place_adressline',
10     'search_name',
11     'word'
12 ]
13
14 NOMINATIM_DROP_TABLES = [
15     'address_levels',
16     'location_area', 'location_area_country', 'location_area_large_100',
17     'location_road_1',
18     'place', 'planet_osm_nodes', 'planet_osm_rels', 'planet_osm_ways',
19     'search_name_111',
20     'wikipedia_article', 'wikipedia_redirect'
21 ]
22
23 def test_drop_tables(temp_db_conn, temp_db_cursor, table_factory):
24     for table in NOMINATIM_RUNTIME_TABLES + NOMINATIM_DROP_TABLES:
25         table_factory(table)
26
27     freeze.drop_update_tables(temp_db_conn)
28
29     for table in NOMINATIM_RUNTIME_TABLES:
30         assert temp_db_cursor.table_exists(table)
31
32     for table in NOMINATIM_DROP_TABLES:
33         assert not temp_db_cursor.table_exists(table)
34
35 def test_drop_flatnode_file_no_file():
36     freeze.drop_flatnode_file('')
37
38
39 def test_drop_flatnode_file_file_already_gone(tmp_path):
40     freeze.drop_flatnode_file(str(tmp_path / 'something.store'))
41
42
43 def test_drop_flatnode_file_delte(tmp_path):
44     flatfile = tmp_path / 'flatnode.store'
45     flatfile.write_text('Some content')
46
47     freeze.drop_flatnode_file(str(flatfile))
48
49     assert not flatfile.exists()