searx/tests/unit/engines/test_duden.py

48 lines
1.6 KiB
Python
Raw Normal View History

2018-08-18 19:24:02 +02:00
from collections import defaultdict
import mock
from searx.engines import duden
from searx.testing import SearxTestCase
from datetime import datetime
class TestDudenEngine(SearxTestCase):
def test_request(self):
query = 'Haus'
dic = defaultdict(dict)
2019-07-25 08:17:45 +02:00
data = [
[1, 'https://www.duden.de/suchen/dudenonline/Haus'],
[2, 'https://www.duden.de/suchen/dudenonline/Haus?search_api_fulltext=&page=1']
]
for page_no, exp_res in data:
dic['pageno'] = page_no
params = duden.request(query, dic)
self.assertTrue('url' in params)
self.assertTrue(query in params['url'])
self.assertTrue('duden.de' in params['url'])
self.assertEqual(params['url'], exp_res)
2018-08-18 19:24:02 +02:00
def test_response(self):
resp = mock.Mock(text='<html></html>')
self.assertEqual(duden.response(resp), [])
html = """
2019-07-25 08:17:45 +02:00
<section class="vignette">
<h2"> <a href="/rechtschreibung/Haus">
<strong>This is the title also here</strong>
</a> </h2>
<p>This is the content</p>
2018-08-18 19:24:02 +02:00
</section>
"""
resp = mock.Mock(text=html)
results = duden.response(resp)
self.assertEqual(len(results), 1)
self.assertEqual(type(results), list)
# testing result (dictionary entry)
r = results[0]
2019-07-25 08:17:45 +02:00
self.assertEqual(r['url'], 'https://www.duden.de/rechtschreibung/Haus')
2018-08-18 19:24:02 +02:00
self.assertEqual(r['title'], 'This is the title also here')
self.assertEqual(r['content'], 'This is the content')