test_subtitleseeker.py 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. from collections import defaultdict
  2. import mock
  3. from searx.engines import subtitleseeker
  4. from searx.testing import SearxTestCase
  5. class TestSubtitleseekerEngine(SearxTestCase):
  6. def test_request(self):
  7. query = 'test_query'
  8. dicto = defaultdict(dict)
  9. dicto['pageno'] = 1
  10. params = subtitleseeker.request(query, dicto)
  11. self.assertTrue('url' in params)
  12. self.assertTrue(query in params['url'])
  13. self.assertTrue('subtitleseeker.com' in params['url'])
  14. def test_response(self):
  15. dicto = defaultdict(dict)
  16. dicto['language'] = 'fr_FR'
  17. response = mock.Mock(search_params=dicto)
  18. self.assertRaises(AttributeError, subtitleseeker.response, None)
  19. self.assertRaises(AttributeError, subtitleseeker.response, [])
  20. self.assertRaises(AttributeError, subtitleseeker.response, '')
  21. self.assertRaises(AttributeError, subtitleseeker.response, '[]')
  22. response = mock.Mock(text='<html></html>', search_params=dicto)
  23. self.assertEqual(subtitleseeker.response(response), [])
  24. html = """
  25. <div class="boxRows">
  26. <div class="boxRowsInner" style="width:600px;">
  27. <img src="http://static.subtitleseeker.com/images/movie.gif"
  28. style="width:16px; height:16px;" class="icon">
  29. <a href="http://this.is.the.url/"
  30. class="blue" title="Title subtitle" >
  31. This is the Title
  32. </a>
  33. <br><br>
  34. <span class="f10b grey-dark arial" style="padding:0px 0px 5px 20px">
  35. "Alternative Title"
  36. </span>
  37. </div>
  38. <div class="boxRowsInner f12b red" style="width:70px;">
  39. 1998
  40. </div>
  41. <div class="boxRowsInner grey-web f12" style="width:120px;">
  42. <img src="http://static.subtitleseeker.com/images/basket_put.png"
  43. style="width:16px; height:16px;" class="icon">
  44. 1039 Subs
  45. </div>
  46. <div class="boxRowsInner grey-web f10" style="width:130px;">
  47. <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
  48. style="width:16px; height:16px;" class="icon">
  49. 1 hours ago
  50. </div>
  51. <div class="clear"></div>
  52. </div>
  53. """
  54. response = mock.Mock(text=html, search_params=dicto)
  55. results = subtitleseeker.response(response)
  56. self.assertEqual(type(results), list)
  57. self.assertEqual(len(results), 1)
  58. self.assertEqual(results[0]['title'], 'This is the Title')
  59. self.assertEqual(results[0]['url'], 'http://this.is.the.url/French/')
  60. self.assertIn('1998', results[0]['content'])
  61. self.assertIn('1039 Subs', results[0]['content'])
  62. self.assertIn('Alternative Title', results[0]['content'])
  63. html = """
  64. <div class="boxRows">
  65. <div class="boxRowsInner" style="width:600px;">
  66. <img src="http://static.subtitleseeker.com/images/movie.gif"
  67. style="width:16px; height:16px;" class="icon">
  68. <a href="http://this.is.the.url/"
  69. class="blue" title="Title subtitle" >
  70. This is the Title
  71. </a>
  72. </div>
  73. <div class="boxRowsInner f12b red" style="width:70px;">
  74. 1998
  75. </div>
  76. <div class="boxRowsInner grey-web f12" style="width:120px;">
  77. <img src="http://static.subtitleseeker.com/images/basket_put.png"
  78. style="width:16px; height:16px;" class="icon">
  79. 1039 Subs
  80. </div>
  81. <div class="boxRowsInner grey-web f10" style="width:130px;">
  82. <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
  83. style="width:16px; height:16px;" class="icon">
  84. 1 hours ago
  85. </div>
  86. <div class="clear"></div>
  87. </div>
  88. """
  89. dicto['language'] = 'all'
  90. response = mock.Mock(text=html, search_params=dicto)
  91. results = subtitleseeker.response(response)
  92. self.assertEqual(type(results), list)
  93. self.assertEqual(len(results), 1)
  94. self.assertEqual(results[0]['title'], 'This is the Title')
  95. self.assertEqual(results[0]['url'], 'http://this.is.the.url/')
  96. self.assertIn('1998', results[0]['content'])
  97. self.assertIn('1039 Subs', results[0]['content'])
  98. html = """
  99. <div class="boxRows">
  100. <div class="boxRowsInner" style="width:600px;">
  101. <img src="http://static.subtitleseeker.com/images/movie.gif"
  102. style="width:16px; height:16px;" class="icon">
  103. <a href="http://this.is.the.url/"
  104. class="blue" title="Title subtitle" >
  105. This is the Title
  106. </a>
  107. </div>
  108. <div class="boxRowsInner f12b red" style="width:70px;">
  109. 1998
  110. </div>
  111. <div class="boxRowsInner grey-web f12" style="width:120px;">
  112. <img src="http://static.subtitleseeker.com/images/basket_put.png"
  113. style="width:16px; height:16px;" class="icon">
  114. 1039 Subs
  115. </div>
  116. <div class="boxRowsInner grey-web f10" style="width:130px;">
  117. <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
  118. style="width:16px; height:16px;" class="icon">
  119. 1 hours ago
  120. </div>
  121. <div class="clear"></div>
  122. </div>
  123. """
  124. subtitleseeker.language = 'English'
  125. response = mock.Mock(text=html, search_params=dicto)
  126. results = subtitleseeker.response(response)
  127. self.assertEqual(type(results), list)
  128. self.assertEqual(len(results), 1)
  129. self.assertEqual(results[0]['title'], 'This is the Title')
  130. self.assertEqual(results[0]['url'], 'http://this.is.the.url/English/')
  131. self.assertIn('1998', results[0]['content'])
  132. self.assertIn('1039 Subs', results[0]['content'])
  133. html = """
  134. <div class="boxRowsInner" style="width:600px;">
  135. <img src="http://static.subtitleseeker.com/images/movie.gif"
  136. style="width:16px; height:16px;" class="icon">
  137. <a href="http://this.is.the.url/"
  138. class="blue" title="Title subtitle" >
  139. This is the Title
  140. </a>
  141. </div>
  142. <div class="boxRowsInner f12b red" style="width:70px;">
  143. 1998
  144. </div>
  145. <div class="boxRowsInner grey-web f12" style="width:120px;">
  146. <img src="http://static.subtitleseeker.com/images/basket_put.png"
  147. style="width:16px; height:16px;" class="icon">
  148. 1039 Subs
  149. </div>
  150. <div class="boxRowsInner grey-web f10" style="width:130px;">
  151. <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
  152. style="width:16px; height:16px;" class="icon">
  153. 1 hours ago
  154. </div>
  155. """
  156. response = mock.Mock(text=html, search_params=dicto)
  157. results = subtitleseeker.response(response)
  158. self.assertEqual(type(results), list)
  159. self.assertEqual(len(results), 0)