|
@@ -1,71 +0,0 @@
|
1
|
|
-from collections import defaultdict
|
2
|
|
-import mock
|
3
|
|
-from searx.engines import blekko_images
|
4
|
|
-from searx.testing import SearxTestCase
|
5
|
|
-
|
6
|
|
-
|
7
|
|
-class TestBlekkoImagesEngine(SearxTestCase):
|
8
|
|
-
|
9
|
|
- def test_request(self):
|
10
|
|
- query = 'test_query'
|
11
|
|
- dicto = defaultdict(dict)
|
12
|
|
- dicto['pageno'] = 0
|
13
|
|
- dicto['safesearch'] = 1
|
14
|
|
- params = blekko_images.request(query, dicto)
|
15
|
|
- self.assertIn('url', params)
|
16
|
|
- self.assertIn(query, params['url'])
|
17
|
|
- self.assertIn('blekko.com', params['url'])
|
18
|
|
- self.assertIn('page', params['url'])
|
19
|
|
-
|
20
|
|
- dicto['pageno'] = 1
|
21
|
|
- params = blekko_images.request(query, dicto)
|
22
|
|
- self.assertNotIn('page', params['url'])
|
23
|
|
-
|
24
|
|
- def test_response(self):
|
25
|
|
- self.assertRaises(AttributeError, blekko_images.response, None)
|
26
|
|
- self.assertRaises(AttributeError, blekko_images.response, [])
|
27
|
|
- self.assertRaises(AttributeError, blekko_images.response, '')
|
28
|
|
- self.assertRaises(AttributeError, blekko_images.response, '[]')
|
29
|
|
-
|
30
|
|
- response = mock.Mock(text='[]')
|
31
|
|
- self.assertEqual(blekko_images.response(response), [])
|
32
|
|
-
|
33
|
|
- json = """
|
34
|
|
- [
|
35
|
|
- {
|
36
|
|
- "c": 1,
|
37
|
|
- "page_url": "http://result_url.html",
|
38
|
|
- "title": "Photo title",
|
39
|
|
- "tn_url": "http://ts1.mm.bing.net/th?id=HN.608050619474382748&pid=15.1",
|
40
|
|
- "url": "http://result_image.jpg"
|
41
|
|
- },
|
42
|
|
- {
|
43
|
|
- "c": 2,
|
44
|
|
- "page_url": "http://companyorange.simpsite.nl/OSM",
|
45
|
|
- "title": "OSM",
|
46
|
|
- "tn_url": "http://ts2.mm.bing.net/th?id=HN.608048068264919461&pid=15.1",
|
47
|
|
- "url": "http://simpsite.nl/userdata2/58985/Home/OSM.bmp"
|
48
|
|
- },
|
49
|
|
- {
|
50
|
|
- "c": 3,
|
51
|
|
- "page_url": "http://invincible.webklik.nl/page/osm",
|
52
|
|
- "title": "OSM",
|
53
|
|
- "tn_url": "http://ts1.mm.bing.net/th?id=HN.608024514657649476&pid=15.1",
|
54
|
|
- "url": "http://www.webklik.nl/user_files/2009_09/65324/osm.gif"
|
55
|
|
- },
|
56
|
|
- {
|
57
|
|
- "c": 4,
|
58
|
|
- "page_url": "http://www.offshorenorway.no/event/companyDetail/id/12492",
|
59
|
|
- "title": "Go to OSM Offshore AS homepage",
|
60
|
|
- "tn_url": "http://ts2.mm.bing.net/th?id=HN.608054265899847285&pid=15.1",
|
61
|
|
- "url": "http://www.offshorenorway.no/firmalogo/OSM-logo.png"
|
62
|
|
- }
|
63
|
|
- ]
|
64
|
|
- """
|
65
|
|
- response = mock.Mock(text=json)
|
66
|
|
- results = blekko_images.response(response)
|
67
|
|
- self.assertEqual(type(results), list)
|
68
|
|
- self.assertEqual(len(results), 4)
|
69
|
|
- self.assertEqual(results[0]['title'], 'Photo title')
|
70
|
|
- self.assertEqual(results[0]['url'], 'http://result_url.html')
|
71
|
|
- self.assertEqual(results[0]['img_src'], 'http://result_image.jpg')
|