]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/python/api/test_server_glue_v1.py
also enable flake for tests in github actions
[nominatim.git] / test / python / api / test_server_glue_v1.py
index 5ef169045e0a4712c256bf38d2634a4bbae6e146..8d9f09404bfb2cd92c703d136c33fa5784f36c9d 100644 (file)
@@ -2,14 +2,13 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2024 by the Nominatim developer community.
+# Copyright (C) 2025 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Tests for the Python web frameworks adaptor, v1 API.
 """
 import json
 import xml.etree.ElementTree as ET
-from pathlib import Path
 
 import pytest
 
@@ -122,7 +121,6 @@ class TestAdaptorRaiseError:
 
         return excinfo.value
 
-
     def test_without_content_set(self):
         err = self.run_raise_error('TEST', 404)
 
@@ -130,7 +128,6 @@ class TestAdaptorRaiseError:
         assert err.msg == 'ERROR 404: TEST'
         assert err.status == 404
 
-
     def test_json(self):
         self.adaptor.content_type = 'application/json; charset=utf-8'
 
@@ -140,7 +137,6 @@ class TestAdaptorRaiseError:
         assert content['code'] == 501
         assert content['message'] == 'TEST'
 
-
     def test_xml(self):
         self.adaptor.content_type = 'text/xml; charset=utf-8'
 
@@ -236,50 +232,46 @@ class TestStatusEndpoint:
 
         monkeypatch.setattr(napi.NominatimAPIAsync, 'status', _status)
 
-
     @pytest.mark.asyncio
     async def test_status_without_params(self):
         a = FakeAdaptor()
         self.status = napi.StatusResult(0, 'foo')
 
-        resp = await glue.status_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        resp = await glue.status_endpoint(napi.NominatimAPIAsync(), a)
 
         assert isinstance(resp, FakeResponse)
         assert resp.status == 200
         assert resp.content_type == 'text/plain; charset=utf-8'
 
-
     @pytest.mark.asyncio
     async def test_status_with_error(self):
         a = FakeAdaptor()
         self.status = napi.StatusResult(405, 'foo')
 
-        resp = await glue.status_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        resp = await glue.status_endpoint(napi.NominatimAPIAsync(), a)
 
         assert isinstance(resp, FakeResponse)
         assert resp.status == 500
         assert resp.content_type == 'text/plain; charset=utf-8'
 
-
     @pytest.mark.asyncio
     async def test_status_json_with_error(self):
         a = FakeAdaptor(params={'format': 'json'})
         self.status = napi.StatusResult(405, 'foo')
 
-        resp = await glue.status_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        resp = await glue.status_endpoint(napi.NominatimAPIAsync(), a)
 
         assert isinstance(resp, FakeResponse)
         assert resp.status == 200
         assert resp.content_type == 'application/json; charset=utf-8'
 
-
     @pytest.mark.asyncio
     async def test_status_bad_format(self):
         a = FakeAdaptor(params={'format': 'foo'})
         self.status = napi.StatusResult(0, 'foo')
 
         with pytest.raises(FakeError):
-            await glue.status_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+            await glue.status_endpoint(napi.NominatimAPIAsync(), a)
 
 
 # details_endpoint()
@@ -299,53 +291,48 @@ class TestDetailsEndpoint:
 
         monkeypatch.setattr(napi.NominatimAPIAsync, 'details', _lookup)
 
-
     @pytest.mark.asyncio
     async def test_details_no_params(self):
         a = FakeAdaptor()
 
         with pytest.raises(FakeError, match='^400 -- .*Missing'):
-            await glue.details_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
-
+            await glue.details_endpoint(napi.NominatimAPIAsync(), a)
 
     @pytest.mark.asyncio
     async def test_details_by_place_id(self):
         a = FakeAdaptor(params={'place_id': '4573'})
 
-        await glue.details_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        await glue.details_endpoint(napi.NominatimAPIAsync(), a)
 
         assert self.lookup_args[0].place_id == 4573
 
-
     @pytest.mark.asyncio
     async def test_details_by_osm_id(self):
         a = FakeAdaptor(params={'osmtype': 'N', 'osmid': '45'})
 
-        await glue.details_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        await glue.details_endpoint(napi.NominatimAPIAsync(), a)
 
         assert self.lookup_args[0].osm_type == 'N'
         assert self.lookup_args[0].osm_id == 45
         assert self.lookup_args[0].osm_class is None
 
-
     @pytest.mark.asyncio
     async def test_details_with_debugging(self):
         a = FakeAdaptor(params={'osmtype': 'N', 'osmid': '45', 'debug': '1'})
 
-        resp = await glue.details_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        resp = await glue.details_endpoint(napi.NominatimAPIAsync(), a)
         content = ET.fromstring(resp.output)
 
         assert resp.content_type == 'text/html; charset=utf-8'
         assert content.tag == 'html'
 
-
     @pytest.mark.asyncio
     async def test_details_no_result(self):
         a = FakeAdaptor(params={'place_id': '4573'})
         self.result = None
 
         with pytest.raises(FakeError, match='^404 -- .*found'):
-            await glue.details_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+            await glue.details_endpoint(napi.NominatimAPIAsync(), a)
 
 
 # reverse_endpoint()
@@ -354,14 +341,14 @@ class TestReverseEndPoint:
     @pytest.fixture(autouse=True)
     def patch_reverse_func(self, monkeypatch):
         self.result = napi.ReverseResult(napi.SourceTable.PLACEX,
-                                          ('place', 'thing'),
-                                          napi.Point(1.0, 2.0))
+                                         ('place', 'thing'),
+                                         napi.Point(1.0, 2.0))
+
         async def _reverse(*args, **kwargs):
             return self.result
 
         monkeypatch.setattr(napi.NominatimAPIAsync, 'reverse', _reverse)
 
-
     @pytest.mark.asyncio
     @pytest.mark.parametrize('params', [{}, {'lat': '3.4'}, {'lon': '6.7'}])
     async def test_reverse_no_params(self, params):
@@ -370,20 +357,7 @@ class TestReverseEndPoint:
         a.params['format'] = 'xml'
 
         with pytest.raises(FakeError, match='^400 -- (?s:.*)missing'):
-            await glue.reverse_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
-
-
-    @pytest.mark.asyncio
-    @pytest.mark.parametrize('params', [{'lat': '45.6', 'lon': '4563'}])
-    async def test_reverse_success(self, params):
-        a = FakeAdaptor()
-        a.params = params
-        a.params['format'] = 'json'
-
-        res = await glue.reverse_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
-
-        assert res == ''
-
+            await glue.reverse_endpoint(napi.NominatimAPIAsync(), a)
 
     @pytest.mark.asyncio
     async def test_reverse_success(self):
@@ -391,8 +365,7 @@ class TestReverseEndPoint:
         a.params['lat'] = '56.3'
         a.params['lon'] = '6.8'
 
-        assert await glue.reverse_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
-
+        assert await glue.reverse_endpoint(napi.NominatimAPIAsync(), a)
 
     @pytest.mark.asyncio
     async def test_reverse_from_search(self):
@@ -400,7 +373,7 @@ class TestReverseEndPoint:
         a.params['q'] = '34.6 2.56'
         a.params['format'] = 'json'
 
-        res = await glue.search_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        res = await glue.search_endpoint(napi.NominatimAPIAsync(), a)
 
         assert len(json.loads(res.output)) == 1
 
@@ -414,22 +387,21 @@ class TestLookupEndpoint:
         self.results = [napi.SearchResult(napi.SourceTable.PLACEX,
                                           ('place', 'thing'),
                                           napi.Point(1.0, 2.0))]
+
         async def _lookup(*args, **kwargs):
             return napi.SearchResults(self.results)
 
         monkeypatch.setattr(napi.NominatimAPIAsync, 'lookup', _lookup)
 
-
     @pytest.mark.asyncio
     async def test_lookup_no_params(self):
         a = FakeAdaptor()
         a.params['format'] = 'json'
 
-        res = await glue.lookup_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        res = await glue.lookup_endpoint(napi.NominatimAPIAsync(), a)
 
         assert res.output == '[]'
 
-
     @pytest.mark.asyncio
     @pytest.mark.parametrize('param', ['w', 'bad', ''])
     async def test_lookup_bad_params(self, param):
@@ -437,11 +409,10 @@ class TestLookupEndpoint:
         a.params['format'] = 'json'
         a.params['osm_ids'] = f'W34,{param},N33333'
 
-        res = await glue.lookup_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        res = await glue.lookup_endpoint(napi.NominatimAPIAsync(), a)
 
         assert len(json.loads(res.output)) == 1
 
-
     @pytest.mark.asyncio
     @pytest.mark.parametrize('param', ['p234234', '4563'])
     async def test_lookup_bad_osm_type(self, param):
@@ -449,18 +420,17 @@ class TestLookupEndpoint:
         a.params['format'] = 'json'
         a.params['osm_ids'] = f'W34,{param},N33333'
 
-        res = await glue.lookup_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        res = await glue.lookup_endpoint(napi.NominatimAPIAsync(), a)
 
         assert len(json.loads(res.output)) == 1
 
-
     @pytest.mark.asyncio
     async def test_lookup_working(self):
         a = FakeAdaptor()
         a.params['format'] = 'json'
         a.params['osm_ids'] = 'N23,W34'
 
-        res = await glue.lookup_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        res = await glue.lookup_endpoint(napi.NominatimAPIAsync(), a)
 
         assert len(json.loads(res.output)) == 1
 
@@ -474,34 +444,32 @@ class TestSearchEndPointSearch:
         self.results = [napi.SearchResult(napi.SourceTable.PLACEX,
                                           ('place', 'thing'),
                                           napi.Point(1.0, 2.0))]
+
         async def _search(*args, **kwargs):
             return napi.SearchResults(self.results)
 
         monkeypatch.setattr(napi.NominatimAPIAsync, 'search', _search)
 
-
     @pytest.mark.asyncio
     async def test_search_free_text(self):
         a = FakeAdaptor()
         a.params['q'] = 'something'
 
-        res = await glue.search_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        res = await glue.search_endpoint(napi.NominatimAPIAsync(), a)
 
         assert len(json.loads(res.output)) == 1
 
-
     @pytest.mark.asyncio
     async def test_search_free_text_xml(self):
         a = FakeAdaptor()
         a.params['q'] = 'something'
         a.params['format'] = 'xml'
 
-        res = await glue.search_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        res = await glue.search_endpoint(napi.NominatimAPIAsync(), a)
 
         assert res.status == 200
         assert res.output.index('something') > 0
 
-
     @pytest.mark.asyncio
     async def test_search_free_and_structured(self):
         a = FakeAdaptor()
@@ -509,8 +477,7 @@ class TestSearchEndPointSearch:
         a.params['city'] = 'ignored'
 
         with pytest.raises(FakeError, match='^400 -- .*cannot be used together'):
-            res = await glue.search_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
-
+            await glue.search_endpoint(napi.NominatimAPIAsync(), a)
 
     @pytest.mark.asyncio
     @pytest.mark.parametrize('dedupe,numres', [(True, 1), (False, 2)])
@@ -521,7 +488,7 @@ class TestSearchEndPointSearch:
         if not dedupe:
             a.params['dedupe'] = '0'
 
-        res = await glue.search_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        res = await glue.search_endpoint(napi.NominatimAPIAsync(), a)
 
         assert len(json.loads(res.output)) == numres
 
@@ -533,18 +500,18 @@ class TestSearchEndPointSearchAddress:
         self.results = [napi.SearchResult(napi.SourceTable.PLACEX,
                                           ('place', 'thing'),
                                           napi.Point(1.0, 2.0))]
+
         async def _search(*args, **kwargs):
             return napi.SearchResults(self.results)
 
         monkeypatch.setattr(napi.NominatimAPIAsync, 'search_address', _search)
 
-
     @pytest.mark.asyncio
     async def test_search_structured(self):
         a = FakeAdaptor()
         a.params['street'] = 'something'
 
-        res = await glue.search_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        res = await glue.search_endpoint(napi.NominatimAPIAsync(), a)
 
         assert len(json.loads(res.output)) == 1
 
@@ -556,17 +523,17 @@ class TestSearchEndPointSearchCategory:
         self.results = [napi.SearchResult(napi.SourceTable.PLACEX,
                                           ('place', 'thing'),
                                           napi.Point(1.0, 2.0))]
+
         async def _search(*args, **kwargs):
             return napi.SearchResults(self.results)
 
         monkeypatch.setattr(napi.NominatimAPIAsync, 'search_category', _search)
 
-
     @pytest.mark.asyncio
     async def test_search_category(self):
         a = FakeAdaptor()
         a.params['q'] = '[shop=fog]'
 
-        res = await glue.search_endpoint(napi.NominatimAPIAsync(Path('/invalid')), a)
+        res = await glue.search_endpoint(napi.NominatimAPIAsync(), a)
 
         assert len(json.loads(res.output)) == 1