test_acgsou.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. <table id="listTable" class="list_style table_fixed">
  19. <thead class="tcat">
  20. <tr>
  21. tablehead
  22. </tr>
  23. </thead>
  24. <tbody class="tbody" id="data_list">
  25. <tr class="alt1 ">
  26. <td nowrap="nowrap">date</td>
  27. <td><a href="category.html">testcategory</a></td>
  28. <td style="text-align:left;">
  29. <a href="show-torrentid.html" target="_blank">torrentname</a>
  30. </td>
  31. <td>1MB</td>
  32. <td nowrap="nowrap">
  33. <span class="bts_1">
  34. 29
  35. </span>
  36. </td>
  37. <td nowrap="nowrap">
  38. <span class="btl_1">
  39. 211
  40. </span>
  41. </td>
  42. <td nowrap="nowrap">
  43. <span class="btc_">
  44. 168
  45. </span>
  46. </td>
  47. <td><a href="random.html">user</a></td>
  48. </tr>
  49. </table>
  50. """
  51. resp = mock.Mock(text=html)
  52. results = acgsou.response(resp)
  53. self.assertEqual(type(results), list)
  54. self.assertEqual(len(results), 1)
  55. r = results[0]
  56. self.assertEqual(r['url'], 'https://www.acgsou.com/show-torrentid.html')
  57. self.assertEqual(r['content'], 'Category: "testcategory".')
  58. self.assertEqual(r['title'], 'torrentname')
  59. self.assertEqual(r['filesize'], 1048576)