test_subtitleseeker.py 7.5 KB

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