logo

searx

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

test_deviantart.py (4141B)


  1. from collections import defaultdict
  2. import mock
  3. from searx.engines import deviantart
  4. from searx.testing import SearxTestCase
  5. class TestDeviantartEngine(SearxTestCase):
  6. def test_request(self):
  7. dicto = defaultdict(dict)
  8. query = 'test_query'
  9. dicto['pageno'] = 0
  10. dicto['time_range'] = ''
  11. params = deviantart.request(query, dicto)
  12. self.assertTrue('url' in params)
  13. self.assertTrue(query in params['url'])
  14. self.assertTrue('deviantart.com' in params['url'])
  15. def test_no_url_in_request_year_time_range(self):
  16. dicto = defaultdict(dict)
  17. query = 'test_query'
  18. dicto['time_range'] = 'year'
  19. params = deviantart.request(query, dicto)
  20. self.assertEqual({}, params['url'])
  21. def test_response(self):
  22. self.assertRaises(AttributeError, deviantart.response, None)
  23. self.assertRaises(AttributeError, deviantart.response, [])
  24. self.assertRaises(AttributeError, deviantart.response, '')
  25. self.assertRaises(AttributeError, deviantart.response, '[]')
  26. response = mock.Mock(text='<html></html>')
  27. self.assertEqual(deviantart.response(response), [])
  28. response = mock.Mock(status_code=302)
  29. self.assertEqual(deviantart.response(response), [])
  30. html = """
  31. <div id="page-1-results" class="page-results results-page-thumb torpedo-container">
  32. <span class="thumb wide" href="http://amai911.deviantart.com/art/Horse-195212845"
  33. data-super-full-width="900" data-super-full-height="600">
  34. <a class="torpedo-thumb-link" href="https://url.of.image">
  35. <img data-sigil="torpedo-img" src="https://url.of.thumbnail" />
  36. </a>
  37. <span class="info"><span class="title-wrap"><span class="title">Title of image</span></span>
  38. </div>
  39. """
  40. response = mock.Mock(text=html)
  41. results = deviantart.response(response)
  42. self.assertEqual(type(results), list)
  43. self.assertEqual(len(results), 1)
  44. self.assertEqual(results[0]['title'], 'Title of image')
  45. self.assertEqual(results[0]['url'], 'https://url.of.image')
  46. self.assertNotIn('content', results[0])
  47. self.assertEqual(results[0]['thumbnail_src'], 'https://url.of.thumbnail')
  48. html = """
  49. <span class="tt-fh-tc" style="width: 202px;">
  50. <span class="tt-bb" style="width: 202px;">
  51. </span>
  52. <span class="shadow">
  53. <a class="thumb" href="http://url.of.result/2nd.part.of.url"
  54. title="Behoimi BE Animation Test by test-0, Jan 4,
  55. 2010 in Digital Art &gt; Animation"> <i></i>
  56. <img width="200" height="200" alt="Test"
  57. src="http://url.of.thumbnail" data-src="http://th08.deviantart.net/test.jpg">
  58. </a>
  59. </span>
  60. <!-- ^TTT -->
  61. </span>
  62. <span class="details">
  63. <a href="http://test-0.deviantart.com/art/Test" class="t"
  64. title="Behoimi BE Animation Test by test-0, Jan 4, 2010">
  65. <span class="tt-fh-oe">Title of image</span> </a>
  66. <small>
  67. <span class="category">
  68. <span class="age">
  69. 5 years ago
  70. </span>
  71. in <a title="Behoimi BE Animation Test by test-0, Jan 4, 2010"
  72. href="http://www.deviantart.com/browse/all/digitalart/animation/">Animation</a>
  73. </span>
  74. <div class="commentcount">
  75. <a href="http://test-0.deviantart.com/art/Test#comments">
  76. <span class="iconcommentsstats"></span>9 Comments</a>
  77. </div>
  78. <a class="mlt-link" href="http://www.deviantart.com/morelikethis/149167425">
  79. <span class="mlt-icon"></span> <span class="mlt-text">More Like This</span> </a>
  80. </span>
  81. </small> <!-- TTT$ -->
  82. """
  83. response = mock.Mock(text=html)
  84. results = deviantart.response(response)
  85. self.assertEqual(type(results), list)
  86. self.assertEqual(len(results), 0)