summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjibe-b <user701@orange.fr>2017-09-22 22:09:33 +0200
committerNoémi Ványi <sitbackandwait@gmail.com>2017-11-01 17:02:38 +0100
commitdf0d915806b6e4488099130cd1d7fb1775fe475c (patch)
tree926bb6a3e8a35fdc91ceb23d22649a9c0db54f11 /tests
parent1b10abfc92afed36627c7052b89d2de5e7f537ee (diff)
downloadsearxng-df0d915806b6e4488099130cd1d7fb1775fe475c.tar.gz
searxng-df0d915806b6e4488099130cd1d7fb1775fe475c.zip
[add] pubmed engine
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/engines/pubmed.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/unit/engines/pubmed.py b/tests/unit/engines/pubmed.py
new file mode 100644
index 000000000..370efe067
--- /dev/null
+++ b/tests/unit/engines/pubmed.py
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+from collections import defaultdict
+import mock
+from searx.engines import pubmed
+from searx.testing import SearxTestCase
+
+
+class TestPubmedEngine(SearxTestCase):
+
+ def test_request(self):
+ query = 'test_query'
+ dicto = defaultdict(dict)
+ dicto['pageno'] = 1
+ params = pubmed.request(query, dicto)
+ self.assertIn('url', params)
+ self.assertIn('eutils.ncbi.nlm.nih.gov/', params['url'])
+ self.assertIn('term', params['url'])
+
+ def test_response(self):
+ self.assertRaises(AttributeError, pubmed.response, None)
+ self.assertRaises(AttributeError, pubmed.response, [])
+ self.assertRaises(AttributeError, pubmed.response, '')
+ self.assertRaises(AttributeError, pubmed.response, '[]')
+
+ response = mock.Mock(text='<PubmedArticleSet></PubmedArticleSet>')
+ self.assertEqual(pubmed.response(response), [])
+
+ xml_mock = """<eSearchResult><Count>1</Count><RetMax>1</RetMax><RetStart>0</RetStart><IdList>
+<Id>1</Id>
+</IdList></eSearchResult>
+"""
+
+ response = mock.Mock(text=xml_mock.encode('utf-8'))
+ results = pubmed.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 1)
+ self.assertEqual(results[0]['content'], 'No abstract is available for this publication.')