@@ -0,0 +1,79 @@
1+# -*- coding: utf-8 -*-
2+from collections import defaultdict
3+import mock
4+from searx.engines import doku
5+from searx.testing import SearxTestCase
6+
7+
8+class TestDokuEngine(SearxTestCase):
9+
10+ def test_request(self):
11+ query = 'test_query'
12+ dicto = defaultdict(dict)
13+ params = doku.request(query, dicto)
14+ self.assertIn('url', params)
15+ self.assertIn(query, params['url'])
16+
17+ def test_response(self):
18+ self.assertRaises(AttributeError, doku.response, None)
19+ self.assertRaises(AttributeError, doku.response, [])
20+ self.assertRaises(AttributeError, doku.response, '')
21+ self.assertRaises(AttributeError, doku.response, '[]')
22+
23+ response = mock.Mock(text='<html></html>')
24+ self.assertEqual(doku.response(response), [])
25+
26+ html = u"""
27+ <div class="search_quickresult">
28+ <h3>Pages trouvées :</h3>
29+ <ul class="search_quickhits">
30+ <li> <a href="/xfconf-query" class="wikilink1" title="xfconf-query">xfconf-query</a></li>
31+ </ul>
32+ <div class="clearer"></div>
33+ </div>
34+ """
35+ response = mock.Mock(text=html)
36+ results = doku.response(response)
37+ expected = [{'content': '', 'title': 'xfconf-query', 'url': 'http://localhost:8090/xfconf-query'}]
38+ self.assertEqual(doku.response(response), expected)
39+
40+ html = u"""
41+ <dl class="search_results">
42+ <dt><a href="/xvnc?s[]=query" class="wikilink1" title="xvnc">xvnc</a>: 40 Occurrences trouvées</dt>
43+ <dd>er = /usr/bin/Xvnc
44+ server_args = -inetd -<strong class="search_hit">query</strong> localhost -geometry 640x480 ... er = /usr/bin/Xvnc
45+ server_args = -inetd -<strong class="search_hit">query</strong> localhost -geometry 800x600 ... er = /usr/bin/Xvnc
46+ server_args = -inetd -<strong class="search_hit">query</strong> localhost -geometry 1024x768 ... er = /usr/bin/Xvnc
47+ server_args = -inetd -<strong class="search_hit">query</strong> localhost -geometry 1280x1024 -depth 8 -Sec</dd>
48+ <dt><a href="/postfix_mysql_tls_sasl_1404?s[]=query"
49+ class="wikilink1"
50+ title="postfix_mysql_tls_sasl_1404">postfix_mysql_tls_sasl_1404</a>: 14 Occurrences trouvées</dt>
51+ <dd>tdepasse
52+ hosts = 127.0.0.1
53+ dbname = postfix
54+ <strong class="search_hit">query</strong> = SELECT goto FROM alias WHERE address='%s' AND a... tdepasse
55+ hosts = 127.0.0.1
56+ dbname = postfix
57+ <strong class="search_hit">query</strong> = SELECT domain FROM domain WHERE domain='%s'
58+ #optional <strong class="search_hit">query</strong> to use when relaying for backup MX
59+ #<strong class="search_hit">query</strong> = SELECT domain FROM domain WHERE domain='%s' and backupmx =</dd>
60+ <dt><a href="/bind9?s[]=query" class="wikilink1" title="bind9">bind9</a>: 12 Occurrences trouvées</dt>
61+ <dd> printcmd
62+;; Got answer:
63+;; ->>HEADER<<- opcode: <strong class="search_hit">QUERY</strong>, status: NOERROR, id: 13427
64+;; flags: qr aa rd ra; <strong class="search_hit">QUERY</strong>: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
65+
66+[...]
67+
68+;; <strong class="search_hit">Query</strong> time: 1 msec
69+;; SERVER: 127.0.0.1#53(127.0.0.1)
70+;... par la requête (<strong class="search_hit">Query</strong> time) , entre la première et la deuxième requête.</dd>
71+ </dl>
72+ """
73+ response = mock.Mock(text=html)
74+ results = doku.response(response)
75+ self.assertEqual(type(results), list)
76+ self.assertEqual(len(results), 3)
77+ self.assertEqual(results[0]['title'], 'xvnc')
78+# FIXME self.assertEqual(results[0]['url'], u'http://this.should.be.the.link/ű')
79+# FIXME self.assertEqual(results[0]['content'], 'This should be the content.')