logo

searx

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

test_arxiv.py (2454B)


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