|
@@ -0,0 +1,57 @@
|
|
1
|
+from collections import defaultdict
|
|
2
|
+import mock
|
|
3
|
+from searx.engines import www1x
|
|
4
|
+from searx.testing import SearxTestCase
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+class TestWww1xEngine(SearxTestCase):
|
|
8
|
+
|
|
9
|
+ def test_request(self):
|
|
10
|
+ query = 'test_query'
|
|
11
|
+ params = www1x.request(query, defaultdict(dict))
|
|
12
|
+ self.assertTrue('url' in params)
|
|
13
|
+ self.assertTrue(query in params['url'])
|
|
14
|
+ self.assertTrue('1x.com' in params['url'])
|
|
15
|
+
|
|
16
|
+ def test_response(self):
|
|
17
|
+ self.assertRaises(AttributeError, www1x.response, None)
|
|
18
|
+ self.assertRaises(AttributeError, www1x.response, [])
|
|
19
|
+ self.assertRaises(AttributeError, www1x.response, '')
|
|
20
|
+ self.assertRaises(AttributeError, www1x.response, '[]')
|
|
21
|
+
|
|
22
|
+ response = mock.Mock(text='<html></html>')
|
|
23
|
+ self.assertEqual(www1x.response(response), [])
|
|
24
|
+ html = """
|
|
25
|
+ <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE characters
|
|
26
|
+ [
|
|
27
|
+ <!ELEMENT characters (character*) >
|
|
28
|
+ <!ELEMENT character (#PCDATA ) >
|
|
29
|
+
|
|
30
|
+ <!ENTITY iexcl "¡" >
|
|
31
|
+ <!ENTITY cent "¢" >
|
|
32
|
+ <!ENTITY pound "£" >
|
|
33
|
+ ]
|
|
34
|
+ ><root><searchresult><![CDATA[<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
35
|
+ <tr>
|
|
36
|
+ <td style="min-width: 220px;" valign="top">
|
|
37
|
+ <div style="font-size: 30px; margin: 0px 0px 20px 0px;">Photos</div>
|
|
38
|
+ <div>
|
|
39
|
+ <a href="/photo/123456" class="dynamiclink">
|
|
40
|
+<img border="0" class="searchresult" src="/images/user/testimage-123456.jpg" style="width: 125px; height: 120px;">
|
|
41
|
+ </a>
|
|
42
|
+ <a title="sjoerd lammers street photography" href="/member/sjoerdlammers" class="dynamiclink">
|
|
43
|
+<img border="0" class="searchresult" src="/images/profile/60c48b394c677d2fa4d9e7d263aabf44-square.jpg">
|
|
44
|
+ </a>
|
|
45
|
+ </div>
|
|
46
|
+ </td>
|
|
47
|
+ </table>
|
|
48
|
+ ]]></searchresult></root>
|
|
49
|
+ """
|
|
50
|
+ response = mock.Mock(text=html)
|
|
51
|
+ results = www1x.response(response)
|
|
52
|
+ self.assertEqual(type(results), list)
|
|
53
|
+ self.assertEqual(len(results), 1)
|
|
54
|
+ self.assertEqual(results[0]['url'], 'http://1x.com/photo/123456')
|
|
55
|
+ self.assertEqual(results[0]['thumbnail_src'], 'http://1x.com/images/user/testimage-123456.jpg')
|
|
56
|
+ self.assertEqual(results[0]['content'], '')
|
|
57
|
+ self.assertEqual(results[0]['template'], 'images.html')
|