]> git.openstreetmap.org Git - nominatim.git/blob - test/python/api/test_api_polygons_v1.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / test / python / api / test_api_polygons_v1.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2025 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Tests for the deletable v1 API call.
9 """
10 import json
11 import datetime as dt
12
13 import pytest
14
15 from fake_adaptor import FakeAdaptor
16
17 import nominatim_api.v1.server_glue as glue
18
19
20 class TestPolygonsEndPoint:
21
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)
26
27         table_factory('import_polygon_error',
28                       definition="""osm_id bigint,
29                                     osm_type character(1),
30                                     class text,
31                                     type text,
32                                     name hstore,
33                                     country_code character varying(2),
34                                     updated timestamp without time zone,
35                                     errormessage text,
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',
42                                 None, 'ds', self.now,
43                                 'Area reduced by lots', None, None)])
44
45     @pytest.mark.asyncio
46     async def test_polygons_simple(self, api):
47         a = FakeAdaptor()
48
49         resp = await glue.polygons_endpoint(api, a)
50         results = json.loads(resp.output)
51
52         results.sort(key=lambda r: (r['osm_type'], r['osm_id']))
53
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')}]
64
65     @pytest.mark.asyncio
66     async def test_polygons_days(self, api):
67         a = FakeAdaptor()
68         a.params['days'] = '2'
69
70         resp = await glue.polygons_endpoint(api, a)
71         results = json.loads(resp.output)
72
73         assert [r['osm_id'] for r in results] == [781]
74
75     @pytest.mark.asyncio
76     async def test_polygons_class(self, api):
77         a = FakeAdaptor()
78         a.params['class'] = 'landuse'
79
80         resp = await glue.polygons_endpoint(api, a)
81         results = json.loads(resp.output)
82
83         assert [r['osm_id'] for r in results] == [781]
84
85     @pytest.mark.asyncio
86     async def test_polygons_reduced(self, api):
87         a = FakeAdaptor()
88         a.params['reduced'] = '1'
89
90         resp = await glue.polygons_endpoint(api, a)
91         results = json.loads(resp.output)
92
93         assert [r['osm_id'] for r in results] == [781]