mirror of
https://github.com/searxng/searxng.git
synced 2025-07-24 13:49:26 +02:00
Adds a unit test for the unsplash engine
This commit is contained in:
parent
72d063d27d
commit
ee07a5e750
2 changed files with 279 additions and 0 deletions
38
tests/unit/engines/test_unsplash.py
Normal file
38
tests/unit/engines/test_unsplash.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
from collections import defaultdict
|
||||
import mock
|
||||
from searx.testing import SearxTestCase
|
||||
from searx.engines import unsplash
|
||||
|
||||
|
||||
class TestUnsplashEngine(SearxTestCase):
|
||||
def test_request(self):
|
||||
query = 'penguin'
|
||||
_dict = defaultdict(dict)
|
||||
_dict['pageno'] = 1
|
||||
params = unsplash.request(query, _dict)
|
||||
|
||||
self.assertTrue('url' in params)
|
||||
self.assertTrue(query in params['url'])
|
||||
|
||||
def test_response(self):
|
||||
resp = mock.Mock(text='{}')
|
||||
result = unsplash.response(resp)
|
||||
self.assertEqual([], result)
|
||||
|
||||
resp.text = '{"results": []}'
|
||||
result = unsplash.response(resp)
|
||||
self.assertEqual([], result)
|
||||
|
||||
# Sourced from https://unsplash.com/napi/search/photos?query=penguin&xp=&per_page=20&page=2
|
||||
with open('./tests/unit/engines/unsplash_fixture.json') as fixture:
|
||||
resp.text = fixture.read()
|
||||
|
||||
result = unsplash.response(resp)
|
||||
self.assertEqual(len(result), 2)
|
||||
self.assertEqual(result[0]['title'], 'low angle photography of swimming penguin')
|
||||
self.assertEqual(result[0]['url'], 'https://unsplash.com/photos/FY8d721UO_4')
|
||||
self.assertEqual(result[0]['thumbnail_src'], 'https://images.unsplash.com/photo-1523557148507-1b77641c7e7c?ixlib=rb-0.3.5&q=80\
|
||||
&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&ixid=eyJhcHBfaWQiOjEyMDd9&s=a9b9e56e63efc6f4611a87ce7e9a48f8')
|
||||
self.assertEqual(result[0]['img_src'], 'https://images.unsplash.com/photo-1523557148507-1b77641c7e7c?ixlib=rb-0.3.5\
|
||||
&ixid=eyJhcHBfaWQiOjEyMDd9&s=095c5fc319c5a77c705f49ad63e0f195')
|
||||
self.assertEqual(result[0]['content'], '')
|
Loading…
Add table
Add a link
Reference in a new issue