logo

searx

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

pubmed.py (1352B)


  1. # -*- coding: utf-8 -*-
  2. from collections import defaultdict
  3. import mock
  4. from searx.engines import pubmed
  5. from searx.testing import SearxTestCase
  6. class TestPubmedEngine(SearxTestCase):
  7. def test_request(self):
  8. query = 'test_query'
  9. dicto = defaultdict(dict)
  10. dicto['pageno'] = 1
  11. params = pubmed.request(query, dicto)
  12. self.assertIn('url', params)
  13. self.assertIn('eutils.ncbi.nlm.nih.gov/', params['url'])
  14. self.assertIn('term', params['url'])
  15. def test_response(self):
  16. self.assertRaises(AttributeError, pubmed.response, None)
  17. self.assertRaises(AttributeError, pubmed.response, [])
  18. self.assertRaises(AttributeError, pubmed.response, '')
  19. self.assertRaises(AttributeError, pubmed.response, '[]')
  20. response = mock.Mock(text='<PubmedArticleSet></PubmedArticleSet>')
  21. self.assertEqual(pubmed.response(response), [])
  22. xml_mock = """<eSearchResult><Count>1</Count><RetMax>1</RetMax><RetStart>0</RetStart><IdList>
  23. <Id>1</Id>
  24. </IdList></eSearchResult>
  25. """
  26. response = mock.Mock(text=xml_mock.encode('utf-8'))
  27. results = pubmed.response(response)
  28. self.assertEqual(type(results), list)
  29. self.assertEqual(len(results), 1)
  30. self.assertEqual(results[0]['content'], 'No abstract is available for this publication.')