1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2024 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Tests for the deletable v1 API call.
11 from pathlib import Path
16 from fake_adaptor import FakeAdaptor, FakeError, FakeResponse
18 import nominatim_api.v1.server_glue as glue
19 import nominatim_api as napi
21 @pytest_asyncio.fixture
23 api = napi.NominatimAPIAsync(Path('/invalid'))
28 class TestDeletableEndPoint:
30 @pytest.fixture(autouse=True)
31 def setup_deletable_table(self, temp_db_cursor, table_factory, temp_db_with_extensions):
32 table_factory('import_polygon_delete',
33 definition='osm_id bigint, osm_type char(1), class text, type text',
34 content=[(345, 'N', 'boundary', 'administrative'),
35 (781, 'R', 'landuse', 'wood'),
36 (781, 'R', 'landcover', 'grass')])
37 table_factory('placex',
38 definition="""place_id bigint, osm_id bigint, osm_type char(1),
39 class text, type text, name HSTORE, country_code char(2)""",
40 content=[(1, 345, 'N', 'boundary', 'administrative', {'old_name': 'Former'}, 'ab'),
41 (2, 781, 'R', 'landuse', 'wood', {'name': 'Wood'}, 'cd'),
42 (3, 781, 'R', 'landcover', 'grass', None, 'cd')])
47 async def test_deletable(self, api):
50 resp = await glue.deletable_endpoint(api, a)
51 results = json.loads(resp.output)
53 results.sort(key=lambda r: r['place_id'])
55 assert results == [{'place_id': 1, 'country_code': 'ab', 'name': None,
56 'osm_id': 345, 'osm_type': 'N',
57 'class': 'boundary', 'type': 'administrative'},
58 {'place_id': 2, 'country_code': 'cd', 'name': 'Wood',
59 'osm_id': 781, 'osm_type': 'R',
60 'class': 'landuse', 'type': 'wood'},
61 {'place_id': 3, 'country_code': 'cd', 'name': None,
62 'osm_id': 781, 'osm_type': 'R',
63 'class': 'landcover', 'type': 'grass'}]