test_unsplash.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from collections import defaultdict
  2. import mock
  3. from searx.testing import SearxTestCase
  4. from searx.engines import unsplash
  5. class TestUnsplashEngine(SearxTestCase):
  6. def test_request(self):
  7. query = 'penguin'
  8. _dict = defaultdict(dict)
  9. _dict['pageno'] = 1
  10. params = unsplash.request(query, _dict)
  11. self.assertTrue('url' in params)
  12. self.assertTrue(query in params['url'])
  13. def test_response(self):
  14. resp = mock.Mock(text='{}')
  15. result = unsplash.response(resp)
  16. self.assertEqual([], result)
  17. resp.text = '{"results": []}'
  18. result = unsplash.response(resp)
  19. self.assertEqual([], result)
  20. # Sourced from https://unsplash.com/napi/search/photos?query=penguin&xp=&per_page=20&page=2
  21. with open('./tests/unit/engines/unsplash_fixture.json') as fixture:
  22. resp.text = fixture.read()
  23. result = unsplash.response(resp)
  24. self.assertEqual(len(result), 2)
  25. self.assertEqual(result[0]['title'], 'low angle photography of swimming penguin')
  26. self.assertEqual(result[0]['url'], 'https://unsplash.com/photos/FY8d721UO_4')
  27. self.assertEqual(result[0]['thumbnail_src'], 'https://images.unsplash.com/photo-1523557148507-1b77641c7e7c?ixlib=rb-0.3.5&q=80\
  28. &fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max')
  29. self.assertEqual(result[0]['img_src'], 'https://images.unsplash.com/photo-1523557148507-1b77641c7e7c\
  30. ?ixlib=rb-0.3.5')
  31. self.assertEqual(result[0]['content'], '')