test_gigablast.py 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from collections import defaultdict
  2. import mock
  3. from searx.engines import gigablast
  4. from searx.testing import SearxTestCase
  5. class TestGigablastEngine(SearxTestCase):
  6. def test_request(self):
  7. query = 'test_query'
  8. dicto = defaultdict(dict)
  9. dicto['pageno'] = 0
  10. dicto['language'] = 'all'
  11. params = gigablast.request(query, dicto)
  12. self.assertTrue('url' in params)
  13. self.assertTrue(query in params['url'])
  14. self.assertTrue('gigablast.com' in params['url'])
  15. def test_response(self):
  16. self.assertRaises(AttributeError, gigablast.response, None)
  17. self.assertRaises(AttributeError, gigablast.response, [])
  18. self.assertRaises(AttributeError, gigablast.response, '')
  19. self.assertRaises(AttributeError, gigablast.response, '[]')
  20. response = mock.Mock(text='{"results": []}')
  21. self.assertEqual(gigablast.response(response), [])
  22. json = """{"results": [
  23. {
  24. "title":"South by Southwest 2016",
  25. "dmozEntry":{
  26. "dmozCatId":1041152,
  27. "directCatId":1,
  28. "dmozCatStr":"Top: Regional: North America: United States",
  29. "dmozTitle":"South by Southwest (SXSW)",
  30. "dmozSum":"Annual music, film, and interactive conference.",
  31. "dmozAnchor":""
  32. },
  33. "dmozEntry":{
  34. "dmozCatId":763945,
  35. "directCatId":1,
  36. "dmozCatStr":"Top: Regional: North America: United States",
  37. "dmozTitle":"South by Southwest (SXSW)",
  38. "dmozSum":"",
  39. "dmozAnchor":"www.sxsw.com"
  40. },
  41. "dmozEntry":{
  42. "dmozCatId":761446,
  43. "directCatId":1,
  44. "dmozCatStr":"Top: Regional: North America: United States",
  45. "dmozTitle":"South by Southwest (SXSW)",
  46. "dmozSum":"Music, film, and interactive conference and festival.",
  47. "dmozAnchor":""
  48. },
  49. "indirectDmozCatId":1041152,
  50. "indirectDmozCatId":763945,
  51. "indirectDmozCatId":761446,
  52. "contentType":"html",
  53. "sum":"This should be the content.",
  54. "url":"www.sxsw.com",
  55. "hopCount":0,
  56. "size":" 102k",
  57. "sizeInBytes":104306,
  58. "bytesUsedToComputeSummary":70000,
  59. "docId":269411794364,
  60. "docScore":586571136.000000,
  61. "summaryGenTimeMS":12,
  62. "summaryTagdbLookupTimeMS":0,
  63. "summaryTitleRecLoadTimeMS":1,
  64. "site":"www.sxsw.com",
  65. "spidered":1452203608,
  66. "firstIndexedDateUTC":1444167123,
  67. "contentHash32":2170650347,
  68. "language":"English",
  69. "langAbbr":"en"
  70. }
  71. ]}
  72. """
  73. response = mock.Mock(text=json)
  74. results = gigablast.response(response)
  75. self.assertEqual(type(results), list)
  76. self.assertEqual(len(results), 1)
  77. self.assertEqual(results[0]['title'], 'South by Southwest 2016')
  78. self.assertEqual(results[0]['url'], 'www.sxsw.com')
  79. self.assertEqual(results[0]['content'], 'This should be the content.')