X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/5e477e3b5b99da6fc4e54749d4671a6fc8fdcd66..8e8f7a641b8b2eadd99e8e3198f762a3c3ebfd67:/test/python/db/test_status.py diff --git a/test/python/db/test_status.py b/test/python/db/test_status.py index 0cb12e02..77135a8c 100644 --- a/test/python/db/test_status.py +++ b/test/python/db/test_status.py @@ -1,8 +1,8 @@ -# SPDX-License-Identifier: GPL-2.0-only +# SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 2022 by the Nominatim developer community. +# Copyright (C) 2024 by the Nominatim developer community. # For a full list of authors see the git log. """ Tests for status table manipulation. @@ -11,8 +11,8 @@ import datetime as dt import pytest -import nominatim.db.status -from nominatim.errors import UsageError +import nominatim_db.db.status +from nominatim_db.errors import UsageError OSM_NODE_DATA = """\ @@ -22,7 +22,7 @@ OSM_NODE_DATA = """\ """ def iso_date(date): - return dt.datetime.strptime(date, nominatim.db.status.ISODATE_FORMAT)\ + return dt.datetime.strptime(date, nominatim_db.db.status.ISODATE_FORMAT)\ .replace(tzinfo=dt.timezone.utc) @@ -31,9 +31,25 @@ def setup_status_table(status_table): pass +@pytest.mark.parametrize('offline', [True, False]) +def test_compute_database_date_from_osm2pgsql(table_factory, temp_db_conn, offline): + table_factory('osm2pgsql_properties', 'property TEXT, value TEXT', + content=(('current_timestamp', '2024-01-03T23:45:54Z'), )) + + date = nominatim_db.db.status.compute_database_date(temp_db_conn, offline=offline) + assert date == iso_date('2024-01-03T23:45:54') + + +def test_compute_database_date_from_osm2pgsql_nodata(table_factory, temp_db_conn): + table_factory('osm2pgsql_properties', 'property TEXT, value TEXT') + + with pytest.raises(UsageError, match='Cannot determine database date from data in offline mode'): + nominatim_db.db.status.compute_database_date(temp_db_conn, offline=True) + + def test_compute_database_date_place_empty(place_table, temp_db_conn): with pytest.raises(UsageError): - nominatim.db.status.compute_database_date(temp_db_conn) + nominatim_db.db.status.compute_database_date(temp_db_conn) def test_compute_database_date_valid(monkeypatch, place_row, temp_db_conn): @@ -44,9 +60,9 @@ def test_compute_database_date_valid(monkeypatch, place_row, temp_db_conn): requested_url.append(url) return OSM_NODE_DATA - monkeypatch.setattr(nominatim.db.status, "get_url", mock_url) + monkeypatch.setattr(nominatim_db.db.status, "get_url", mock_url) - date = nominatim.db.status.compute_database_date(temp_db_conn) + date = nominatim_db.db.status.compute_database_date(temp_db_conn) assert requested_url == ['https://www.openstreetmap.org/api/0.6/node/45673/1'] assert date == iso_date('2006-01-27T22:09:10') @@ -60,15 +76,15 @@ def test_compute_database_broken_api(monkeypatch, place_row, temp_db_conn): requested_url.append(url) return '