X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/b90e719da595b6760b39b7cd64ee29447de2d5e8..8c14df55a61d71f2476c8a17287e1bd162a5c6a6:/test/python/db/test_status.py diff --git a/test/python/db/test_status.py b/test/python/db/test_status.py index b6f5a7b1..77135a8c 100644 --- a/test/python/db/test_status.py +++ b/test/python/db/test_status.py @@ -1,3 +1,9 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This file is part of Nominatim. (https://nominatim.org) +# +# Copyright (C) 2024 by the Nominatim developer community. +# For a full list of authors see the git log. """ Tests for status table manipulation. """ @@ -5,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 = """\ @@ -16,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) @@ -25,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): @@ -38,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') @@ -54,15 +76,15 @@ def test_compute_database_broken_api(monkeypatch, place_row, temp_db_conn): requested_url.append(url) return '