]> git.openstreetmap.org Git - nominatim.git/blob - test/python/api/test_api_deletable_v1.py
enable all API tests for sqlite and port missing features
[nominatim.git] / test / python / api / test_api_deletable_v1.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2023 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for the deletable v1 API call.
9 """
10 import json
11 from pathlib import Path
12
13 import pytest
14 import pytest_asyncio
15
16 import psycopg2.extras
17
18 from fake_adaptor import FakeAdaptor, FakeError, FakeResponse
19
20 import nominatim.api.v1.server_glue as glue
21 import nominatim.api as napi
22
23 @pytest_asyncio.fixture
24 async def api():
25     api = napi.NominatimAPIAsync(Path('/invalid'))
26     yield api
27     await api.close()
28
29
30 class TestDeletableEndPoint:
31
32     @pytest.fixture(autouse=True)
33     def setup_deletable_table(self, temp_db_cursor, table_factory, temp_db_with_extensions):
34         psycopg2.extras.register_hstore(temp_db_cursor)
35         table_factory('import_polygon_delete',
36                       definition='osm_id bigint, osm_type char(1), class text, type text',
37                       content=[(345, 'N', 'boundary', 'administrative'),
38                                (781, 'R', 'landuse', 'wood'),
39                                (781, 'R', 'landcover', 'grass')])
40         table_factory('placex',
41                       definition="""place_id bigint, osm_id bigint, osm_type char(1),
42                                     class text, type text, name HSTORE, country_code char(2)""",
43                       content=[(1, 345, 'N', 'boundary', 'administrative', {'old_name': 'Former'}, 'ab'),
44                                (2, 781, 'R', 'landuse', 'wood', {'name': 'Wood'}, 'cd'),
45                                (3, 781, 'R', 'landcover', 'grass', None, 'cd')])
46
47
48
49     @pytest.mark.asyncio
50     async def test_deletable(self, api):
51         a = FakeAdaptor()
52
53         resp = await glue.deletable_endpoint(api, a)
54         results = json.loads(resp.output)
55
56         results.sort(key=lambda r: r['place_id'])
57
58         assert results == [{'place_id': 1, 'country_code': 'ab', 'name': None,
59                             'osm_id': 345, 'osm_type': 'N',
60                             'class': 'boundary', 'type': 'administrative'},
61                            {'place_id': 2, 'country_code': 'cd', 'name': 'Wood',
62                             'osm_id': 781, 'osm_type': 'R',
63                             'class': 'landuse', 'type': 'wood'},
64                            {'place_id': 3, 'country_code': 'cd', 'name': None,
65                             'osm_id': 781, 'osm_type': 'R',
66                             'class': 'landcover', 'type': 'grass'}]
67