logo

searx

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

test_seedpeer.py (1959B)


  1. import mock
  2. from collections import defaultdict
  3. from searx.engines import seedpeer
  4. from searx.testing import SearxTestCase
  5. from datetime import datetime
  6. class TestSeedPeerEngine(SearxTestCase):
  7. html = ''
  8. with open('./tests/unit/engines/seedpeer_fixture.html') as fixture:
  9. html += fixture.read()
  10. def test_request(self):
  11. query = 'test_query'
  12. dicto = defaultdict(dict)
  13. dicto['pageno'] = 1
  14. params = seedpeer.request(query, dicto)
  15. self.assertIn('url', params)
  16. self.assertIn(query, params['url'])
  17. self.assertIn('seedpeer.eu', params['url'])
  18. def test_response_raises_attr_error_on_empty_response(self):
  19. self.assertRaises(AttributeError, seedpeer.response, None)
  20. self.assertRaises(AttributeError, seedpeer.response, [])
  21. self.assertRaises(AttributeError, seedpeer.response, '')
  22. self.assertRaises(AttributeError, seedpeer.response, '[]')
  23. def test_response_returns_empty_list(self):
  24. response = mock.Mock(text='<html></html>')
  25. self.assertEqual(seedpeer.response(response), [])
  26. def test_response_returns_all_results(self):
  27. response = mock.Mock(text=self.html)
  28. results = seedpeer.response(response)
  29. self.assertTrue(isinstance(results, list))
  30. self.assertEqual(len(results), 2)
  31. def test_response_returns_correct_results(self):
  32. response = mock.Mock(text=self.html)
  33. results = seedpeer.response(response)
  34. self.assertEqual(
  35. results[0]['title'], 'Narcos - Season 2 - 720p WEBRiP - x265 HEVC - ShAaNiG '
  36. )
  37. self.assertEqual(
  38. results[0]['url'],
  39. 'http://www.seedpeer.eu/details/11685972/Narcos---Season-2---720p-WEBRiP---x265-HEVC---ShAaNiG.html'
  40. )
  41. self.assertEqual(results[0]['content'], '2.48 GB, 1 day')
  42. self.assertEqual(results[0]['seed'], '861')
  43. self.assertEqual(results[0]['leech'], '332')