logo

searx

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

test_nyaa.py (5085B)


  1. from collections import defaultdict
  2. import mock
  3. from searx.engines import nyaa
  4. from searx.testing import SearxTestCase
  5. class TestNyaaEngine(SearxTestCase):
  6. def test_request(self):
  7. query = 'test_query'
  8. dic = defaultdict(dict)
  9. dic['pageno'] = 1
  10. params = nyaa.request(query, dic)
  11. self.assertTrue('url' in params)
  12. self.assertTrue(query in params['url'])
  13. self.assertTrue('nyaa.si' in params['url'])
  14. def test_response(self):
  15. resp = mock.Mock(text='<html></html>')
  16. self.assertEqual(nyaa.response(resp), [])
  17. html = """
  18. <table class="table table-bordered table-hover table-striped torrent-list">
  19. <thead>
  20. <tr>
  21. <th class="hdr-category text-center" style="width:80px;">
  22. <div>Category</div>
  23. </th>
  24. <th class="hdr-name" style="width:auto;">
  25. <div>Name</div>
  26. </th>
  27. <th class="hdr-comments sorting text-center" title="Comments" style="width:50px;">
  28. <a href="/?f=0&amp;c=0_0&amp;q=Death+Parade&amp;s=comments&amp;o=desc"></a>
  29. <i class="fa fa-comments-o"></i>
  30. </th>
  31. <th class="hdr-link text-center" style="width:70px;">
  32. <div>Link</div>
  33. </th>
  34. <th class="hdr-size sorting text-center" style="width:100px;">
  35. <a href="/?f=0&amp;c=0_0&amp;q=Death+Parade&amp;s=size&amp;o=desc"></a>
  36. <div>Size</div>
  37. </th>
  38. <th class="hdr-date sorting_desc text-center" title="In local time" style="width:140px;">
  39. <a href="/?f=0&amp;c=0_0&amp;q=Death+Parade&amp;s=id&amp;o=asc"></a>
  40. <div>Date</div>
  41. </th>
  42. <th class="hdr-seeders sorting text-center" title="Seeders" style="width:50px;">
  43. <a href="/?f=0&amp;c=0_0&amp;q=Death+Parade&amp;s=seeders&amp;o=desc"></a>
  44. <i class="fa fa-arrow-up" aria-hidden="true"></i>
  45. </th>
  46. <th class="hdr-leechers sorting text-center" title="Leechers" style="width:50px;">
  47. <a href="/?f=0&amp;c=0_0&amp;q=Death+Parade&amp;s=leechers&amp;o=desc"></a>
  48. <i class="fa fa-arrow-down" aria-hidden="true"></i>
  49. </th>
  50. <th class="hdr-downloads sorting text-center" title="Completed downloads" style="width:50px;">
  51. <a href="/?f=0&amp;c=0_0&amp;q=Death+Parade&amp;s=downloads&amp;o=desc"></a>
  52. <i class="fa fa-check" aria-hidden="true"></i>
  53. </th>
  54. </tr>
  55. </thead>
  56. <tbody>
  57. <tr class="default">
  58. <td style="padding:0 4px;">
  59. <a href="/?c=1_2" title="Anime - English-translated">
  60. <img src="/static/img/icons/nyaa/1_2.png" alt="Anime - English-translated">
  61. </a>
  62. </td>
  63. <td colspan="2">
  64. <a href="/view/1" title="Sample title 1">Sample title 1</a>
  65. </td>
  66. <td class="text-center" style="white-space: nowrap;">
  67. <a href="/download/1.torrent"><i class="fa fa-fw fa-download"></i></a>
  68. <a href="magnet:?xt=urn:btih:2"><i class="fa fa-fw fa-magnet"></i></a>
  69. </td>
  70. <td class="text-center">723.7 MiB</td>
  71. <td class="text-center" data-timestamp="1503307456" title="1 week 3
  72. days 9 hours 44 minutes 39 seconds ago">2017-08-21 11:24</td>
  73. <td class="text-center" style="color: green;">1</td>
  74. <td class="text-center" style="color: red;">3</td>
  75. <td class="text-center">12</td>
  76. </tr>
  77. <tr class="default">
  78. <td style="padding:0 4px;">
  79. <a href="/?c=1_2" title="Anime - English-translated">
  80. <img src="/static/img/icons/nyaa/1_2.png" alt="Anime - English-translated">
  81. </a>
  82. </td>
  83. <td colspan="2">
  84. <a href="/view/2" title="Sample title 2">Sample title 2</a>
  85. </td>
  86. <td class="text-center" style="white-space: nowrap;">
  87. <a href="magnet:?xt=urn:btih:2"><i class="fa fa-fw fa-magnet"></i></a>
  88. </td>
  89. <td class="text-center">8.2 GiB</td>
  90. <td class="text-center" data-timestamp="1491608400" title="4 months 3
  91. weeks 4 days 19 hours 28 minutes 55 seconds ago">2017-04-08 01:40</td>
  92. <td class="text-center" style="color: green;">10</td>
  93. <td class="text-center" style="color: red;">1</td>
  94. <td class="text-center">206</td>
  95. </tr>
  96. </tbody>
  97. </table>
  98. """
  99. resp = mock.Mock(text=html)
  100. results = nyaa.response(resp)
  101. self.assertEqual(type(results), list)
  102. self.assertEqual(len(results), 2)
  103. r = results[0]
  104. self.assertTrue(r['url'].find('1') >= 0)
  105. self.assertTrue(r['torrentfile'].find('1.torrent') >= 0)
  106. self.assertTrue(r['content'].find('Anime - English-translated') >= 0)
  107. self.assertTrue(r['content'].find('Downloaded 12 times.') >= 0)
  108. self.assertEqual(r['title'], 'Sample title 1')
  109. self.assertEqual(r['seed'], 1)
  110. self.assertEqual(r['leech'], 3)
  111. self.assertEqual(r['filesize'], 723700000)
  112. r = results[1]
  113. self.assertTrue(r['url'].find('2') >= 0)
  114. self.assertTrue(r['magnetlink'].find('magnet:') >= 0)