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