|
@@ -0,0 +1,59 @@
|
|
1
|
+from collections import defaultdict
|
|
2
|
+import mock
|
|
3
|
+from searx.engines import digbt
|
|
4
|
+from searx.testing import SearxTestCase
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+class TestDigBTEngine(SearxTestCase):
|
|
8
|
+
|
|
9
|
+ def test_request(self):
|
|
10
|
+ query = 'test_query'
|
|
11
|
+ dicto = defaultdict(dict)
|
|
12
|
+ dicto['pageno'] = 0
|
|
13
|
+ params = digbt.request(query, dicto)
|
|
14
|
+ self.assertIn('url', params)
|
|
15
|
+ self.assertIn(query, params['url'])
|
|
16
|
+ self.assertIn('digbt.org', params['url'])
|
|
17
|
+
|
|
18
|
+ def test_response(self):
|
|
19
|
+ self.assertRaises(AttributeError, digbt.response, None)
|
|
20
|
+ self.assertRaises(AttributeError, digbt.response, [])
|
|
21
|
+ self.assertRaises(AttributeError, digbt.response, '')
|
|
22
|
+ self.assertRaises(AttributeError, digbt.response, '[]')
|
|
23
|
+
|
|
24
|
+ response = mock.Mock(content='<html></html>')
|
|
25
|
+ self.assertEqual(digbt.response(response), [])
|
|
26
|
+
|
|
27
|
+ html = """
|
|
28
|
+ <table class="table">
|
|
29
|
+ <tr><td class="x-item">
|
|
30
|
+ <div>
|
|
31
|
+ <a title="The Big Bang Theory" class="title" href="/The-Big-Bang-Theory-d2.html">The Big Bang Theory</a>
|
|
32
|
+ <span class="ctime"><span style="color:red;">4 hours ago</span></span>
|
|
33
|
+ </div>
|
|
34
|
+ <div class="files">
|
|
35
|
+ <ul>
|
|
36
|
+ <li>The Big Bang Theory 2.9 GB</li>
|
|
37
|
+ <li>....</li>
|
|
38
|
+ </ul>
|
|
39
|
+ </div>
|
|
40
|
+ <div class="tail">
|
|
41
|
+ Files: 1 Size: 2.9 GB Downloads: 1 Updated: <span style="color:red;">4 hours ago</span>
|
|
42
|
+
|
|
43
|
+ <a class="title" href="magnet:?xt=urn:btih:a&dn=The+Big+Bang+Theory">
|
|
44
|
+ <span class="glyphicon glyphicon-magnet"></span> magnet-link
|
|
45
|
+ </a>
|
|
46
|
+
|
|
47
|
+ </div>
|
|
48
|
+ </td></tr>
|
|
49
|
+ </table>
|
|
50
|
+ """
|
|
51
|
+ response = mock.Mock(content=html)
|
|
52
|
+ results = digbt.response(response)
|
|
53
|
+ self.assertEqual(type(results), list)
|
|
54
|
+ self.assertEqual(len(results), 1)
|
|
55
|
+ self.assertEqual(results[0]['title'], 'The Big Bang Theory')
|
|
56
|
+ self.assertEqual(results[0]['url'], 'https://digbt.org/The-Big-Bang-Theory-d2.html')
|
|
57
|
+ self.assertEqual(results[0]['content'], 'The Big Bang Theory 2.9 GB ....')
|
|
58
|
+ self.assertEqual(results[0]['filesize'], 3113851289)
|
|
59
|
+ self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:a&dn=The+Big+Bang+Theory')
|