@@ -0,0 +1,118 @@
1+from collections import defaultdict
2+import mock
3+from searx.engines import deviantart
4+from searx.testing import SearxTestCase
5+
6+
7+class TestDeviantartEngine(SearxTestCase):
8+
9+ def test_request(self):
10+ query = 'test_query'
11+ dicto = defaultdict(dict)
12+ dicto['pageno'] = 0
13+ params = deviantart.request(query, dicto)
14+ self.assertTrue('url' in params)
15+ self.assertTrue(query in params['url'])
16+ self.assertTrue('deviantart.com' in params['url'])
17+
18+ def test_response(self):
19+ self.assertRaises(AttributeError, deviantart.response, None)
20+ self.assertRaises(AttributeError, deviantart.response, [])
21+ self.assertRaises(AttributeError, deviantart.response, '')
22+ self.assertRaises(AttributeError, deviantart.response, '[]')
23+
24+ response = mock.Mock(text='<html></html>')
25+ self.assertEqual(deviantart.response(response), [])
26+
27+ response = mock.Mock(status_code=302)
28+ self.assertEqual(deviantart.response(response), [])
29+
30+ html = """
31+ <div class="tt-a tt-fh tt-boxed" collect_rid="1:149167425"
32+ usericon="http://a.deviantart.net/avatars/t/e/test-0.gif" userid="233301"
33+ username="test-0" symbol="~" category="digitalart/animation">
34+ <span class="tt-w" style="width: auto; max-width: 277px;">
35+ <span class="tt-fh-tc" style="width: 202px;">
36+ <span class="tt-bb" style="width: 202px;">
37+ </span>
38+ <span class="shadow">
39+ <a class="thumb" href="http://url.of.result/2nd.part.of.url"
40+ title="Behoimi BE Animation Test by test-0, Jan 4,
41+ 2010 in Digital Art > Animation"> <i></i>
42+ <img width="200" height="200" alt="Test"
43+ src="http://url.of.thumbnail" data-src="http://th08.deviantart.net/test.jpg">
44+ </a>
45+ </span>
46+ <!-- ^TTT -->
47+ </span>
48+ <span class="details">
49+ <a href="http://test-0.deviantart.com/art/Test" class="t"
50+ title="Behoimi BE Animation Test by test-0, Jan 4, 2010">
51+ <span class="tt-fh-oe">Title of image</span> </a>
52+ <small>
53+ <span class="category">
54+ <span class="age">
55+ 5 years ago
56+ </span>
57+ in <a title="Behoimi BE Animation Test by test-0, Jan 4, 2010"
58+ href="http://www.deviantart.com/browse/all/digitalart/animation/">Animation</a>
59+ </span>
60+ <div class="commentcount">
61+ <a href="http://test-0.deviantart.com/art/Test#comments">
62+ <span class="iconcommentsstats"></span>9 Comments</a>
63+ </div>
64+ <a class="mlt-link" href="http://www.deviantart.com/morelikethis/149167425">
65+ <span class="mlt-icon"></span> <span class="mlt-text">More Like This</span> </a>
66+ </span>
67+ </small> <!-- TTT$ -->
68+ </span>
69+ </div>
70+ """
71+ response = mock.Mock(text=html)
72+ results = deviantart.response(response)
73+ self.assertEqual(type(results), list)
74+ self.assertEqual(len(results), 1)
75+ self.assertEqual(results[0]['title'], 'Title of image')
76+ self.assertEqual(results[0]['url'], 'http://url.of.result/2nd.part.of.url')
77+ self.assertNotIn('content', results[0])
78+ self.assertEqual(results[0]['thumbnail_src'], 'http://url.of.thumbnail')
79+
80+ html = """
81+ <span class="tt-fh-tc" style="width: 202px;">
82+ <span class="tt-bb" style="width: 202px;">
83+ </span>
84+ <span class="shadow">
85+ <a class="thumb" href="http://url.of.result/2nd.part.of.url"
86+ title="Behoimi BE Animation Test by test-0, Jan 4,
87+ 2010 in Digital Art > Animation"> <i></i>
88+ <img width="200" height="200" alt="Test"
89+ src="http://url.of.thumbnail" data-src="http://th08.deviantart.net/test.jpg">
90+ </a>
91+ </span>
92+ <!-- ^TTT -->
93+ </span>
94+ <span class="details">
95+ <a href="http://test-0.deviantart.com/art/Test" class="t"
96+ title="Behoimi BE Animation Test by test-0, Jan 4, 2010">
97+ <span class="tt-fh-oe">Title of image</span> </a>
98+ <small>
99+ <span class="category">
100+ <span class="age">
101+ 5 years ago
102+ </span>
103+ in <a title="Behoimi BE Animation Test by test-0, Jan 4, 2010"
104+ href="http://www.deviantart.com/browse/all/digitalart/animation/">Animation</a>
105+ </span>
106+ <div class="commentcount">
107+ <a href="http://test-0.deviantart.com/art/Test#comments">
108+ <span class="iconcommentsstats"></span>9 Comments</a>
109+ </div>
110+ <a class="mlt-link" href="http://www.deviantart.com/morelikethis/149167425">
111+ <span class="mlt-icon"></span> <span class="mlt-text">More Like This</span> </a>
112+ </span>
113+ </small> <!-- TTT$ -->
114+ """
115+ response = mock.Mock(text=html)
116+ results = deviantart.response(response)
117+ self.assertEqual(type(results), list)
118+ self.assertEqual(len(results), 0)