2 Tests for function for importing address ranks.
6 from pathlib import Path
8 from nominatim.tools.refresh import load_address_levels, load_address_levels_from_file
10 def test_load_ranks_def_config(temp_db_conn, temp_db_cursor, def_config):
11 load_address_levels_from_file(temp_db_conn, Path(def_config.ADDRESS_LEVEL_CONFIG))
13 assert temp_db_cursor.scalar('SELECT count(*) FROM address_levels') > 0
15 def test_load_ranks_from_file(temp_db_conn, temp_db_cursor, tmp_path):
16 test_file = tmp_path / 'test_levels.json'
17 test_file.write_text('[{"tags":{"place":{"sea":2}}}]')
19 load_address_levels_from_file(temp_db_conn, test_file)
21 assert temp_db_cursor.scalar('SELECT count(*) FROM address_levels') > 0
24 def test_load_ranks_from_broken_file(temp_db_conn, tmp_path):
25 test_file = tmp_path / 'test_levels.json'
26 test_file.write_text('[{"tags":"place":{"sea":2}}}]')
28 with pytest.raises(json.decoder.JSONDecodeError):
29 load_address_levels_from_file(temp_db_conn, test_file)
32 def test_load_ranks_country(temp_db_conn, temp_db_cursor):
33 load_address_levels(temp_db_conn, 'levels',
34 [{"tags": {"place": {"village": 14}}},
36 "tags": {"place": {"village": 15}}},
37 {"countries": ['uk', 'us' ],
38 "tags": {"place": {"village": 16}}}
41 assert temp_db_cursor.row_set('SELECT * FROM levels') == \
42 set([(None, 'place', 'village', 14, 14),
43 ('de', 'place', 'village', 15, 15),
44 ('uk', 'place', 'village', 16, 16),
45 ('us', 'place', 'village', 16, 16),
49 def test_load_ranks_default_value(temp_db_conn, temp_db_cursor):
50 load_address_levels(temp_db_conn, 'levels',
51 [{"tags": {"boundary": {"": 28}}},
53 "tags": {"boundary": {"": 29}}}
56 assert temp_db_cursor.row_set('SELECT * FROM levels') == \
57 set([(None, 'boundary', None, 28, 28),
58 ('hu', 'boundary', None, 29, 29),
62 def test_load_ranks_multiple_keys(temp_db_conn, temp_db_cursor):
63 load_address_levels(temp_db_conn, 'levels',
65 {"place": {"city": 14},
66 "boundary": {"administrative2" : 4}}
69 assert temp_db_cursor.row_set('SELECT * FROM levels') == \
70 set([(None, 'place', 'city', 14, 14),
71 (None, 'boundary', 'administrative2', 4, 4),
75 def test_load_ranks_address(temp_db_conn, temp_db_cursor):
76 load_address_levels(temp_db_conn, 'levels',
78 {"place": {"city": 14,
82 assert temp_db_cursor.row_set('SELECT * FROM levels') == \
83 set([(None, 'place', 'city', 14, 14),
84 (None, 'place', 'town', 14, 13),