2 Tests for import special phrases functions
5 from nominatim.tools.special_phrases import _create_place_classtype_indexes, _create_place_classtype_table, _get_wiki_content, _grant_access_to_webuser, _process_amenity
7 def test_process_amenity_with_operator(temp_db_conn, getorcreate_amenityoperator_funcs):
8 _process_amenity(temp_db_conn, '', '', '', '', 'near')
9 _process_amenity(temp_db_conn, '', '', '', '', 'in')
11 def test_process_amenity_without_operator(temp_db_conn, getorcreate_amenity_funcs):
12 _process_amenity(temp_db_conn, '', '', '', '', '')
14 def test_create_place_classtype_indexes(temp_db_conn):
15 phrase_class = 'class'
17 table_name = 'place_classtype_{}_{}'.format(phrase_class, phrase_type)
18 index_prefix = 'idx_place_classtype_{}_{}_'.format(phrase_class, phrase_type)
20 with temp_db_conn.cursor() as temp_db_cursor:
21 temp_db_cursor.execute("CREATE EXTENSION postgis;")
22 temp_db_cursor.execute('CREATE TABLE {}(place_id BIGINT, centroid GEOMETRY)'.format(table_name))
24 _create_place_classtype_indexes(temp_db_conn, '', phrase_class, phrase_type)
26 centroid_index_exists = temp_db_conn.index_exists(index_prefix + 'centroid')
27 place_id_index_exists = temp_db_conn.index_exists(index_prefix + 'place_id')
29 assert centroid_index_exists and place_id_index_exists
31 def test_create_place_classtype_table(temp_db_conn, placex_table):
32 phrase_class = 'class'
34 _create_place_classtype_table(temp_db_conn, '', phrase_class, phrase_type)
36 with temp_db_conn.cursor() as temp_db_cursor:
37 temp_db_cursor.execute(f"""
39 FROM information_schema.tables
40 WHERE table_type='BASE TABLE'
41 AND table_name='place_classtype_{phrase_class}_{phrase_type}'""")
42 result = temp_db_cursor.fetchone()
45 def test_grant_access_to_web_user(temp_db_conn, def_config):
46 phrase_class = 'class'
48 table_name = 'place_classtype_{}_{}'.format(phrase_class, phrase_type)
50 with temp_db_conn.cursor() as temp_db_cursor:
51 temp_db_cursor.execute('CREATE TABLE {}()'.format(table_name))
53 _grant_access_to_webuser(temp_db_conn, def_config, phrase_class, phrase_type)
55 with temp_db_conn.cursor() as temp_db_cursor:
56 temp_db_cursor.execute(f"""
57 SELECT * FROM information_schema.role_table_grants
58 WHERE table_name='{table_name}'
59 AND grantee='{def_config.DATABASE_WEBUSER}'
60 AND privilege_type='SELECT'""")
61 result = temp_db_cursor.fetchone()
65 def make_strandard_name_func(temp_db_cursor):
66 temp_db_cursor.execute(f"""
67 CREATE OR REPLACE FUNCTION make_standard_name(name TEXT) RETURNS TEXT AS $$
69 RETURN trim(name); --Basically return only the trimed name for the tests
71 $$ LANGUAGE plpgsql IMMUTABLE;""")
74 def getorcreate_amenity_funcs(temp_db_cursor, make_strandard_name_func):
75 temp_db_cursor.execute(f"""
76 CREATE OR REPLACE FUNCTION getorcreate_amenity(lookup_word TEXT, normalized_word TEXT,
77 lookup_class text, lookup_type text)
80 $$ LANGUAGE plpgsql""")
83 def getorcreate_amenityoperator_funcs(temp_db_cursor, make_strandard_name_func):
84 temp_db_cursor.execute(f"""
85 CREATE OR REPLACE FUNCTION getorcreate_amenityoperator(lookup_word TEXT, normalized_word TEXT,
86 lookup_class text, lookup_type text, op text)
89 $$ LANGUAGE plpgsql""")