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
 
  16 from fake_adaptor import FakeAdaptor, FakeError, FakeResponse
 
  18 import nominatim_api.v1.server_glue as glue
 
  20 class TestPolygonsEndPoint:
 
  22     @pytest.fixture(autouse=True)
 
  23     def setup_deletable_table(self, temp_db_cursor, table_factory, temp_db_with_extensions):
 
  24         self.now = dt.datetime.now()
 
  25         self.recent = dt.datetime.now() - dt.timedelta(days=3)
 
  27         table_factory('import_polygon_error',
 
  28                       definition="""osm_id bigint,
 
  29                                     osm_type character(1),
 
  33                                     country_code character varying(2),
 
  34                                     updated timestamp without time zone,
 
  36                                     prevgeometry geometry(Geometry,4326),
 
  37                                     newgeometry geometry(Geometry,4326)""",
 
  38                     content=[(345, 'N', 'boundary', 'administrative',
 
  39                               {'name': 'Foo'}, 'xx', self.recent,
 
  40                               'some text', None, None),
 
  41                              (781, 'R', 'landuse', 'wood',
 
  43                               'Area reduced by lots', None, None)])
 
  47     async def test_polygons_simple(self, api):
 
  50         resp = await glue.polygons_endpoint(api, a)
 
  51         results = json.loads(resp.output)
 
  53         results.sort(key=lambda r: (r['osm_type'], r['osm_id']))
 
  55         assert results == [{'osm_type': 'N', 'osm_id': 345,
 
  56                             'class': 'boundary', 'type': 'administrative',
 
  57                             'name': 'Foo', 'country_code': 'xx',
 
  58                             'errormessage': 'some text',
 
  59                             'updated': self.recent.isoformat(sep=' ', timespec='seconds')},
 
  60                            {'osm_type': 'R', 'osm_id': 781,
 
  61                             'class': 'landuse', 'type': 'wood',
 
  62                             'name': None, 'country_code': 'ds',
 
  63                             'errormessage': 'Area reduced by lots',
 
  64                             'updated': self.now.isoformat(sep=' ', timespec='seconds')}]
 
  68     async def test_polygons_days(self, api):
 
  70         a.params['days'] = '2'
 
  72         resp = await glue.polygons_endpoint(api, a)
 
  73         results = json.loads(resp.output)
 
  75         assert [r['osm_id'] for r in results] == [781]
 
  79     async def test_polygons_class(self, api):
 
  81         a.params['class'] = 'landuse'
 
  83         resp = await glue.polygons_endpoint(api, a)
 
  84         results = json.loads(resp.output)
 
  86         assert [r['osm_id'] for r in results] == [781]
 
  91     async def test_polygons_reduced(self, api):
 
  93         a.params['reduced'] = '1'
 
  95         resp = await glue.polygons_endpoint(api, a)
 
  96         results = json.loads(resp.output)
 
  98         assert [r['osm_id'] for r in results] == [781]