@@ -0,0 +1,199 @@
1+# -*- coding: utf-8 -*-
2+from collections import defaultdict
4+from searx.engines import openstreetmap
5+from searx.testing import SearxTestCase
8+class TestOpenstreetmapEngine(SearxTestCase):
10+ def test_request(self):
12+ dicto = defaultdict(dict)
14+ params = openstreetmap.request(query, dicto)
15+ self.assertIn('url', params)
16+ self.assertIn(query, params['url'])
17+ self.assertIn('openstreetmap.org', params['url'])
19+ def test_response(self):
20+ self.assertRaises(AttributeError, openstreetmap.response, None)
21+ self.assertRaises(AttributeError, openstreetmap.response, [])
22+ self.assertRaises(AttributeError, openstreetmap.response, '')
23+ self.assertRaises(AttributeError, openstreetmap.response, '[]')
25+ response = mock.Mock(text='{}')
26+ self.assertEqual(openstreetmap.response(response), [])
28+ response = mock.Mock(text='{"data": []}')
29+ self.assertEqual(openstreetmap.response(response), [])
34+ "place_id": "127732055",
35+ "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright",
36+ "osm_type": "relation",
46+ "display_name": "This is the title",
49+ "importance": 0.96893459932191,
50+ "icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png",
54+ "state": "Île-de-France",
72+ response = mock.Mock(text=json)
73+ results = openstreetmap.response(response)
74+ self.assertEqual(type(results), list)
75+ self.assertEqual(len(results), 1)
76+ self.assertEqual(results[0]['title'], 'This is the title')
77+ self.assertEqual(results[0]['url'], 'https://openstreetmap.org/relation/7444')
78+ self.assertIn('coordinates', results[0]['geojson'])
79+ self.assertEqual(results[0]['geojson']['coordinates'][0][0][0], 2.224122)
80+ self.assertEqual(results[0]['geojson']['coordinates'][0][0][1], 48.854199)
81+ self.assertEqual(results[0]['address'], None)
82+ self.assertIn('48.8155755', results[0]['boundingbox'])
83+ self.assertIn('48.902156', results[0]['boundingbox'])
84+ self.assertIn('2.224122', results[0]['boundingbox'])
85+ self.assertIn('2.4697602', results[0]['boundingbox'])
90+ "place_id": "127732055",
91+ "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright",
92+ "osm_type": "relation",
100+ "lat": "48.8565056",
102+ "display_name": "This is the title",
105+ "importance": 0.96893459932191,
106+ "icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png",
110+ "state": "Île-de-France",
111+ "country": "France",
112+ "country_code": "fr",
113+ "address29": "Address"
128+ "place_id": "127732055",
129+ "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright",
130+ "osm_type": "relation",
138+ "lat": "48.8565056",
140+ "display_name": "This is the title",
143+ "importance": 0.96893459932191,
144+ "icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png",
148+ "state": "Île-de-France",
149+ "country": "France",
151+ "country_code": "fr"
166+ "place_id": "127732055",
167+ "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright",
176+ "lat": "48.8565056",
178+ "display_name": "This is the title",
181+ "importance": 0.96893459932191,
182+ "icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png",
186+ "state": "Île-de-France",
187+ "country": "France",
188+ "country_code": "fr",
189+ "address29": "Address"
194+ response = mock.Mock(text=json)
195+ results = openstreetmap.response(response)
196+ self.assertEqual(type(results), list)
197+ self.assertEqual(len(results), 3)
198+ self.assertIn('48.8565056', results[2]['geojson']['coordinates'])
199+ self.assertIn('2.3521334', results[2]['geojson']['coordinates'])