]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/python/tools/test_admin.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / test / python / tools / test_admin.py
index e53d35c478469f7dcebba1658aed50c0a37dc6a9..9c010b9d4b77e00bc784b305eb2c1cfceab3b2be 100644 (file)
@@ -11,37 +11,62 @@ import pytest
 
 from nominatim.errors import UsageError
 from nominatim.tools import admin
 
 from nominatim.errors import UsageError
 from nominatim.tools import admin
+from nominatim.tokenizer import factory
 
 @pytest.fixture(autouse=True)
 
 @pytest.fixture(autouse=True)
-def create_placex_table(placex_table):
+def create_placex_table(project_env, tokenizer_mock, temp_db_cursor, placex_table):
     """ All tests in this module require the placex table to be set up.
     """
     """ All tests in this module require the placex table to be set up.
     """
+    temp_db_cursor.execute("DROP TYPE IF EXISTS prepare_update_info CASCADE")
+    temp_db_cursor.execute("""CREATE TYPE prepare_update_info AS (
+                             name HSTORE,
+                             address HSTORE,
+                             rank_address SMALLINT,
+                             country_code TEXT,
+                             class TEXT,
+                             type TEXT,
+                             linked_place_id BIGINT
+                           )""")
+    temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION placex_indexing_prepare(p placex,
+                                                     OUT result prepare_update_info)
+                           AS $$
+                           BEGIN
+                             result.address := p.address;
+                             result.name := p.name;
+                             result.class := p.class;
+                             result.type := p.type;
+                             result.country_code := p.country_code;
+                             result.rank_address := p.rank_address;
+                           END;
+                           $$ LANGUAGE plpgsql STABLE;
+                        """)
+    factory.create_tokenizer(project_env)
 
 
 
 
-def test_analyse_indexing_no_objects(temp_db_conn):
+def test_analyse_indexing_no_objects(project_env):
     with pytest.raises(UsageError):
     with pytest.raises(UsageError):
-        admin.analyse_indexing(temp_db_conn)
+        admin.analyse_indexing(project_env)
 
 
 @pytest.mark.parametrize("oid", ['1234', 'N123a', 'X123'])
 
 
 @pytest.mark.parametrize("oid", ['1234', 'N123a', 'X123'])
-def test_analyse_indexing_bad_osmid(temp_db_conn, oid):
+def test_analyse_indexing_bad_osmid(project_env, oid):
     with pytest.raises(UsageError):
     with pytest.raises(UsageError):
-        admin.analyse_indexing(temp_db_conn, osm_id=oid)
+        admin.analyse_indexing(project_env, osm_id=oid)
 
 
 
 
-def test_analyse_indexing_unknown_osmid(temp_db_conn):
+def test_analyse_indexing_unknown_osmid(project_env):
     with pytest.raises(UsageError):
     with pytest.raises(UsageError):
-        admin.analyse_indexing(temp_db_conn, osm_id='W12345674')
+        admin.analyse_indexing(project_env, osm_id='W12345674')
 
 
 
 
-def test_analyse_indexing_with_place_id(temp_db_conn, temp_db_cursor):
+def test_analyse_indexing_with_place_id(project_env, temp_db_cursor):
     temp_db_cursor.execute("INSERT INTO placex (place_id) VALUES(12345)")
 
     temp_db_cursor.execute("INSERT INTO placex (place_id) VALUES(12345)")
 
-    admin.analyse_indexing(temp_db_conn, place_id=12345)
+    admin.analyse_indexing(project_env, place_id=12345)
 
 
 
 
-def test_analyse_indexing_with_osm_id(temp_db_conn, temp_db_cursor):
+def test_analyse_indexing_with_osm_id(project_env, temp_db_cursor):
     temp_db_cursor.execute("""INSERT INTO placex (place_id, osm_type, osm_id)
                               VALUES(9988, 'N', 10000)""")
 
     temp_db_cursor.execute("""INSERT INTO placex (place_id, osm_type, osm_id)
                               VALUES(9988, 'N', 10000)""")
 
-    admin.analyse_indexing(temp_db_conn, osm_id='N10000')
+    admin.analyse_indexing(project_env, osm_id='N10000')