logo

searx

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

test_startpage.py (5753B)


  1. # -*- coding: utf-8 -*-
  2. from collections import defaultdict
  3. import mock
  4. from searx.engines import startpage
  5. from searx.testing import SearxTestCase
  6. class TestStartpageEngine(SearxTestCase):
  7. def test_request(self):
  8. query = 'test_query'
  9. dicto = defaultdict(dict)
  10. dicto['pageno'] = 1
  11. dicto['language'] = 'fr_FR'
  12. params = startpage.request(query, dicto)
  13. self.assertIn('url', params)
  14. self.assertIn('startpage.com', params['url'])
  15. self.assertIn('data', params)
  16. self.assertIn('query', params['data'])
  17. self.assertIn(query, params['data']['query'])
  18. self.assertIn('with_language', params['data'])
  19. self.assertIn('lang_fr', params['data']['with_language'])
  20. def test_response(self):
  21. self.assertRaises(AttributeError, startpage.response, None)
  22. self.assertRaises(AttributeError, startpage.response, [])
  23. self.assertRaises(AttributeError, startpage.response, '')
  24. self.assertRaises(AttributeError, startpage.response, '[]')
  25. response = mock.Mock(text='<html></html>')
  26. self.assertEqual(startpage.response(response), [])
  27. html = """
  28. <li class="search-result search-item">
  29. <h3>
  30. <a href='http://this.should.be.the.link/' id='title_2' name='title_2' >
  31. This should be the title
  32. </a>
  33. <span id='title_stars_2' name='title_stars_2'> </span>
  34. </h3>
  35. <p class="search-item__body">
  36. This should be the content.
  37. </p>
  38. <p>
  39. <span class='url'>www.speed<b>test</b>.net/fr/
  40. </span>
  41. -
  42. <A class="proxy" id="proxy_link" HREF="https://ixquick-proxy.com/do/spg/proxy?ep=&edata=&ek=&ekdata="
  43. class='proxy'>
  44. Navigation avec Ixquick Proxy
  45. </A>
  46. -
  47. <A HREF="https://ixquick-proxy.com/do/spg/highlight.pl?l=francais&c=hf&cat=web&q=test&rl=NONE&rid=
  48. &hlq=https://startpage.com/do/search&mtabp=-1&mtcmd=process_search&mtlanguage=francais&mtengine0=
  49. &mtcat=web&u=http:%2F%2Fwww.speedtest.net%2Ffr%2F" class='proxy'>
  50. Mis en surbrillance
  51. </A>
  52. </p>
  53. </li>
  54. """
  55. response = mock.Mock(text=html.encode('utf-8'))
  56. results = startpage.response(response)
  57. self.assertEqual(type(results), list)
  58. self.assertEqual(len(results), 1)
  59. self.assertEqual(results[0]['title'], 'This should be the title')
  60. self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/')
  61. self.assertEqual(results[0]['content'], 'This should be the content.')
  62. html = """
  63. <li class="search-result search-item">
  64. <h3>
  65. <a href='http://www.google.com/aclk?sa=l&ai=C' id='title_2' name='title_2' >
  66. This should be the title
  67. </a>
  68. <span id='title_stars_2' name='title_stars_2'> </span>
  69. </h3>
  70. <p class="search-item__body">
  71. This should be the content.
  72. </p>
  73. <p>
  74. <span class='url'>www.speed<b>test</b>.net/fr/
  75. </span>
  76. -
  77. <A class="proxy" id="proxy_link" HREF="https://ixquick-proxy.com/do/spg/proxy?ep=&edata=&ek=&ekdata="
  78. class='proxy'>
  79. Navigation avec Ixquick Proxy
  80. </A>
  81. -
  82. <A HREF="https://ixquick-proxy.com/do/spg/highlight.pl?l=francais&c=hf&cat=web&q=test&rl=NONE&rid=
  83. &hlq=https://startpage.com/do/search&mtabp=-1&mtcmd=process_search&mtlanguage=francais&mtengine0=
  84. &mtcat=web&u=http:%2F%2Fwww.speedtest.net%2Ffr%2F" class='proxy'>
  85. Mis en surbrillance
  86. </A>
  87. </p>
  88. </li>
  89. <li class="search-result search-item">
  90. <h3>
  91. <span id='title_stars_2' name='title_stars_2'> </span>
  92. </h3>
  93. <p class="search-item__body">
  94. This should be the content.
  95. </p>
  96. <p>
  97. <span class='url'>www.speed<b>test</b>.net/fr/
  98. </span>
  99. </p>
  100. </li>
  101. <li class="search-result search-item">
  102. <h3>
  103. <a href='http://this.should.be.the.link/' id='title_2' name='title_2' >
  104. This should be the title
  105. </a>
  106. <span id='title_stars_2' name='title_stars_2'> </span>
  107. </h3>
  108. <p>
  109. <span class='url'>www.speed<b>test</b>.net/fr/
  110. </span>
  111. -
  112. <A class="proxy" id="proxy_link" HREF="https://ixquick-proxy.com/do/spg/proxy?ep=&edata=&ek=&ekdata="
  113. class='proxy'>
  114. Navigation avec Ixquick Proxy
  115. </A>
  116. -
  117. <A HREF="https://ixquick-proxy.com/do/spg/highlight.pl?l=francais&c=hf&cat=web&q=test&rl=NONE&rid=
  118. &hlq=https://startpage.com/do/search&mtabp=-1&mtcmd=process_search&mtlanguage=francais&mtengine0=
  119. &mtcat=web&u=http:%2F%2Fwww.speedtest.net%2Ffr%2F" class='proxy'>
  120. Mis en surbrillance
  121. </A>
  122. </p>
  123. </li>
  124. """
  125. response = mock.Mock(text=html.encode('utf-8'))
  126. results = startpage.response(response)
  127. self.assertEqual(type(results), list)
  128. self.assertEqual(len(results), 1)
  129. self.assertEqual(results[0]['content'], '')