make status API work with sqlite incl. unit tests

This commit is contained in:
Sarah Hoffmann 2023-10-12 16:17:16 +02:00
parent 07e6c5cf69
commit 06bbd501fd
2 changed files with 9 additions and 4 deletions

View File

@ -36,6 +36,9 @@ async def get_status(conn: SearchConnection) -> StatusResult:
sql = sa.select(conn.t.import_status.c.lastimportdate).limit(1) sql = sa.select(conn.t.import_status.c.lastimportdate).limit(1)
status.data_updated = await conn.scalar(sql) status.data_updated = await conn.scalar(sql)
if status.data_updated is not None:
status.data_updated = status.data_updated.replace(tzinfo=dt.timezone.utc)
# Database version # Database version
try: try:
verstr = await conn.get_property('database_version') verstr = await conn.get_property('database_version')

View File

@ -14,8 +14,9 @@ import pytest
from nominatim.version import NOMINATIM_VERSION, NominatimVersion from nominatim.version import NOMINATIM_VERSION, NominatimVersion
import nominatim.api as napi import nominatim.api as napi
def test_status_no_extra_info(apiobj): def test_status_no_extra_info(apiobj, frontend):
result = apiobj.api.status() api = frontend(apiobj)
result = api.status()
assert result.status == 0 assert result.status == 0
assert result.message == 'OK' assert result.message == 'OK'
@ -24,14 +25,15 @@ def test_status_no_extra_info(apiobj):
assert result.data_updated is None assert result.data_updated is None
def test_status_full(apiobj): def test_status_full(apiobj, frontend):
import_date = dt.datetime(2022, 12, 7, 14, 14, 46, 0, tzinfo=dt.timezone.utc) import_date = dt.datetime(2022, 12, 7, 14, 14, 46, 0, tzinfo=dt.timezone.utc)
apiobj.add_data('import_status', apiobj.add_data('import_status',
[{'lastimportdate': import_date}]) [{'lastimportdate': import_date}])
apiobj.add_data('properties', apiobj.add_data('properties',
[{'property': 'database_version', 'value': '99.5.4-2'}]) [{'property': 'database_version', 'value': '99.5.4-2'}])
result = apiobj.api.status() api = frontend(apiobj)
result = api.status()
assert result.status == 0 assert result.status == 0
assert result.message == 'OK' assert result.message == 'OK'