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(project_env, temp_db_conn, temp_db_cursor):
17 test_file = project_env.project_dir / 'address-levels.json'
18 test_file.write_text('[{"tags":{"place":{"sea":2}}}]')
20 load_address_levels_from_config(temp_db_conn, project_env)
22 assert temp_db_cursor.table_rows('address_levels') == 1
25 def test_load_ranks_from_broken_file(project_env, temp_db_conn):
26 test_file = project_env.project_dir / 'address-levels.json'
27 test_file.write_text('[{"tags":"place":{"sea":2}}}]')
29 with pytest.raises(json.decoder.JSONDecodeError):
30 load_address_levels_from_config(temp_db_conn, project_env)
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',
65 [{"tags": {"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',
77 [{"tags": {"place": {"city": 14,
81 assert temp_db_cursor.row_set('SELECT * FROM levels') == \
82 set([(None, 'place', 'city', 14, 14),
83 (None, 'place', 'town', 14, 13),