on master help sign in
Subtitleseeker's unit test
3a4d604Cqoicebordel
searx/engines/subtitleseeker.py+8−7
@@ -12,6 +12,7 @@ from cgi import escape
12from urllib import quote_plus
12from urllib import quote_plus
13from lxml import html
13from lxml import html
14from searx.languages import language_codes
14from searx.languages import language_codes
15+from searx.engines.xpath import extract_text
15
16
16# engine dependent config
17# engine dependent config
17categories = ['videos']
18categories = ['videos']
@@ -20,7 +21,7 @@ language = ""
20
21
21# search-url
22# search-url
22url = 'http://www.subtitleseeker.com/'
23url = 'http://www.subtitleseeker.com/'
23−search_url = url+'search/TITLES/{query}&p={pageno}'
24+search_url = url + 'search/TITLES/{query}&p={pageno}'
24
25
25# specific xpath variables
26# specific xpath variables
26results_xpath = '//div[@class="boxRows"]'
27results_xpath = '//div[@class="boxRows"]'
@@ -44,7 +45,7 @@ def response(resp):
44 if resp.search_params['language'] != 'all':
45 if resp.search_params['language'] != 'all':
45 search_lang = [lc[1]
46 search_lang = [lc[1]
46 for lc in language_codes
47 for lc in language_codes
47− if lc[0][:2] == resp.search_params['language']][0]
48+ if lc[0][:2] == resp.search_params['language'].split('_')[0]][0]
48
49
49 # parse results
50 # parse results
50 for result in dom.xpath(results_xpath):
51 for result in dom.xpath(results_xpath):
@@ -56,17 +57,17 @@ def response(resp):
56 elif search_lang:
57 elif search_lang:
57 href = href + search_lang + '/'
58 href = href + search_lang + '/'
58
59
59− title = escape(link.xpath(".//text()")[0])
60+ title = escape(extract_text(link))
60
61
61− content = result.xpath('.//div[contains(@class,"red")]//text()')[0]
62+ content = extract_text(result.xpath('.//div[contains(@class,"red")]'))
62 content = content + " - "
63 content = content + " - "
63− text = result.xpath('.//div[contains(@class,"grey-web")]')[0]
64+ text = extract_text(result.xpath('.//div[contains(@class,"grey-web")]')[0])
64− content = content + html.tostring(text, method='text')
65+ content = content + text
65
66
66 if result.xpath(".//span") != []:
67 if result.xpath(".//span") != []:
67 content = content +\
68 content = content +\
68 " - (" +\
69 " - (" +\
69− result.xpath(".//span//text()")[0].strip() +\
70+ extract_text(result.xpath(".//span")) +\
70 ")"
71 ")"
71
72
72 # append result
73 # append result
searx/tests/engines/test_subtitleseeker.pynew file+169
@@ -0,0 +1,169 @@
1+from collections import defaultdict
2+import mock
3+from searx.engines import subtitleseeker
4+from searx.testing import SearxTestCase
5+
6+
7+class TestSubtitleseekerEngine(SearxTestCase):
8+
9+ def test_request(self):
10+ query = 'test_query'
11+ dicto = defaultdict(dict)
12+ dicto['pageno'] = 1
13+ params = subtitleseeker.request(query, dicto)
14+ self.assertTrue('url' in params)
15+ self.assertTrue(query in params['url'])
16+ self.assertTrue('subtitleseeker.com' in params['url'])
17+
18+ def test_response(self):
19+ dicto = defaultdict(dict)
20+ dicto['language'] = 'fr_FR'
21+ response = mock.Mock(search_params=dicto)
22+
23+ self.assertRaises(AttributeError, subtitleseeker.response, None)
24+ self.assertRaises(AttributeError, subtitleseeker.response, [])
25+ self.assertRaises(AttributeError, subtitleseeker.response, '')
26+ self.assertRaises(AttributeError, subtitleseeker.response, '[]')
27+
28+ response = mock.Mock(text='<html></html>', search_params=dicto)
29+ self.assertEqual(subtitleseeker.response(response), [])
30+
31+ html = """
32+ <div class="boxRows">
33+ <div class="boxRowsInner" style="width:600px;">
34+ <img src="http://static.subtitleseeker.com/images/movie.gif"
35+ style="width:16px; height:16px;" class="icon">
36+ <a href="http://this.is.the.url/"
37+ class="blue" title="Title subtitle" >
38+ This is the Title
39+ </a>
40+ <br><br>
41+ <span class="f10b grey-dark arial" style="padding:0px 0px 5px 20px">
42+ "Alternative Title"
43+ </span>
44+ </div>
45+ <div class="boxRowsInner f12b red" style="width:70px;">
46+ 1998
47+ </div>
48+ <div class="boxRowsInner grey-web f12" style="width:120px;">
49+ <img src="http://static.subtitleseeker.com/images/basket_put.png"
50+ style="width:16px; height:16px;" class="icon">
51+ 1039 Subs
52+ </div>
53+ <div class="boxRowsInner grey-web f10" style="width:130px;">
54+ <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
55+ style="width:16px; height:16px;" class="icon">
56+ 1 hours ago
57+ </div>
58+ <div class="clear"></div>
59+ </div>
60+ """
61+ response = mock.Mock(text=html, search_params=dicto)
62+ results = subtitleseeker.response(response)
63+ self.assertEqual(type(results), list)
64+ self.assertEqual(len(results), 1)
65+ self.assertEqual(results[0]['title'], 'This is the Title')
66+ self.assertEqual(results[0]['url'], 'http://this.is.the.url/French/')
67+ self.assertIn('1998', results[0]['content'])
68+ self.assertIn('1039 Subs', results[0]['content'])
69+ self.assertIn('Alternative Title', results[0]['content'])
70+
71+ html = """
72+ <div class="boxRows">
73+ <div class="boxRowsInner" style="width:600px;">
74+ <img src="http://static.subtitleseeker.com/images/movie.gif"
75+ style="width:16px; height:16px;" class="icon">
76+ <a href="http://this.is.the.url/"
77+ class="blue" title="Title subtitle" >
78+ This is the Title
79+ </a>
80+ </div>
81+ <div class="boxRowsInner f12b red" style="width:70px;">
82+ 1998
83+ </div>
84+ <div class="boxRowsInner grey-web f12" style="width:120px;">
85+ <img src="http://static.subtitleseeker.com/images/basket_put.png"
86+ style="width:16px; height:16px;" class="icon">
87+ 1039 Subs
88+ </div>
89+ <div class="boxRowsInner grey-web f10" style="width:130px;">
90+ <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
91+ style="width:16px; height:16px;" class="icon">
92+ 1 hours ago
93+ </div>
94+ <div class="clear"></div>
95+ </div>
96+ """
97+ dicto['language'] = 'all'
98+ response = mock.Mock(text=html, search_params=dicto)
99+ results = subtitleseeker.response(response)
100+ self.assertEqual(type(results), list)
101+ self.assertEqual(len(results), 1)
102+ self.assertEqual(results[0]['title'], 'This is the Title')
103+ self.assertEqual(results[0]['url'], 'http://this.is.the.url/')
104+ self.assertIn('1998', results[0]['content'])
105+ self.assertIn('1039 Subs', results[0]['content'])
106+
107+ html = """
108+ <div class="boxRows">
109+ <div class="boxRowsInner" style="width:600px;">
110+ <img src="http://static.subtitleseeker.com/images/movie.gif"
111+ style="width:16px; height:16px;" class="icon">
112+ <a href="http://this.is.the.url/"
113+ class="blue" title="Title subtitle" >
114+ This is the Title
115+ </a>
116+ </div>
117+ <div class="boxRowsInner f12b red" style="width:70px;">
118+ 1998
119+ </div>
120+ <div class="boxRowsInner grey-web f12" style="width:120px;">
121+ <img src="http://static.subtitleseeker.com/images/basket_put.png"
122+ style="width:16px; height:16px;" class="icon">
123+ 1039 Subs
124+ </div>
125+ <div class="boxRowsInner grey-web f10" style="width:130px;">
126+ <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
127+ style="width:16px; height:16px;" class="icon">
128+ 1 hours ago
129+ </div>
130+ <div class="clear"></div>
131+ </div>
132+ """
133+ subtitleseeker.language = 'English'
134+ response = mock.Mock(text=html, search_params=dicto)
135+ results = subtitleseeker.response(response)
136+ self.assertEqual(type(results), list)
137+ self.assertEqual(len(results), 1)
138+ self.assertEqual(results[0]['title'], 'This is the Title')
139+ self.assertEqual(results[0]['url'], 'http://this.is.the.url/English/')
140+ self.assertIn('1998', results[0]['content'])
141+ self.assertIn('1039 Subs', results[0]['content'])
142+
143+ html = """
144+ <div class="boxRowsInner" style="width:600px;">
145+ <img src="http://static.subtitleseeker.com/images/movie.gif"
146+ style="width:16px; height:16px;" class="icon">
147+ <a href="http://this.is.the.url/"
148+ class="blue" title="Title subtitle" >
149+ This is the Title
150+ </a>
151+ </div>
152+ <div class="boxRowsInner f12b red" style="width:70px;">
153+ 1998
154+ </div>
155+ <div class="boxRowsInner grey-web f12" style="width:120px;">
156+ <img src="http://static.subtitleseeker.com/images/basket_put.png"
157+ style="width:16px; height:16px;" class="icon">
158+ 1039 Subs
159+ </div>
160+ <div class="boxRowsInner grey-web f10" style="width:130px;">
161+ <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
162+ style="width:16px; height:16px;" class="icon">
163+ 1 hours ago
164+ </div>
165+ """
166+ response = mock.Mock(text=html, search_params=dicto)
167+ results = subtitleseeker.response(response)
168+ self.assertEqual(type(results), list)
169+ self.assertEqual(len(results), 0)
searx/tests/test_engines.py+1
@@ -23,6 +23,7 @@ from searx.tests.engines.test_searchcode_code import * # noqa
23from searx.tests.engines.test_searchcode_doc import * # noqa
23from searx.tests.engines.test_searchcode_doc import * # noqa
24from searx.tests.engines.test_soundcloud import * # noqa
24from searx.tests.engines.test_soundcloud import * # noqa
25from searx.tests.engines.test_stackoverflow import * # noqa
25from searx.tests.engines.test_stackoverflow import * # noqa
26+from searx.tests.engines.test_subtitleseeker import * # noqa
26from searx.tests.engines.test_twitter import * # noqa
27from searx.tests.engines.test_twitter import * # noqa
27from searx.tests.engines.test_vimeo import * # noqa
28from searx.tests.engines.test_vimeo import * # noqa
28from searx.tests.engines.test_www500px import * # noqa
29from searx.tests.engines.test_www500px import * # noqa