on master help sign in
Merge pull request #1562 from asciimoo/settings

Remove some engines : subtitleseeker, seedpeer, swisscows

commita255651671a2f26dd6c2f02da367a017fb4c24c4 authorAlexandre Flament <alex@al-f.net> dateTue 28 May 2019, 11:14 (7 years ago) parent6c95ebcffe0972
7 files changed−686
searx/engines/seedpeer.py−75 searx/engines/subtitleseeker.py−86 searx/engines/swisscows.py−125 searx/settings.yml−18 tests/unit/engines/test_seedpeer.py−51 tests/unit/engines/test_subtitleseeker.py−174 tests/unit/engines/test_swisscows.py−157
searx/engines/seedpeer.pydeleted−75
@@ -1,75 +0,0 @@
1−# Seedpeer (Videos, Music, Files)
2−#
3−# @website http://seedpeer.eu
4−# @provide-api no (nothing found)
5−#
6−# @using-api no
7−# @results HTML (using search portal)
8−# @stable yes (HTML can change)
9−# @parse url, title, content, seed, leech, magnetlink
10−
11−from lxml import html
12−from operator import itemgetter
13−from searx.url_utils import quote, urljoin
14−
15−
16−url = 'http://www.seedpeer.eu/'
17−search_url = url + 'search/{search_term}/7/{page_no}.html'
18−# specific xpath variables
19−torrent_xpath = '//*[@id="body"]/center/center/table[2]/tr/td/a'
20−alternative_torrent_xpath = '//*[@id="body"]/center/center/table[1]/tr/td/a'
21−title_xpath = '//*[@id="body"]/center/center/table[2]/tr/td/a/text()'
22−alternative_title_xpath = '//*[@id="body"]/center/center/table/tr/td/a'
23−seeds_xpath = '//*[@id="body"]/center/center/table[2]/tr/td[4]/font/text()'
24−alternative_seeds_xpath = '//*[@id="body"]/center/center/table/tr/td[4]/font/text()'
25−peers_xpath = '//*[@id="body"]/center/center/table[2]/tr/td[5]/font/text()'
26−alternative_peers_xpath = '//*[@id="body"]/center/center/table/tr/td[5]/font/text()'
27−age_xpath = '//*[@id="body"]/center/center/table[2]/tr/td[2]/text()'
28−alternative_age_xpath = '//*[@id="body"]/center/center/table/tr/td[2]/text()'
29−size_xpath = '//*[@id="body"]/center/center/table[2]/tr/td[3]/text()'
30−alternative_size_xpath = '//*[@id="body"]/center/center/table/tr/td[3]/text()'
31−
32−
33−# do search-request
34−def request(query, params):
35− params['url'] = search_url.format(search_term=quote(query),
36− page_no=params['pageno'] - 1)
37− return params
38−
39−
40−# get response from search-request
41−def response(resp):
42− results = []
43− dom = html.fromstring(resp.text)
44− torrent_links = dom.xpath(torrent_xpath)
45− if len(torrent_links) > 0:
46− seeds = dom.xpath(seeds_xpath)
47− peers = dom.xpath(peers_xpath)
48− titles = dom.xpath(title_xpath)
49− sizes = dom.xpath(size_xpath)
50− ages = dom.xpath(age_xpath)
51− else: # under ~5 results uses a different xpath
52− torrent_links = dom.xpath(alternative_torrent_xpath)
53− seeds = dom.xpath(alternative_seeds_xpath)
54− peers = dom.xpath(alternative_peers_xpath)
55− titles = dom.xpath(alternative_title_xpath)
56− sizes = dom.xpath(alternative_size_xpath)
57− ages = dom.xpath(alternative_age_xpath)
58− # return empty array if nothing is found
59− if not torrent_links:
60− return []
61−
62− # parse results
63− for index, result in enumerate(torrent_links):
64− link = result.attrib.get('href')
65− href = urljoin(url, link)
66− results.append({'url': href,
67− 'title': titles[index].text_content(),
68− 'content': '{}, {}'.format(sizes[index], ages[index]),
69− 'seed': seeds[index],
70− 'leech': peers[index],
71−
72− 'template': 'torrent.html'})
73−
74− # return results sorted by seeder
75− return sorted(results, key=itemgetter('seed'), reverse=True)
searx/engines/subtitleseeker.pydeleted−86
@@ -1,86 +0,0 @@
1−"""
2− Subtitleseeker (Video)
3−
4− @website http://www.subtitleseeker.com
5− @provide-api no
6−
7− @using-api no
8− @results HTML
9− @stable no (HTML can change)
10− @parse url, title, content
11−"""
12−
13−from lxml import html
14−from searx.languages import language_codes
15−from searx.engines.xpath import extract_text
16−from searx.url_utils import quote_plus
17−
18−# engine dependent config
19−categories = ['videos']
20−paging = True
21−language = ""
22−
23−# search-url
24−url = 'http://www.subtitleseeker.com/'
25−search_url = url + 'search/TITLES/{query}?p={pageno}'
26−
27−# specific xpath variables
28−results_xpath = '//div[@class="boxRows"]'
29−
30−
31−# do search-request
32−def request(query, params):
33− params['url'] = search_url.format(query=quote_plus(query),
34− pageno=params['pageno'])
35− return params
36−
37−
38−# get response from search-request
39−def response(resp):
40− results = []
41−
42− dom = html.fromstring(resp.text)
43−
44− search_lang = ""
45−
46− # dirty fix for languages named differenly in their site
47− if resp.search_params['language'][:2] == 'fa':
48− search_lang = 'Farsi'
49− elif resp.search_params['language'] == 'pt-BR':
50− search_lang = 'Brazilian'
51− elif resp.search_params['language'] != 'all':
52− search_lang = [lc[3]
53− for lc in language_codes
54− if lc[0].split('-')[0] == resp.search_params['language'].split('-')[0]]
55− search_lang = search_lang[0].split(' (')[0]
56−
57− # parse results
58− for result in dom.xpath(results_xpath):
59− link = result.xpath(".//a")[0]
60− href = link.attrib.get('href')
61−
62− if language is not "":
63− href = href + language + '/'
64− elif search_lang:
65− href = href + search_lang + '/'
66−
67− title = extract_text(link)
68−
69− content = extract_text(result.xpath('.//div[contains(@class,"red")]'))
70− content = content + " - "
71− text = extract_text(result.xpath('.//div[contains(@class,"grey-web")]')[0])
72− content = content + text
73−
74− if result.xpath(".//span") != []:
75− content = content +\
76− " - (" +\
77− extract_text(result.xpath(".//span")) +\
78− ")"
79−
80− # append result
81− results.append({'url': href,
82− 'title': title,
83− 'content': content})
84−
85− # return results
86− return results
searx/engines/swisscows.pydeleted−125
@@ -1,125 +0,0 @@
1−"""
2− Swisscows (Web, Images)
3−
4− @website https://swisscows.ch
5− @provide-api no
6−
7− @using-api no
8− @results HTML (using search portal)
9− @stable no (HTML can change)
10− @parse url, title, content
11−"""
12−
13−from json import loads
14−import re
15−from lxml.html import fromstring
16−from searx.url_utils import unquote, urlencode
17−from searx.utils import match_language
18−
19−# engine dependent config
20−categories = ['general', 'images']
21−paging = True
22−language_support = True
23−
24−# search-url
25−base_url = 'https://swisscows.ch/'
26−search_string = '?{query}&page={page}'
27−
28−supported_languages_url = base_url
29−
30−# regex
31−regex_json = re.compile(b'initialData: {"Request":(.|\n)*},\s*environment')
32−regex_json_remove_start = re.compile(b'^initialData:\s*')
33−regex_json_remove_end = re.compile(b',\s*environment$')
34−regex_img_url_remove_start = re.compile(b'^https?://i\.swisscows\.ch/\?link=')
35−
36−
37−# do search-request
38−def request(query, params):
39− if params['language'] == 'all':
40− ui_language = 'browser'
41− region = 'browser'
42− else:
43− region = match_language(params['language'], supported_languages, language_aliases)
44− ui_language = region.split('-')[0]
45−
46− search_path = search_string.format(
47− query=urlencode({'query': query, 'uiLanguage': ui_language, 'region': region}),
48− page=params['pageno']
49− )
50−
51− # image search query is something like 'image?{query}&page={page}'
52− if params['category'] == 'images':
53− search_path = 'image' + search_path
54−
55− params['url'] = base_url + search_path
56−
57− return params
58−
59−
60−# get response from search-request
61−def response(resp):
62− results = []
63−
64− json_regex = regex_json.search(resp.text)
65−
66− # check if results are returned
67− if not json_regex:
68− return []
69−
70− json_raw = regex_json_remove_end.sub(b'', regex_json_remove_start.sub(b'', json_regex.group()))
71− json = loads(json_raw.decode('utf-8'))
72−
73− # parse results
74− for result in json['Results'].get('items', []):
75− result_title = result['Title'].replace(u'\uE000', '').replace(u'\uE001', '')
76−
77− # parse image results
78− if result.get('ContentType', '').startswith('image'):
79− img_url = unquote(regex_img_url_remove_start.sub(b'', result['Url'].encode('utf-8')).decode('utf-8'))
80−
81− # append result
82− results.append({'url': result['SourceUrl'],
83− 'title': result['Title'],
84− 'content': '',
85− 'img_src': img_url,
86− 'template': 'images.html'})
87−
88− # parse general results
89− else:
90− result_url = result['Url'].replace(u'\uE000', '').replace(u'\uE001', '')
91− result_content = result['Description'].replace(u'\uE000', '').replace(u'\uE001', '')
92−
93− # append result
94− results.append({'url': result_url,
95− 'title': result_title,
96− 'content': result_content})
97−
98− # parse images
99− for result in json.get('Images', []):
100− # decode image url
101− img_url = unquote(regex_img_url_remove_start.sub(b'', result['Url'].encode('utf-8')).decode('utf-8'))
102−
103− # append result
104− results.append({'url': result['SourceUrl'],
105− 'title': result['Title'],
106− 'content': '',
107− 'img_src': img_url,
108− 'template': 'images.html'})
109−
110− # return results
111− return results
112−
113−
114−# get supported languages from their site
115−def _fetch_supported_languages(resp):
116− supported_languages = []
117− dom = fromstring(resp.text)
118− options = dom.xpath('//div[@id="regions-popup"]//ul/li/a')
119− for option in options:
120− code = option.xpath('./@data-search-language')[0]
121− if code.startswith('nb-'):
122− code = code.replace('nb', 'no', 1)
123− supported_languages.append(code)
124−
125− return supported_languages
searx/settings.yml−18
@@ -568,24 +568,12 @@ engines:
568568 engine : spotify
569569 shortcut : stf
570570
571− - name : subtitleseeker
572− engine : subtitleseeker
573− shortcut : ss
574−# The language is an option. You can put any language written in english
575−# Examples : English, French, German, Hungarian, Chinese...
576−# language : English
577−
578571 - name : startpage
579572 engine : startpage
580573 shortcut : sp
581574 timeout : 6.0
582575 disabled : True
583576
584− - name : swisscows
585− engine : swisscows
586− shortcut : sw
587− disabled : True
588−
589577 - name : tokyotoshokan
590578 engine : tokyotoshokan
591579 shortcut : tt
@@ -664,12 +652,6 @@ engines:
664652 timeout: 6.0
665653 categories : science
666654
667− - name : seedpeer
668− engine : seedpeer
669− shortcut: speu
670− categories: files, music, videos
671− disabled: True
672−
673655 - name : dictzone
674656 engine : dictzone
675657 shortcut : dc
tests/unit/engines/test_seedpeer.pydeleted−51
@@ -1,51 +0,0 @@
1−import mock
2−from collections import defaultdict
3−from searx.engines import seedpeer
4−from searx.testing import SearxTestCase
5−from datetime import datetime
6−
7−
8−class TestSeedPeerEngine(SearxTestCase):
9−
10− html = ''
11− with open('./tests/unit/engines/seedpeer_fixture.html') as fixture:
12− html += fixture.read()
13−
14− def test_request(self):
15− query = 'test_query'
16− dicto = defaultdict(dict)
17− dicto['pageno'] = 1
18− params = seedpeer.request(query, dicto)
19− self.assertIn('url', params)
20− self.assertIn(query, params['url'])
21− self.assertIn('seedpeer.eu', params['url'])
22−
23− def test_response_raises_attr_error_on_empty_response(self):
24− self.assertRaises(AttributeError, seedpeer.response, None)
25− self.assertRaises(AttributeError, seedpeer.response, [])
26− self.assertRaises(AttributeError, seedpeer.response, '')
27− self.assertRaises(AttributeError, seedpeer.response, '[]')
28−
29− def test_response_returns_empty_list(self):
30− response = mock.Mock(text='<html></html>')
31− self.assertEqual(seedpeer.response(response), [])
32−
33− def test_response_returns_all_results(self):
34− response = mock.Mock(text=self.html)
35− results = seedpeer.response(response)
36− self.assertTrue(isinstance(results, list))
37− self.assertEqual(len(results), 2)
38−
39− def test_response_returns_correct_results(self):
40− response = mock.Mock(text=self.html)
41− results = seedpeer.response(response)
42− self.assertEqual(
43− results[0]['title'], 'Narcos - Season 2 - 720p WEBRiP - x265 HEVC - ShAaNiG '
44− )
45− self.assertEqual(
46− results[0]['url'],
47− 'http://www.seedpeer.eu/details/11685972/Narcos---Season-2---720p-WEBRiP---x265-HEVC---ShAaNiG.html'
48− )
49− self.assertEqual(results[0]['content'], '2.48 GB, 1 day')
50− self.assertEqual(results[0]['seed'], '861')
51− self.assertEqual(results[0]['leech'], '332')
tests/unit/engines/test_subtitleseeker.pydeleted−174
@@ -1,174 +0,0 @@
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− dicto['language'] = 'fr-FR'
14− params = subtitleseeker.request(query, dicto)
15− self.assertTrue('url' in params)
16− self.assertTrue(query in params['url'])
17− self.assertTrue('subtitleseeker.com' in params['url'])
18−
19− def test_response(self):
20− dicto = defaultdict(dict)
21− dicto['language'] = 'fr-FR'
22− response = mock.Mock(search_params=dicto)
23−
24− self.assertRaises(AttributeError, subtitleseeker.response, None)
25− self.assertRaises(AttributeError, subtitleseeker.response, [])
26− self.assertRaises(AttributeError, subtitleseeker.response, '')
27− self.assertRaises(AttributeError, subtitleseeker.response, '[]')
28−
29− response = mock.Mock(text='<html></html>', search_params=dicto)
30− self.assertEqual(subtitleseeker.response(response), [])
31−
32− html = """
33− <div class="boxRows">
34− <div class="boxRowsInner" style="width:600px;">
35− <img src="http://static.subtitleseeker.com/images/movie.gif"
36− style="width:16px; height:16px;" class="icon">
37− <a href="http://this.is.the.url/"
38− class="blue" title="Title subtitle" >
39− This is the Title
40− </a>
41− <br><br>
42− <span class="f10b grey-dark arial" style="padding:0px 0px 5px 20px">
43− "Alternative Title"
44− </span>
45− </div>
46− <div class="boxRowsInner f12b red" style="width:70px;">
47− 1998
48− </div>
49− <div class="boxRowsInner grey-web f12" style="width:120px;">
50− <img src="http://static.subtitleseeker.com/images/basket_put.png"
51− style="width:16px; height:16px;" class="icon">
52− 1039 Subs
53− </div>
54− <div class="boxRowsInner grey-web f10" style="width:130px;">
55− <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
56− style="width:16px; height:16px;" class="icon">
57− 1 hours ago
58− </div>
59− <div class="clear"></div>
60− </div>
61− """
62− response = mock.Mock(text=html, search_params=dicto)
63− results = subtitleseeker.response(response)
64− self.assertEqual(type(results), list)
65− self.assertEqual(len(results), 1)
66− self.assertEqual(results[0]['title'], 'This is the Title')
67− self.assertEqual(results[0]['url'], 'http://this.is.the.url/French/')
68− self.assertIn('1998', results[0]['content'])
69− self.assertIn('1039 Subs', results[0]['content'])
70− self.assertIn('Alternative Title', results[0]['content'])
71−
72− dicto['language'] = 'pt-BR'
73− results = subtitleseeker.response(response)
74− self.assertEqual(results[0]['url'], 'http://this.is.the.url/Brazilian/')
75−
76− html = """
77− <div class="boxRows">
78− <div class="boxRowsInner" style="width:600px;">
79− <img src="http://static.subtitleseeker.com/images/movie.gif"
80− style="width:16px; height:16px;" class="icon">
81− <a href="http://this.is.the.url/"
82− class="blue" title="Title subtitle" >
83− This is the Title
84− </a>
85− </div>
86− <div class="boxRowsInner f12b red" style="width:70px;">
87− 1998
88− </div>
89− <div class="boxRowsInner grey-web f12" style="width:120px;">
90− <img src="http://static.subtitleseeker.com/images/basket_put.png"
91− style="width:16px; height:16px;" class="icon">
92− 1039 Subs
93− </div>
94− <div class="boxRowsInner grey-web f10" style="width:130px;">
95− <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
96− style="width:16px; height:16px;" class="icon">
97− 1 hours ago
98− </div>
99− <div class="clear"></div>
100− </div>
101− """
102− dicto['language'] = 'all'
103− response = mock.Mock(text=html, search_params=dicto)
104− results = subtitleseeker.response(response)
105− self.assertEqual(type(results), list)
106− self.assertEqual(len(results), 1)
107− self.assertEqual(results[0]['title'], 'This is the Title')
108− self.assertEqual(results[0]['url'], 'http://this.is.the.url/')
109− self.assertIn('1998', results[0]['content'])
110− self.assertIn('1039 Subs', results[0]['content'])
111−
112− html = """
113− <div class="boxRows">
114− <div class="boxRowsInner" style="width:600px;">
115− <img src="http://static.subtitleseeker.com/images/movie.gif"
116− style="width:16px; height:16px;" class="icon">
117− <a href="http://this.is.the.url/"
118− class="blue" title="Title subtitle" >
119− This is the Title
120− </a>
121− </div>
122− <div class="boxRowsInner f12b red" style="width:70px;">
123− 1998
124− </div>
125− <div class="boxRowsInner grey-web f12" style="width:120px;">
126− <img src="http://static.subtitleseeker.com/images/basket_put.png"
127− style="width:16px; height:16px;" class="icon">
128− 1039 Subs
129− </div>
130− <div class="boxRowsInner grey-web f10" style="width:130px;">
131− <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
132− style="width:16px; height:16px;" class="icon">
133− 1 hours ago
134− </div>
135− <div class="clear"></div>
136− </div>
137− """
138− subtitleseeker.language = 'English'
139− response = mock.Mock(text=html, search_params=dicto)
140− results = subtitleseeker.response(response)
141− self.assertEqual(type(results), list)
142− self.assertEqual(len(results), 1)
143− self.assertEqual(results[0]['title'], 'This is the Title')
144− self.assertEqual(results[0]['url'], 'http://this.is.the.url/English/')
145− self.assertIn('1998', results[0]['content'])
146− self.assertIn('1039 Subs', results[0]['content'])
147−
148− html = """
149− <div class="boxRowsInner" style="width:600px;">
150− <img src="http://static.subtitleseeker.com/images/movie.gif"
151− style="width:16px; height:16px;" class="icon">
152− <a href="http://this.is.the.url/"
153− class="blue" title="Title subtitle" >
154− This is the Title
155− </a>
156− </div>
157− <div class="boxRowsInner f12b red" style="width:70px;">
158− 1998
159− </div>
160− <div class="boxRowsInner grey-web f12" style="width:120px;">
161− <img src="http://static.subtitleseeker.com/images/basket_put.png"
162− style="width:16px; height:16px;" class="icon">
163− 1039 Subs
164− </div>
165− <div class="boxRowsInner grey-web f10" style="width:130px;">
166− <img src="http://static.subtitleseeker.com/images/arrow_refresh_small.png"
167− style="width:16px; height:16px;" class="icon">
168− 1 hours ago
169− </div>
170− """
171− response = mock.Mock(text=html, search_params=dicto)
172− results = subtitleseeker.response(response)
173− self.assertEqual(type(results), list)
174− self.assertEqual(len(results), 0)
tests/unit/engines/test_swisscows.pydeleted−157
@@ -1,157 +0,0 @@
1−from collections import defaultdict
2−import mock
3−from searx.engines import swisscows
4−from searx.testing import SearxTestCase
5−
6−
7−class TestSwisscowsEngine(SearxTestCase):
8−
9− def test_request(self):
10− swisscows.supported_languages = ['de-AT', 'de-DE']
11− swisscows.language_aliases = {}
12− query = 'test_query'
13− dicto = defaultdict(dict)
14− dicto['pageno'] = 1
15− dicto['language'] = 'de-DE'
16− params = swisscows.request(query, dicto)
17− self.assertTrue('url' in params)
18− self.assertTrue(query in params['url'])
19− self.assertTrue('swisscows.ch' in params['url'])
20− self.assertTrue('uiLanguage=de' in params['url'])
21− self.assertTrue('region=de-DE' in params['url'])
22−
23− dicto['language'] = 'all'
24− params = swisscows.request(query, dicto)
25− self.assertTrue('uiLanguage=browser' in params['url'])
26− self.assertTrue('region=browser' in params['url'])
27−
28− dicto['category'] = 'images'
29− params = swisscows.request(query, dicto)
30− self.assertIn('image', params['url'])
31−
32− def test_response(self):
33− self.assertRaises(AttributeError, swisscows.response, None)
34− self.assertRaises(AttributeError, swisscows.response, [])
35− self.assertRaises(AttributeError, swisscows.response, '')
36− self.assertRaises(AttributeError, swisscows.response, '[]')
37−
38− response = mock.Mock(text=b'<html></html>')
39− self.assertEqual(swisscows.response(response), [])
40−
41− response = mock.Mock(text=b'<html></html>')
42− self.assertEqual(swisscows.response(response), [])
43−
44− html = b"""
45− <script>
46− App.Dispatcher.dispatch("initialize", {
47− html5history: true,
48− initialData: {"Request":
49− {"Page":1,
50− "ItemsCount":1,
51− "Query":"This should ",
52− "NormalizedQuery":"This should ",
53− "Region":"de-AT",
54− "UILanguage":"de"},
55− "Results":{"items":[
56− {"Title":"\uE000This should\uE001 be the title",
57− "Description":"\uE000This should\uE001 be the content.",
58− "Url":"http://this.should.be.the.link/",
59− "DisplayUrl":"www.\uE000this.should.be.the\uE001.link",
60− "Id":"782ef287-e439-451c-b380-6ebc14ba033d"},
61− {"Title":"Datei:This should1.svg",
62− "Url":"https://i.swisscows.ch/?link=http%3a%2f%2fts2.mm.This/should1.png",
63− "SourceUrl":"http://de.wikipedia.org/wiki/Datei:This should1.svg",
64− "DisplayUrl":"de.wikipedia.org/wiki/Datei:This should1.svg",
65− "Width":950,
66− "Height":534,
67− "FileSize":92100,
68− "ContentType":"image/jpeg",
69− "Thumbnail":{
70− "Url":"https://i.swisscows.ch/?link=http%3a%2f%2fts2.mm.This/should1.png",
71− "ContentType":"image/jpeg",
72− "Width":300,
73− "Height":168,
74− "FileSize":9134},
75− "Id":"6a97a542-8f65-425f-b7f6-1178c3aba7be"
76− }
77− ],"TotalCount":55300,
78− "Query":"This should "
79− },
80− "Images":[{"Title":"Datei:This should.svg",
81− "Url":"https://i.swisscows.ch/?link=http%3a%2f%2fts2.mm.This/should.png",
82− "SourceUrl":"http://de.wikipedia.org/wiki/Datei:This should.svg",
83− "DisplayUrl":"de.wikipedia.org/wiki/Datei:This should.svg",
84− "Width":1280,
85− "Height":677,
86− "FileSize":50053,
87− "ContentType":"image/png",
88− "Thumbnail":{"Url":"https://i.swisscows.ch/?link=http%3a%2f%2fts2.mm.This/should.png",
89− "ContentType":"image/png",
90− "Width":300,
91− "Height":158,
92− "FileSize":8023},
93− "Id":"ae230fd8-a06a-47d6-99d5-e74766d8143a"}]},
94− environment: "production"
95− }).then(function (options) {
96− $('#Search_Form').on('submit', function (e) {
97− if (!Modernizr.history) return;
98− e.preventDefault();
99−
100− var $form = $(this),
101− $query = $('#Query'),
102− query = $.trim($query.val()),
103− path = App.Router.makePath($form.attr('action'), null, $form.serializeObject())
104−
105− if (query.length) {
106− options.html5history ?
107− ReactRouter.HistoryLocation.push(path) :
108− ReactRouter.RefreshLocation.push(path);
109− }
110− else $('#Query').trigger('blur');
111− });
112−
113− });
114− </script>
115− """
116− response = mock.Mock(text=html)
117− results = swisscows.response(response)
118− self.assertEqual(type(results), list)
119− self.assertEqual(len(results), 3)
120− self.assertEqual(results[0]['title'], 'This should be the title')
121− self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/')
122− self.assertEqual(results[0]['content'], 'This should be the content.')
123− self.assertEqual(results[1]['title'], 'Datei:This should1.svg')
124− self.assertEqual(results[1]['url'], 'http://de.wikipedia.org/wiki/Datei:This should1.svg')
125− self.assertEqual(results[1]['img_src'], 'http://ts2.mm.This/should1.png')
126− self.assertEqual(results[1]['template'], 'images.html')
127− self.assertEqual(results[2]['title'], 'Datei:This should.svg')
128− self.assertEqual(results[2]['url'], 'http://de.wikipedia.org/wiki/Datei:This should.svg')
129− self.assertEqual(results[2]['img_src'], 'http://ts2.mm.This/should.png')
130− self.assertEqual(results[2]['template'], 'images.html')
131−
132− def test_fetch_supported_languages(self):
133− html = """<html></html>"""
134− response = mock.Mock(text=html)
135− languages = swisscows._fetch_supported_languages(response)
136− self.assertEqual(type(languages), list)
137− self.assertEqual(len(languages), 0)
138−
139− html = """
140− <html>
141− <div id="regions-popup">
142− <div>
143− <ul>
144− <li><a data-search-language="browser"></a></li>
145− <li><a data-search-language="de-CH"></a></li>
146− <li><a data-search-language="fr-CH"></a></li>
147− </ul>
148− </div>
149− </div>
150− </html>
151− """
152− response = mock.Mock(text=html)
153− languages = swisscows._fetch_supported_languages(response)
154− self.assertEqual(type(languages), list)
155− self.assertEqual(len(languages), 3)
156− self.assertIn('de-CH', languages)
157− self.assertIn('fr-CH', languages)