logo

searx

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

test_duden.py (1372B)


  1. from collections import defaultdict
  2. import mock
  3. from searx.engines import duden
  4. from searx.testing import SearxTestCase
  5. from datetime import datetime
  6. class TestDudenEngine(SearxTestCase):
  7. def test_request(self):
  8. query = 'Haus'
  9. dic = defaultdict(dict)
  10. dic['pageno'] = 1
  11. params = duden.request(query, dic)
  12. self.assertTrue('url' in params)
  13. self.assertTrue(query in params['url'])
  14. self.assertTrue('duden.de' in params['url'])
  15. def test_response(self):
  16. resp = mock.Mock(text='<html></html>')
  17. self.assertEqual(duden.response(resp), [])
  18. html = """
  19. <section class="wide">
  20. <h2><a href="https://this.is.the.url/" class="hidden-link"><strong>This is the title</strong> also here</a></h2>
  21. <p>This is the <strong>content</strong></p>
  22. <a href="https://this.is.the.url/">Zum vollst&auml;ndigen Artikel</a>
  23. </section>
  24. """
  25. resp = mock.Mock(text=html)
  26. results = duden.response(resp)
  27. self.assertEqual(len(results), 1)
  28. self.assertEqual(type(results), list)
  29. # testing result (dictionary entry)
  30. r = results[0]
  31. self.assertEqual(r['url'], 'https://this.is.the.url/')
  32. self.assertEqual(r['title'], 'This is the title also here')
  33. self.assertEqual(r['content'], 'This is the content')