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.
12 from pathlib import Path
17 from fake_adaptor import FakeAdaptor, FakeError, FakeResponse
19 import nominatim_api.v1.server_glue as glue
20 import nominatim_api as napi
22 @pytest_asyncio.fixture
24 api = napi.NominatimAPIAsync(Path('/invalid'))
29 class TestPolygonsEndPoint:
31 @pytest.fixture(autouse=True)
32 def setup_deletable_table(self, temp_db_cursor, table_factory, temp_db_with_extensions):
33 self.now = dt.datetime.now()
34 self.recent = dt.datetime.now() - dt.timedelta(days=3)
36 table_factory('import_polygon_error',
37 definition="""osm_id bigint,
38 osm_type character(1),
42 country_code character varying(2),
43 updated timestamp without time zone,
45 prevgeometry geometry(Geometry,4326),
46 newgeometry geometry(Geometry,4326)""",
47 content=[(345, 'N', 'boundary', 'administrative',
48 {'name': 'Foo'}, 'xx', self.recent,
49 'some text', None, None),
50 (781, 'R', 'landuse', 'wood',
52 'Area reduced by lots', None, None)])
56 async def test_polygons_simple(self, api):
59 resp = await glue.polygons_endpoint(api, a)
60 results = json.loads(resp.output)
62 results.sort(key=lambda r: (r['osm_type'], r['osm_id']))
64 assert results == [{'osm_type': 'N', 'osm_id': 345,
65 'class': 'boundary', 'type': 'administrative',
66 'name': 'Foo', 'country_code': 'xx',
67 'errormessage': 'some text',
68 'updated': self.recent.isoformat(sep=' ', timespec='seconds')},
69 {'osm_type': 'R', 'osm_id': 781,
70 'class': 'landuse', 'type': 'wood',
71 'name': None, 'country_code': 'ds',
72 'errormessage': 'Area reduced by lots',
73 'updated': self.now.isoformat(sep=' ', timespec='seconds')}]
77 async def test_polygons_days(self, api):
79 a.params['days'] = '2'
81 resp = await glue.polygons_endpoint(api, a)
82 results = json.loads(resp.output)
84 assert [r['osm_id'] for r in results] == [781]
88 async def test_polygons_class(self, api):
90 a.params['class'] = 'landuse'
92 resp = await glue.polygons_endpoint(api, a)
93 results = json.loads(resp.output)
95 assert [r['osm_id'] for r in results] == [781]
100 async def test_polygons_reduced(self, api):
102 a.params['reduced'] = '1'
104 resp = await glue.polygons_endpoint(api, a)
105 results = json.loads(resp.output)
107 assert [r['osm_id'] for r in results] == [781]