From 3e3672e0790266fc7f2482fdd854d7789a915d4d Mon Sep 17 00:00:00 2001 From: jibe-b Date: Sat, 23 Sep 2017 14:16:06 +0200 Subject: [add] arxiv engine --- tests/unit/engines/test_arxiv.py | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/unit/engines/test_arxiv.py (limited to 'tests/unit') diff --git a/tests/unit/engines/test_arxiv.py b/tests/unit/engines/test_arxiv.py new file mode 100644 index 000000000..e51d0f483 --- /dev/null +++ b/tests/unit/engines/test_arxiv.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import arxiv +from searx.testing import SearxTestCase + + +class TestBaseEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = arxiv.request(query, dicto) + self.assertIn('url', params) + self.assertIn('export.arxiv.org/api/', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, arxiv.response, None) + self.assertRaises(AttributeError, arxiv.response, []) + self.assertRaises(AttributeError, arxiv.response, '') + self.assertRaises(AttributeError, arxiv.response, '[]') + + response = mock.Mock(text=''' +''') + self.assertEqual(arxiv.response(response), []) + + xml_mock = ''' + + ArXiv Query: search_query=all:test_query&id_list=&start=0&max_results=1 + http://arxiv.org/api/1 + 2000-01-21T00:00:00-01:00 + 1 + 0 + 1 + + http://arxiv.org/1 + 2000-01-01T00:00:01Z + 2000-01-01T00:00:01Z + Mathematical proof. + Mathematical formula. + + A. B. + + + + + + + +''' + + response = mock.Mock(text=xml_mock.encode('utf-8')) + results = arxiv.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Mathematical proof.') + self.assertEqual(results[0]['content'], 'Mathematical formula.') -- cgit v1.2.3 From 9c2b7a82f0c515fd1df88ed80349eda7f49e0825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Wed, 1 Nov 2017 12:28:18 +0100 Subject: minor fixes of arxiv Closes #1050 --- tests/unit/engines/test_arxiv.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/engines/test_arxiv.py b/tests/unit/engines/test_arxiv.py index e51d0f483..b32c0e605 100644 --- a/tests/unit/engines/test_arxiv.py +++ b/tests/unit/engines/test_arxiv.py @@ -21,11 +21,11 @@ class TestBaseEngine(SearxTestCase): self.assertRaises(AttributeError, arxiv.response, '') self.assertRaises(AttributeError, arxiv.response, '[]') - response = mock.Mock(text=''' + response = mock.Mock(content=b''' ''') self.assertEqual(arxiv.response(response), []) - xml_mock = ''' + xml_mock = b''' ArXiv Query: search_query=all:test_query&id_list=&start=0&max_results=1 http://arxiv.org/api/1 @@ -50,7 +50,7 @@ class TestBaseEngine(SearxTestCase): ''' - response = mock.Mock(text=xml_mock.encode('utf-8')) + response = mock.Mock(content=xml_mock) results = arxiv.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 1) -- cgit v1.2.3 From df0d915806b6e4488099130cd1d7fb1775fe475c Mon Sep 17 00:00:00 2001 From: jibe-b Date: Fri, 22 Sep 2017 22:09:33 +0200 Subject: [add] pubmed engine --- tests/unit/engines/pubmed.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/unit/engines/pubmed.py (limited to 'tests/unit') 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='') + self.assertEqual(pubmed.response(response), []) + + xml_mock = """110 +1 + +""" + + 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.') -- cgit v1.2.3 From 5954a8e16a64a369072a7487f62b6396a451ae5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=83=C2=A9mi=20V=C3=83=C2=A1nyi?= Date: Wed, 1 Nov 2017 16:50:27 +0100 Subject: minor fix of BASE engine --- tests/unit/engines/test_base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/engines/test_base.py b/tests/unit/engines/test_base.py index e008b034c..b5da5bde7 100644 --- a/tests/unit/engines/test_base.py +++ b/tests/unit/engines/test_base.py @@ -21,10 +21,10 @@ class TestBaseEngine(SearxTestCase): self.assertRaises(AttributeError, base.response, '') self.assertRaises(AttributeError, base.response, '[]') - response = mock.Mock(text='') + response = mock.Mock(content=b'') self.assertEqual(base.response(response), []) - xml_mock = """ + xml_mock = b""" 0 @@ -83,7 +83,7 @@ class TestBaseEngine(SearxTestCase): """ - response = mock.Mock(text=xml_mock.encode('utf-8')) + response = mock.Mock(content=xml_mock) results = base.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 1) -- cgit v1.2.3