#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2024 by the Nominatim developer community.
+# Copyright (C) 2025 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Tests for import special phrases methods
of the class SPImporter.
"""
-from shutil import copyfile
import pytest
from nominatim_db.tools.special_phrases.sp_importer import SPImporter
from nominatim_db.tools.special_phrases.sp_wiki_loader import SPWikiLoader
from nominatim_db.tools.special_phrases.special_phrase import SpecialPhrase
-from nominatim_db.errors import UsageError
-from cursor import CursorForTesting
@pytest.fixture
def sp_importer(temp_db_conn, def_config, monkeypatch):
contained_table = sp_importer.table_phrases_to_delete.pop()
assert contained_table == 'place_classtype_testclasstypetable'
+
def test_check_sanity_class(sp_importer):
"""
Check for _check_sanity() method.
assert sp_importer._check_sanity(SpecialPhrase('en', 'class', 'type', ''))
+
def test_load_white_and_black_lists(sp_importer):
"""
Test that _load_white_and_black_lists() well return
assert check_placeid_and_centroid_indexes(temp_db_cursor, phrase_class, phrase_type)
+
def test_create_place_classtype_table(temp_db_conn, temp_db_cursor, placex_table, sp_importer):
"""
Test that _create_place_classtype_table() create
assert check_table_exist(temp_db_cursor, phrase_class, phrase_type)
+
def test_grant_access_to_web_user(temp_db_conn, temp_db_cursor, table_factory,
def_config, sp_importer):
"""
sp_importer._grant_access_to_webuser(phrase_class, phrase_type)
temp_db_conn.commit()
- assert check_grant_access(temp_db_cursor, def_config.DATABASE_WEBUSER, phrase_class, phrase_type)
+ assert check_grant_access(temp_db_cursor, def_config.DATABASE_WEBUSER,
+ phrase_class, phrase_type)
+
def test_create_place_classtype_table_and_indexes(
temp_db_cursor, def_config, placex_table,
assert check_placeid_and_centroid_indexes(temp_db_cursor, pair[0], pair[1])
assert check_grant_access(temp_db_cursor, def_config.DATABASE_WEBUSER, pair[0], pair[1])
+
def test_remove_non_existent_tables_from_db(sp_importer, default_phrases,
temp_db_conn, temp_db_cursor):
"""
temp_db_conn.commit()
assert temp_db_cursor.row_set(query_tables) \
- == {('place_classtype_testclasstypetable_to_keep', )}
+ == {('place_classtype_testclasstypetable_to_keep', )}
@pytest.mark.parametrize("should_replace", [(True), (False)])
It should also update the database well by deleting or preserving existing entries
of the database.
"""
- #Add some data to the database before execution in order to test
- #what is deleted and what is preserved.
+ # Add some data to the database before execution in order to test
+ # what is deleted and what is preserved.
table_factory('place_classtype_amenity_animal_shelter')
table_factory('place_classtype_wrongclass_wrongtype')
if should_replace:
assert not temp_db_cursor.table_exists('place_classtype_wrongclass_wrongtype')
+
def check_table_exist(temp_db_cursor, phrase_class, phrase_type):
"""
Verify that the place_classtype table exists for the given
AND privilege_type='SELECT'""".format(table_name, user))
return temp_db_cursor.fetchone()
+
def check_placeid_and_centroid_indexes(temp_db_cursor, phrase_class, phrase_type):
"""
Check that the place_id index and centroid index exist for the