]> git.openstreetmap.org Git - nominatim.git/blob - test/python/api/test_api_status.py
Merge pull request #2937 from lonvia/python-server-stub
[nominatim.git] / test / python / api / test_api_status.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for the status API call.
9 """
10 from pathlib import Path
11 import datetime as dt
12 import pytest
13
14 from nominatim.version import NOMINATIM_VERSION, NominatimVersion
15 from nominatim.api import NominatimAPI
16
17 def test_status_no_extra_info(apiobj, table_factory):
18     table_factory('import_status',
19                   definition="lastimportdate timestamp with time zone NOT NULL")
20     table_factory('nominatim_properties',
21                   definition='property TEXT, value TEXT')
22
23     result = apiobj.status()
24
25     assert result.status == 0
26     assert result.message == 'OK'
27     assert result.software_version == NOMINATIM_VERSION
28     assert result.database_version is None
29     assert result.data_updated is None
30
31
32 def test_status_full(apiobj, table_factory):
33     table_factory('import_status',
34                   definition="lastimportdate timestamp with time zone NOT NULL",
35                   content=(('2022-12-07 15:14:46+01',),))
36     table_factory('nominatim_properties',
37                   definition='property TEXT, value TEXT',
38                   content=(('database_version', '99.5.4-2'), ))
39
40     result = apiobj.status()
41
42     assert result.status == 0
43     assert result.message == 'OK'
44     assert result.software_version == NOMINATIM_VERSION
45     assert result.database_version == NominatimVersion(99, 5, 4, 2)
46     assert result.data_updated == dt.datetime(2022, 12, 7, 14, 14, 46, 0, tzinfo=dt.timezone.utc)
47
48
49 def test_status_database_not_found(monkeypatch):
50     monkeypatch.setenv('NOMINATIM_DATABASE_DSN', 'dbname=rgjdfkgjedkrgdfkngdfkg')
51
52     api = NominatimAPI(Path('/invalid'), {})
53
54     result = api.status()
55
56     assert result.status == 700
57     assert result.message == 'Database connection failed'
58     assert result.software_version == NOMINATIM_VERSION
59     assert result.database_version is None
60     assert result.data_updated is None