2 Tests for function for importing address ranks.
5 from pathlib import Path
9 from nominatim.tools.refresh import load_address_levels, load_address_levels_from_config
11 def test_load_ranks_def_config(temp_db_conn, temp_db_cursor, def_config):
12 load_address_levels_from_config(temp_db_conn, def_config)
14 assert temp_db_cursor.table_rows('address_levels') > 0
16 def test_load_ranks_from_project_dir(def_config, temp_db_conn, temp_db_cursor,
18 test_file = tmp_path / 'address-levels.json'
19 test_file.write_text('[{"tags":{"place":{"sea":2}}}]')
20 def_config.project_dir = tmp_path
22 load_address_levels_from_config(temp_db_conn, def_config)
24 assert temp_db_cursor.table_rows('address_levels') == 1
27 def test_load_ranks_from_broken_file(def_config, temp_db_conn, tmp_path):
28 test_file = tmp_path / 'address-levels.json'
29 test_file.write_text('[{"tags":"place":{"sea":2}}}]')
30 def_config.project_dir = tmp_path
32 with pytest.raises(json.decoder.JSONDecodeError):
33 load_address_levels_from_config(temp_db_conn, def_config)
36 def test_load_ranks_country(temp_db_conn, temp_db_cursor):
37 load_address_levels(temp_db_conn, 'levels',
38 [{"tags": {"place": {"village": 14}}},
40 "tags": {"place": {"village": 15}}},
41 {"countries": ['uk', 'us'],
42 "tags": {"place": {"village": 16}}}
45 assert temp_db_cursor.row_set('SELECT * FROM levels') == \
46 set([(None, 'place', 'village', 14, 14),
47 ('de', 'place', 'village', 15, 15),
48 ('uk', 'place', 'village', 16, 16),
49 ('us', 'place', 'village', 16, 16),
53 def test_load_ranks_default_value(temp_db_conn, temp_db_cursor):
54 load_address_levels(temp_db_conn, 'levels',
55 [{"tags": {"boundary": {"": 28}}},
57 "tags": {"boundary": {"": 29}}}
60 assert temp_db_cursor.row_set('SELECT * FROM levels') == \
61 set([(None, 'boundary', None, 28, 28),
62 ('hu', 'boundary', None, 29, 29),
66 def test_load_ranks_multiple_keys(temp_db_conn, temp_db_cursor):
67 load_address_levels(temp_db_conn, 'levels',
68 [{"tags": {"place": {"city": 14},
69 "boundary": {"administrative2" : 4}}
72 assert temp_db_cursor.row_set('SELECT * FROM levels') == \
73 set([(None, 'place', 'city', 14, 14),
74 (None, 'boundary', 'administrative2', 4, 4),
78 def test_load_ranks_address(temp_db_conn, temp_db_cursor):
79 load_address_levels(temp_db_conn, 'levels',
80 [{"tags": {"place": {"city": 14,
84 assert temp_db_cursor.row_set('SELECT * FROM levels') == \
85 set([(None, 'place', 'city', 14, 14),
86 (None, 'place', 'town', 14, 13),