1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. from collections import defaultdict
  2. import mock
  3. from searx.engines import acgsou
  4. from searx.testing import SearxTestCase
  5. class TestAcgsouEngine(SearxTestCase):
  6. def test_request(self):
  7. query = 'test_query'
  8. dic = defaultdict(dict)
  9. dic['pageno'] = 1
  10. params = acgsou.request(query, dic)
  11. self.assertTrue('url' in params)
  12. self.assertTrue(query in params['url'])
  13. self.assertTrue('acgsou.com' in params['url'])
  14. def test_response(self):
  15. resp = mock.Mock(text='<html></html>')
  16. self.assertEqual(acgsou.response(resp), [])
  17. html = """
  18. <html>
  19. <table id="listTable" class="list_style table_fixed">
  20. <thead class="tcat">
  21. <tr>
  22. <th axis="string" class="l1 tableHeaderOver">test</th>
  23. <th axis="string" class="l2 tableHeaderOver">test</th>
  24. <th axis="string" class="l3 tableHeaderOver">test</th>
  25. <th axis="size" class="l4 tableHeaderOver">test</th>
  26. <th axis="number" class="l5 tableHeaderOver">test</th>
  27. <th axis="number" class="l6 tableHeaderOver">test</th>
  28. <th axis="number" class="l7 tableHeaderOver">test</th>
  29. <th axis="string" class="l8 tableHeaderOver">test</th>
  30. </tr>
  31. </thead>
  32. <tbody class="tbody" id="data_list">
  33. <tr class="alt1 ">
  34. <td nowrap="nowrap">date</td>
  35. <td><a href="category.html">testcategory</a></td>
  36. <td style="text-align:left;">
  37. <a href="show-torrentid.html" target="_blank">torrentname</a>
  38. </td>
  39. <td>1MB</td>
  40. <td nowrap="nowrap">
  41. <span class="bts_1">
  42. 29
  43. </span>
  44. </td>
  45. <td nowrap="nowrap">
  46. <span class="btl_1">
  47. 211
  48. </span>
  49. </td>
  50. <td nowrap="nowrap">
  51. <span class="btc_">
  52. 168
  53. </span>
  54. </td>
  55. <td><a href="random.html">user</a></td>
  56. </tr>
  57. </tbody>
  58. </table>
  59. </html>
  60. """
  61. resp = mock.Mock(text=html)
  62. results = acgsou.response(resp)
  63. self.assertEqual(type(results), list)
  64. self.assertEqual(len(results), 1)
  65. r = results[0]
  66. self.assertEqual(r['url'], 'http://www.acgsou.com/show-torrentid.html')
  67. self.assertEqual(r['content'], 'Category: "testcategory".')
  68. self.assertEqual(r['title'], 'torrentname')
  69. self.assertEqual(r['filesize'], 1048576)