]> git.openstreetmap.org Git - nominatim.git/blob - test/python/api/test_api_deletable_v1.py
Merge remote-tracking branch 'upstream/master'
[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) 2025 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
12 import pytest
13
14 from fake_adaptor import FakeAdaptor
15
16 import nominatim_api.v1.server_glue as glue
17
18
19 class TestDeletableEndPoint:
20
21     @pytest.fixture(autouse=True)
22     def setup_deletable_table(self, temp_db_cursor, table_factory, temp_db_with_extensions):
23         table_factory('import_polygon_delete',
24                       definition='osm_id bigint, osm_type char(1), class text, type text',
25                       content=[(345, 'N', 'boundary', 'administrative'),
26                                (781, 'R', 'landuse', 'wood'),
27                                (781, 'R', 'landcover', 'grass')])
28         table_factory(
29             'placex',
30             definition="""place_id bigint, osm_id bigint, osm_type char(1),
31                           class text, type text, name HSTORE, country_code char(2)""",
32             content=[(1, 345, 'N', 'boundary', 'administrative', {'old_name': 'Former'}, 'ab'),
33                      (2, 781, 'R', 'landuse', 'wood', {'name': 'Wood'}, 'cd'),
34                      (3, 781, 'R', 'landcover', 'grass', None, 'cd')])
35
36     @pytest.mark.asyncio
37     async def test_deletable(self, api):
38         a = FakeAdaptor()
39
40         resp = await glue.deletable_endpoint(api, a)
41         results = json.loads(resp.output)
42
43         results.sort(key=lambda r: r['place_id'])
44
45         assert results == [{'place_id': 1, 'country_code': 'ab', 'name': None,
46                             'osm_id': 345, 'osm_type': 'N',
47                             'class': 'boundary', 'type': 'administrative'},
48                            {'place_id': 2, 'country_code': 'cd', 'name': 'Wood',
49                             'osm_id': 781, 'osm_type': 'R',
50                             'class': 'landuse', 'type': 'wood'},
51                            {'place_id': 3, 'country_code': 'cd', 'name': None,
52                             'osm_id': 781, 'osm_type': 'R',
53                             'class': 'landcover', 'type': 'grass'}]