logo

searx

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

test_archlinux.py (3629B)


  1. from collections import defaultdict
  2. import mock
  3. from searx.engines import archlinux
  4. from searx.testing import SearxTestCase
  5. domains = {
  6. 'en': 'https://wiki.archlinux.org',
  7. 'de': 'https://wiki.archlinux.de',
  8. 'fr': 'https://wiki.archlinux.fr',
  9. 'ja': 'https://wiki.archlinuxjp.org',
  10. 'ro': 'http://wiki.archlinux.ro',
  11. 'tr': 'http://archtr.org/wiki'
  12. }
  13. class TestArchLinuxEngine(SearxTestCase):
  14. def test_request(self):
  15. query = 'test_query'
  16. dic = defaultdict(dict)
  17. dic['pageno'] = 1
  18. dic['language'] = 'en-US'
  19. params = archlinux.request(query, dic)
  20. self.assertTrue('url' in params)
  21. self.assertTrue(query in params['url'])
  22. self.assertTrue('wiki.archlinux.org' in params['url'])
  23. for lang, name in archlinux.main_langs:
  24. dic['language'] = lang
  25. params = archlinux.request(query, dic)
  26. self.assertTrue(name in params['url'])
  27. for lang, domain in domains.items():
  28. dic['language'] = lang
  29. params = archlinux.request(query, dic)
  30. self.assertTrue(domain in params['url'])
  31. def test_response(self):
  32. response = mock.Mock(text='<html></html>',
  33. search_params={'language': 'en_US'})
  34. self.assertEqual(archlinux.response(response), [])
  35. html = """
  36. <ul class="mw-search-results">
  37. <li>
  38. <div class="mw-search-result-heading">
  39. <a href="/index.php/ATI" title="ATI">ATI</a>
  40. </div>
  41. <div class="searchresult">
  42. Lorem ipsum dolor sit amet
  43. </div>
  44. <div class="mw-search-result-data">
  45. 30 KB (4,630 words) - 19:04, 17 March 2016</div>
  46. </li>
  47. <li>
  48. <div class="mw-search-result-heading">
  49. <a href="/index.php/Frequently_asked_questions" title="Frequently asked questions">
  50. Frequently asked questions
  51. </a>
  52. </div>
  53. <div class="searchresult">
  54. CPUs with AMDs instruction set "AMD64"
  55. </div>
  56. <div class="mw-search-result-data">
  57. 17 KB (2,722 words) - 20:13, 21 March 2016
  58. </div>
  59. </li>
  60. <li>
  61. <div class="mw-search-result-heading">
  62. <a href="/index.php/CPU_frequency_scaling" title="CPU frequency scaling">CPU frequency scaling</a>
  63. </div>
  64. <div class="searchresult">
  65. ondemand for AMD and older Intel CPU
  66. </div>
  67. <div class="mw-search-result-data">
  68. 15 KB (2,319 words) - 23:46, 16 March 2016
  69. </div>
  70. </li>
  71. </ul>
  72. """
  73. expected = [
  74. {
  75. 'title': 'ATI',
  76. 'url': 'https://wiki.archlinux.org/index.php/ATI'
  77. },
  78. {
  79. 'title': 'Frequently asked questions',
  80. 'url': 'https://wiki.archlinux.org/index.php/Frequently_asked_questions'
  81. },
  82. {
  83. 'title': 'CPU frequency scaling',
  84. 'url': 'https://wiki.archlinux.org/index.php/CPU_frequency_scaling'
  85. }
  86. ]
  87. response = mock.Mock(text=html)
  88. response.search_params = {
  89. 'language': 'en_US'
  90. }
  91. results = archlinux.response(response)
  92. self.assertEqual(type(results), list)
  93. self.assertEqual(len(results), len(expected))
  94. i = 0
  95. for exp in expected:
  96. res = results[i]
  97. i += 1
  98. for key, value in exp.items():
  99. self.assertEqual(res[key], value)