1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2023 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 import psycopg2.extras
19 from fake_adaptor import FakeAdaptor, FakeError, FakeResponse
21 import nominatim.api.v1.server_glue as glue
22 import nominatim.api as napi
24 @pytest_asyncio.fixture
26 api = napi.NominatimAPIAsync(Path('/invalid'))
31 class TestPolygonsEndPoint:
33 @pytest.fixture(autouse=True)
34 def setup_deletable_table(self, temp_db_cursor, table_factory, temp_db_with_extensions):
35 psycopg2.extras.register_hstore(temp_db_cursor)
37 self.now = dt.datetime.now()
38 self.recent = dt.datetime.now() - dt.timedelta(days=3)
40 table_factory('import_polygon_error',
41 definition="""osm_id bigint,
42 osm_type character(1),
46 country_code character varying(2),
47 updated timestamp without time zone,
49 prevgeometry geometry(Geometry,4326),
50 newgeometry geometry(Geometry,4326)""",
51 content=[(345, 'N', 'boundary', 'administrative',
52 {'name': 'Foo'}, 'xx', self.recent,
53 'some text', None, None),
54 (781, 'R', 'landuse', 'wood',
56 'Area reduced by lots', None, None)])
60 async def test_polygons_simple(self, api):
63 resp = await glue.polygons_endpoint(api, a)
64 results = json.loads(resp.output)
66 results.sort(key=lambda r: (r['osm_type'], r['osm_id']))
68 assert results == [{'osm_type': 'N', 'osm_id': 345,
69 'class': 'boundary', 'type': 'administrative',
70 'name': 'Foo', 'country_code': 'xx',
71 'errormessage': 'some text',
72 'updated': self.recent.isoformat(sep=' ', timespec='seconds')},
73 {'osm_type': 'R', 'osm_id': 781,
74 'class': 'landuse', 'type': 'wood',
75 'name': None, 'country_code': 'ds',
76 'errormessage': 'Area reduced by lots',
77 'updated': self.now.isoformat(sep=' ', timespec='seconds')}]
81 async def test_polygons_days(self, api):
83 a.params['days'] = '2'
85 resp = await glue.polygons_endpoint(api, a)
86 results = json.loads(resp.output)
88 assert [r['osm_id'] for r in results] == [781]
92 async def test_polygons_class(self, api):
94 a.params['class'] = 'landuse'
96 resp = await glue.polygons_endpoint(api, a)
97 results = json.loads(resp.output)
99 assert [r['osm_id'] for r in results] == [781]
104 async def test_polygons_reduced(self, api):
106 a.params['reduced'] = '1'
108 resp = await glue.polygons_endpoint(api, a)
109 results = json.loads(resp.output)
111 assert [r['osm_id'] for r in results] == [781]