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_file
11 def test_load_ranks_def_config(temp_db_conn, temp_db_cursor, def_config):
12 load_address_levels_from_file(temp_db_conn, Path(def_config.ADDRESS_LEVEL_CONFIG))
14 assert temp_db_cursor.scalar('SELECT count(*) FROM address_levels') > 0
16 def test_load_ranks_from_file(temp_db_conn, temp_db_cursor, tmp_path):
17 test_file = tmp_path / 'test_levels.json'
18 test_file.write_text('[{"tags":{"place":{"sea":2}}}]')
20 load_address_levels_from_file(temp_db_conn, test_file)
22 assert temp_db_cursor.scalar('SELECT count(*) FROM address_levels') > 0
25 def test_load_ranks_from_broken_file(temp_db_conn, tmp_path):
26 test_file = tmp_path / 'test_levels.json'
27 test_file.write_text('[{"tags":"place":{"sea":2}}}]')
29 with pytest.raises(json.decoder.JSONDecodeError):
30 load_address_levels_from_file(temp_db_conn, test_file)
33 def test_load_ranks_country(temp_db_conn, temp_db_cursor):
34 load_address_levels(temp_db_conn, 'levels',
35 [{"tags": {"place": {"village": 14}}},
37 "tags": {"place": {"village": 15}}},
38 {"countries": ['uk', 'us' ],
39 "tags": {"place": {"village": 16}}}
42 assert temp_db_cursor.row_set('SELECT * FROM levels') == \
43 set([(None, 'place', 'village', 14, 14),
44 ('de', 'place', 'village', 15, 15),
45 ('uk', 'place', 'village', 16, 16),
46 ('us', 'place', 'village', 16, 16),
50 def test_load_ranks_default_value(temp_db_conn, temp_db_cursor):
51 load_address_levels(temp_db_conn, 'levels',
52 [{"tags": {"boundary": {"": 28}}},
54 "tags": {"boundary": {"": 29}}}
57 assert temp_db_cursor.row_set('SELECT * FROM levels') == \
58 set([(None, 'boundary', None, 28, 28),
59 ('hu', 'boundary', None, 29, 29),
63 def test_load_ranks_multiple_keys(temp_db_conn, temp_db_cursor):
64 load_address_levels(temp_db_conn, 'levels',
66 {"place": {"city": 14},
67 "boundary": {"administrative2" : 4}}
70 assert temp_db_cursor.row_set('SELECT * FROM levels') == \
71 set([(None, 'place', 'city', 14, 14),
72 (None, 'boundary', 'administrative2', 4, 4),
76 def test_load_ranks_address(temp_db_conn, temp_db_cursor):
77 load_address_levels(temp_db_conn, 'levels',
79 {"place": {"city": 14,
83 assert temp_db_cursor.row_set('SELECT * FROM levels') == \
84 set([(None, 'place', 'city', 14, 14),
85 (None, 'place', 'town', 14, 13),