logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git

test_doku.py (3785B)


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