1 # SPDX-License-Identifier: GPL-3.0-or-later
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2025 by the Nominatim developer community.
 
   6 # For a full list of authors see the git log.
 
   8 Tests for the deletable v1 API call.
 
  15 from fake_adaptor import FakeAdaptor
 
  17 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)])
 
  46     async def test_polygons_simple(self, api):
 
  49         resp = await glue.polygons_endpoint(api, a)
 
  50         results = json.loads(resp.output)
 
  52         results.sort(key=lambda r: (r['osm_type'], r['osm_id']))
 
  54         assert results == [{'osm_type': 'N', 'osm_id': 345,
 
  55                             'class': 'boundary', 'type': 'administrative',
 
  56                             'name': 'Foo', 'country_code': 'xx',
 
  57                             'errormessage': 'some text',
 
  58                             'updated': self.recent.isoformat(sep=' ', timespec='seconds')},
 
  59                            {'osm_type': 'R', 'osm_id': 781,
 
  60                             'class': 'landuse', 'type': 'wood',
 
  61                             'name': None, 'country_code': 'ds',
 
  62                             'errormessage': 'Area reduced by lots',
 
  63                             'updated': self.now.isoformat(sep=' ', timespec='seconds')}]
 
  66     async def test_polygons_days(self, api):
 
  68         a.params['days'] = '2'
 
  70         resp = await glue.polygons_endpoint(api, a)
 
  71         results = json.loads(resp.output)
 
  73         assert [r['osm_id'] for r in results] == [781]
 
  76     async def test_polygons_class(self, api):
 
  78         a.params['class'] = 'landuse'
 
  80         resp = await glue.polygons_endpoint(api, a)
 
  81         results = json.loads(resp.output)
 
  83         assert [r['osm_id'] for r in results] == [781]
 
  86     async def test_polygons_reduced(self, api):
 
  88         a.params['reduced'] = '1'
 
  90         resp = await glue.polygons_endpoint(api, a)
 
  91         results = json.loads(resp.output)
 
  93         assert [r['osm_id'] for r in results] == [781]