logo

searx

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

test_subtitleseeker.py (5993B)


  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. subtitleseeker.language = 'English'
  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/English/')
  100. self.assertIn('1998', results[0]['content'])
  101. self.assertIn('1039 Subs', results[0]['content'])
  102. html = """
  103. <div class="boxRowsInner" style="width:600px;">
  104. <img src="http://static.subtitleseeker.com/images/movie.gif"
  105. style="width:16px; height:16px;" class="icon">
  106. <a href="http://this.is.the.url/"
  107. class="blue" title="Title subtitle" >
  108. This is the Title
  109. </a>
  110. </div>
  111. <div class="boxRowsInner f12b red" style="width:70px;">
  112. 1998
  113. </div>
  114. <div class="boxRowsInner grey-web f12" style="width:120px;">
  115. <img src="http://static.subtitleseeker.com/images/basket_put.png"
  116. style="width:16px; height:16px;" class="icon">
  117. 1039 Subs
  118. </div>
  119. <div class="boxRowsInner grey-web f10" style="width:130px;">
  120. <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
  121. style="width:16px; height:16px;" class="icon">
  122. 1 hours ago
  123. </div>
  124. """
  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), 0)