Ported createCountryNames() to python and added tests

This commit is contained in:
Darkshredder
2021-03-12 10:28:41 +05:30
parent 9086a794a1
commit 7a874d5b97
6 changed files with 69 additions and 30 deletions

View File

@@ -95,6 +95,7 @@ def test_import_full(temp_db, mock_func_factory):
mock_func_factory(nominatim.tools.database_import, 'create_table_triggers'),
mock_func_factory(nominatim.tools.database_import, 'create_partition_tables'),
mock_func_factory(nominatim.tools.database_import, 'create_search_indices'),
mock_func_factory(nominatim.tools.database_import, 'create_country_names'),
mock_func_factory(nominatim.tools.refresh, 'load_address_levels_from_file'),
mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_full'),
mock_func_factory(nominatim.tools.refresh, 'setup_website'),

View File

@@ -200,3 +200,26 @@ def test_load_data(dsn, src_dir, place_row, placex_table, osmline_table, word_ta
assert temp_db_cursor.table_rows('placex') == 30
assert temp_db_cursor.table_rows('location_property_osmline') == 1
@pytest.mark.parametrize("languages", (False, True))
def test_create_country_names(temp_db_conn, temp_db_cursor, def_config,
temp_db_with_extensions, monkeypatch, languages):
if languages:
monkeypatch.setenv('NOMINATIM_LANGUAGES', 'fr,en')
temp_db_cursor.execute("""CREATE FUNCTION make_standard_name (name TEXT)
RETURNS TEXT AS $$ SELECT 'a'::TEXT $$ LANGUAGE SQL
""")
temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION getorcreate_country(lookup_word TEXT,
lookup_country_code varchar(2))
RETURNS INTEGER
AS $$
BEGIN
INSERT INTO country_name VALUES (5, lookup_word);
RETURN 5;
END;
$$
LANGUAGE plpgsql;
""")
temp_db_cursor.execute('CREATE TABLE country_name (id int, country_code varchar(2), name hstore)')
database_import.create_country_names(temp_db_conn, def_config)
assert temp_db_cursor.table_rows('country_name') == 4