X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/c314a3092c5b51c7782015f6fa9ac093b46fa174..d856788bf5cf7b4b3e2b4de10f37cf3002ae6826:/test/python/tools/test_migration.py diff --git a/test/python/tools/test_migration.py b/test/python/tools/test_migration.py index 3a849adb..fd790f75 100644 --- a/test/python/tools/test_migration.py +++ b/test/python/tools/test_migration.py @@ -8,14 +8,12 @@ Tests for migration functions """ import pytest -import psycopg2.extras from nominatim_db.tools import migration from nominatim_db.errors import UsageError +from nominatim_db.db.connection import server_version_tuple import nominatim_db.version -from mock_legacy_word_table import MockLegacyWordTable - class DummyTokenizer: def update_sql_functions(self, config): @@ -28,10 +26,6 @@ def postprocess_mock(monkeypatch): monkeypatch.setattr(migration.tokenizer_factory, 'get_tokenizer_for_db', lambda *args: DummyTokenizer()) -@pytest.fixture -def legacy_word_table(temp_db_conn): - return MockLegacyWordTable(temp_db_conn) - def test_no_migration_old_versions(temp_db_with_extensions, table_factory, def_config): table_factory('country_name', 'name HSTORE, country_code TEXT') @@ -43,7 +37,6 @@ def test_no_migration_old_versions(temp_db_with_extensions, table_factory, def_c def test_set_up_migration_for_36(temp_db_with_extensions, temp_db_cursor, table_factory, def_config, monkeypatch, postprocess_mock): - psycopg2.extras.register_hstore(temp_db_cursor) # don't actually run any migration, except the property table creation monkeypatch.setattr(migration, '_MIGRATION_FUNCTIONS', [((3, 5, 0, 99), migration.add_nominatim_property_table)]) @@ -63,7 +56,7 @@ def test_set_up_migration_for_36(temp_db_with_extensions, temp_db_cursor, WHERE property = 'database_version'""") -def test_already_at_version(def_config, property_table): +def test_already_at_version(temp_db_with_extensions, def_config, property_table): property_table.set('database_version', str(nominatim_db.version.NOMINATIM_VERSION)) @@ -71,8 +64,8 @@ def test_already_at_version(def_config, property_table): assert migration.migrate(def_config, {}) == 0 -def test_run_single_migration(def_config, temp_db_cursor, property_table, - monkeypatch, postprocess_mock): +def test_run_single_migration(temp_db_with_extensions, def_config, temp_db_cursor, + property_table, monkeypatch, postprocess_mock): oldversion = [x for x in nominatim_db.version.NOMINATIM_VERSION] oldversion[0] -= 1 property_table.set('database_version', @@ -146,26 +139,6 @@ def test_add_nominatim_property_table_repeat(temp_db_conn, temp_db_cursor, assert temp_db_cursor.table_exists('nominatim_properties') -def test_change_housenumber_transliteration(temp_db_conn, temp_db_cursor, - legacy_word_table, placex_table): - placex_table.add(housenumber='3A') - - temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION make_standard_name(name TEXT) - RETURNS TEXT AS $$ SELECT lower(name) $$ LANGUAGE SQL """) - temp_db_cursor.execute("""CREATE OR REPLACE FUNCTION getorcreate_housenumber_id(lookup_word TEXT) - RETURNS INTEGER AS $$ SELECT 4325 $$ LANGUAGE SQL """) - - migration.change_housenumber_transliteration(temp_db_conn) - temp_db_conn.commit() - - assert temp_db_cursor.scalar('SELECT housenumber from placex') == '3a' - - migration.change_housenumber_transliteration(temp_db_conn) - temp_db_conn.commit() - - assert temp_db_cursor.scalar('SELECT housenumber from placex') == '3a' - - def test_switch_placenode_geometry_index(temp_db_conn, temp_db_cursor, placex_table): temp_db_cursor.execute("""CREATE INDEX idx_placex_adminname ON placex (place_id)""") @@ -226,7 +199,7 @@ def test_create_tiger_housenumber_index(temp_db_conn, temp_db_cursor, table_fact migration.create_tiger_housenumber_index(temp_db_conn) temp_db_conn.commit() - if temp_db_conn.server_version_tuple() >= (11, 0, 0): + if server_version_tuple(temp_db_conn) >= (11, 0, 0): assert temp_db_cursor.index_exists('location_property_tiger', 'idx_location_property_tiger_housenumber_migrated')