@@ -0,0 +1,58 @@
1+# -*- coding: utf-8 -*-
2+from collections import defaultdict
4+from searx.engines import arxiv
5+from searx.testing import SearxTestCase
8+class TestBaseEngine(SearxTestCase):
10+ def test_request(self):
12+ dicto = defaultdict(dict)
14+ params = arxiv.request(query, dicto)
15+ self.assertIn('url', params)
16+ self.assertIn('export.arxiv.org/api/', params['url'])
18+ def test_response(self):
19+ self.assertRaises(AttributeError, arxiv.response, None)
20+ self.assertRaises(AttributeError, arxiv.response, [])
21+ self.assertRaises(AttributeError, arxiv.response, '')
22+ self.assertRaises(AttributeError, arxiv.response, '[]')
24+ response = mock.Mock(text='''<?xml version="1.0" encoding="UTF-8"?>
25+<feed xmlns="http://www.w3.org/2005/Atom"></feed>''')
26+ self.assertEqual(arxiv.response(response), [])
28+ xml_mock = '''<?xml version="1.0" encoding="UTF-8"?>
29+<feed xmlns="http://www.w3.org/2005/Atom">
30+ <title type="html">ArXiv Query: search_query=all:test_query&id_list=&start=0&max_results=1</title>
31+ <id>http://arxiv.org/api/1</id>
32+ <updated>2000-01-21T00:00:00-01:00</updated>
33+ <opensearch:totalResults xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">1</opensearch:totalResults>
34+ <opensearch:startIndex xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">0</opensearch:startIndex>
35+ <opensearch:itemsPerPage xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">1</opensearch:itemsPerPage>
37+ <id>http://arxiv.org/1</id>
38+ <updated>2000-01-01T00:00:01Z</updated>
39+ <published>2000-01-01T00:00:01Z</published>
40+ <title>Mathematical proof.</title>
41+ <summary>Mathematical formula.</summary>
45+ <link href="http://arxiv.org/1" rel="alternate" type="text/html"/>
46+ <link title="pdf" href="http://arxiv.org/1" rel="related" type="application/pdf"/>
47+ <category term="math.QA" scheme="http://arxiv.org/schemas/atom"/>
48+ <category term="1" scheme="http://arxiv.org/schemas/atom"/>
53+ response = mock.Mock(text=xml_mock.encode('utf-8'))
54+ results = arxiv.response(response)
55+ self.assertEqual(type(results), list)
56+ self.assertEqual(len(results), 1)
57+ self.assertEqual(results[0]['title'], 'Mathematical proof.')
58+ self.assertEqual(results[0]['content'], 'Mathematical formula.')