on master help sign in
Photon's unit test
f703a77Cqoicebordel
searx/engines/photon.py+1−1
@@ -61,7 +61,7 @@ def response(resp):
61 continue
61 continue
62
62
63 # get title
63 # get title
64− title = properties['name']
64+ title = properties.get('name')
65
65
66 # get osm-type
66 # get osm-type
67 if properties.get('osm_type') == 'N':
67 if properties.get('osm_type') == 'N':
searx/tests/engines/test_photon.pynew file+166
@@ -0,0 +1,166 @@
1+# -*- coding: utf-8 -*-
2+from collections import defaultdict
3+import mock
4+from searx.engines import photon
5+from searx.testing import SearxTestCase
6+
7+
8+class TestPhotonEngine(SearxTestCase):
9+
10+ def test_request(self):
11+ query = 'test_query'
12+ dicto = defaultdict(dict)
13+ dicto['pageno'] = 1
14+ dicto['language'] = 'all'
15+ params = photon.request(query, dicto)
16+ self.assertIn('url', params)
17+ self.assertIn(query, params['url'])
18+ self.assertIn('photon.komoot.de', params['url'])
19+
20+ dicto['language'] = 'all'
21+ params = photon.request(query, dicto)
22+ self.assertNotIn('lang', params['url'])
23+
24+ dicto['language'] = 'al'
25+ params = photon.request(query, dicto)
26+ self.assertNotIn('lang', params['url'])
27+
28+ dicto['language'] = 'fr'
29+ params = photon.request(query, dicto)
30+ self.assertIn('fr', params['url'])
31+
32+ def test_response(self):
33+ self.assertRaises(AttributeError, photon.response, None)
34+ self.assertRaises(AttributeError, photon.response, [])
35+ self.assertRaises(AttributeError, photon.response, '')
36+ self.assertRaises(AttributeError, photon.response, '[]')
37+
38+ response = mock.Mock(text='{}')
39+ self.assertEqual(photon.response(response), [])
40+
41+ response = mock.Mock(text='{"data": []}')
42+ self.assertEqual(photon.response(response), [])
43+
44+ json = """
45+ {
46+ "features": [
47+ {
48+ "properties": {
49+ "osm_key": "waterway",
50+ "extent": [
51+ -1.4508446,
52+ 51.1614997,
53+ -1.4408036,
54+ 51.1525635
55+ ],
56+ "name": "This is the title",
57+ "state": "England",
58+ "osm_id": 114823817,
59+ "osm_type": "W",
60+ "osm_value": "river",
61+ "city": "Test Valley",
62+ "country": "United Kingdom"
63+ },
64+ "type": "Feature",
65+ "geometry": {
66+ "type": "Point",
67+ "coordinates": [
68+ -1.4458571,
69+ 51.1576661
70+ ]
71+ }
72+ },
73+ {
74+ "properties": {
75+ "osm_key": "place",
76+ "street": "Rue",
77+ "state": "Ile-de-France",
78+ "osm_id": 129211377,
79+ "osm_type": "R",
80+ "housenumber": "10",
81+ "postcode": "75011",
82+ "osm_value": "house",
83+ "city": "Paris",
84+ "country": "France"
85+ },
86+ "type": "Feature",
87+ "geometry": {
88+ "type": "Point",
89+ "coordinates": [
90+ 2.3725025,
91+ 48.8654481
92+ ]
93+ }
94+ },
95+ {
96+ "properties": {
97+ "osm_key": "amenity",
98+ "street": "Allée",
99+ "name": "Bibliothèque",
100+ "state": "Ile-de-France",
101+ "osm_id": 1028573132,
102+ "osm_type": "N",
103+ "postcode": "75001",
104+ "osm_value": "library",
105+ "city": "Paris",
106+ "country": "France"
107+ },
108+ "type": "Feature",
109+ "geometry": {
110+ "type": "Point",
111+ "coordinates": [
112+ 2.3445634,
113+ 48.862494
114+ ]
115+ }
116+ },
117+ {
118+ "properties": {
119+ "osm_key": "amenity",
120+ "osm_id": 1028573132,
121+ "osm_type": "Y",
122+ "postcode": "75001",
123+ "osm_value": "library",
124+ "city": "Paris",
125+ "country": "France"
126+ },
127+ "type": "Feature",
128+ "geometry": {
129+ "type": "Point",
130+ "coordinates": [
131+ 2.3445634,
132+ 48.862494
133+ ]
134+ }
135+ },
136+ {
137+ }
138+ ],
139+ "type": "FeatureCollection"
140+ }
141+ """
142+ response = mock.Mock(text=json)
143+ results = photon.response(response)
144+ self.assertEqual(type(results), list)
145+ self.assertEqual(len(results), 3)
146+ self.assertEqual(results[0]['title'], 'This is the title')
147+ self.assertEqual(results[0]['content'], '')
148+ self.assertEqual(results[0]['longitude'], -1.4458571)
149+ self.assertEqual(results[0]['latitude'], 51.1576661)
150+ self.assertIn(-1.4508446, results[0]['boundingbox'])
151+ self.assertIn(51.1614997, results[0]['boundingbox'])
152+ self.assertIn(-1.4408036, results[0]['boundingbox'])
153+ self.assertIn(51.1525635, results[0]['boundingbox'])
154+ self.assertIn('type', results[0]['geojson'])
155+ self.assertEqual(results[0]['geojson']['type'], 'Point')
156+ self.assertEqual(results[0]['address'], None)
157+ self.assertEqual(results[0]['osm']['type'], 'way')
158+ self.assertEqual(results[0]['osm']['id'], 114823817)
159+ self.assertEqual(results[0]['url'], 'https://openstreetmap.org/way/114823817')
160+ self.assertEqual(results[1]['osm']['type'], 'relation')
161+ self.assertEqual(results[2]['address']['name'], u'Bibliothèque')
162+ self.assertEqual(results[2]['address']['house_number'], None)
163+ self.assertEqual(results[2]['address']['locality'], 'Paris')
164+ self.assertEqual(results[2]['address']['postcode'], '75001')
165+ self.assertEqual(results[2]['address']['country'], 'France')
166+ self.assertEqual(results[2]['osm']['type'], 'node')
searx/tests/test_engines.py+1
@@ -21,6 +21,7 @@ from searx.tests.engines.test_kickass import * # noqa
21from searx.tests.engines.test_mediawiki import * # noqa
21from searx.tests.engines.test_mediawiki import * # noqa
22from searx.tests.engines.test_mixcloud import * # noqa
22from searx.tests.engines.test_mixcloud import * # noqa
23from searx.tests.engines.test_openstreetmap import * # noqa
23from searx.tests.engines.test_openstreetmap import * # noqa
24+from searx.tests.engines.test_photon import * # noqa
24from searx.tests.engines.test_piratebay import * # noqa
25from searx.tests.engines.test_piratebay import * # noqa
25from searx.tests.engines.test_searchcode_code import * # noqa
26from searx.tests.engines.test_searchcode_code import * # noqa
26from searx.tests.engines.test_searchcode_doc import * # noqa
27from searx.tests.engines.test_searchcode_doc import * # noqa