summaryrefslogtreecommitdiff
path: root/searx/tests
diff options
context:
space:
mode:
authorThomas Pointhuber <thomas.pointhuber@gmx.at>2015-06-01 09:15:50 +0200
committerThomas Pointhuber <thomas.pointhuber@gmx.at>2015-06-01 11:04:01 +0200
commitd923b2a420b77a3a29375516ed9929beeda0924a (patch)
tree0130db9458f7baaf25bb0edff837b0129b6a1e50 /searx/tests
parentaac8d3a7bfdd77a5369e52a4ece99b20669a4625 (diff)
downloadsearxng-d923b2a420b77a3a29375516ed9929beeda0924a.tar.gz
searxng-d923b2a420b77a3a29375516ed9929beeda0924a.zip
[enh] implement swisscows engine, FIX #347
TODO: implement image engine
Diffstat (limited to 'searx/tests')
-rw-r--r--searx/tests/engines/test_swisscows.py104
-rw-r--r--searx/tests/test_engines.py1
2 files changed, 105 insertions, 0 deletions
diff --git a/searx/tests/engines/test_swisscows.py b/searx/tests/engines/test_swisscows.py
new file mode 100644
index 000000000..d52952727
--- /dev/null
+++ b/searx/tests/engines/test_swisscows.py
@@ -0,0 +1,104 @@
+from collections import defaultdict
+import mock
+from searx.engines import swisscows
+from searx.testing import SearxTestCase
+
+
+class TestSwisscowsEngine(SearxTestCase):
+
+ def test_request(self):
+ query = 'test_query'
+ dicto = defaultdict(dict)
+ dicto['pageno'] = 1
+ dicto['language'] = 'de_DE'
+ params = swisscows.request(query, dicto)
+ self.assertTrue('url' in params)
+ self.assertTrue(query in params['url'])
+ self.assertTrue('swisscows.ch' in params['url'])
+ self.assertTrue('uiLanguage=de' in params['url'])
+ self.assertTrue('region=de-DE' in params['url'])
+
+ dicto['language'] = 'all'
+ params = swisscows.request(query, dicto)
+ self.assertTrue('uiLanguage=browser' in params['url'])
+ self.assertTrue('region=browser' in params['url'])
+
+ def test_response(self):
+ self.assertRaises(AttributeError, swisscows.response, None)
+ self.assertRaises(AttributeError, swisscows.response, [])
+ self.assertRaises(AttributeError, swisscows.response, '')
+ self.assertRaises(AttributeError, swisscows.response, '[]')
+
+ response = mock.Mock(content='<html></html>')
+ self.assertEqual(swisscows.response(response), [])
+
+ response = mock.Mock(content='<html></html>')
+ self.assertEqual(swisscows.response(response), [])
+
+ html = u"""
+ <script>
+ App.Dispatcher.dispatch("initialize", {
+ html5history: true,
+ initialData: {"Request":
+ {"Page":1,
+ "ItemsCount":1,
+ "Query":"This should ",
+ "NormalizedQuery":"This should ",
+ "Region":"de-AT",
+ "UILanguage":"de"},
+ "Results":{"items":[
+ {"Title":"\uE000This should\uE001 be the title",
+ "Description":"\uE000This should\uE001 be the content.",
+ "Url":"http://this.should.be.the.link/",
+ "DisplayUrl":"www.\uE000this.should.be.the\uE001.link",
+ "Id":"782ef287-e439-451c-b380-6ebc14ba033d"}
+ ],"TotalCount":55300,
+ "Query":"This should "
+ },
+ "Images":[{"Title":"Datei:This should.svg",
+ "Url":"https://i.swisscows.ch/?link=http%3a%2f%2fts2.mm.This/should.png",
+ "SourceUrl":"http://de.wikipedia.org/wiki/Datei:This should.svg",
+ "DisplayUrl":"de.wikipedia.org/wiki/Datei:This should.svg",
+ "Width":1280,
+ "Height":677,
+ "FileSize":50053,
+ "ContentType":"image/png",
+ "Thumbnail":{"Url":"https://i.swisscows.ch/?link=http%3a%2f%2fts2.mm.This/should.png",
+ "ContentType":"image/png",
+ "Width":300,
+ "Height":158,
+ "FileSize":8023},
+ "Id":"ae230fd8-a06a-47d6-99d5-e74766d8143a"}]},
+ environment: "production"
+ }).then(function (options) {
+ $('#Search_Form').on('submit', function (e) {
+ if (!Modernizr.history) return;
+ e.preventDefault();
+
+ var $form = $(this),
+ $query = $('#Query'),
+ query = $.trim($query.val()),
+ path = App.Router.makePath($form.attr('action'), null, $form.serializeObject())
+
+ if (query.length) {
+ options.html5history ?
+ ReactRouter.HistoryLocation.push(path) :
+ ReactRouter.RefreshLocation.push(path);
+ }
+ else $('#Query').trigger('blur');
+ });
+
+ });
+ </script>
+ """
+ response = mock.Mock(content=html)
+ results = swisscows.response(response)
+ self.assertEqual(type(results), list)
+ self.assertEqual(len(results), 2)
+ self.assertEqual(results[0]['title'], 'This should be the title')
+ self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/')
+ self.assertEqual(results[0]['content'], 'This should be the content.')
+ self.assertEqual(results[1]['title'], 'Datei:This should.svg')
+ self.assertEqual(results[1]['url'], 'http://de.wikipedia.org/wiki/Datei:This should.svg')
+ self.assertEqual(results[1]['img_src'], 'http://ts2.mm.This/should.png')
+ self.assertEqual(results[1]['template'], 'images.html')
diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py
index 5770458f3..90f0ce846 100644
--- a/searx/tests/test_engines.py
+++ b/searx/tests/test_engines.py
@@ -32,6 +32,7 @@ from searx.tests.engines.test_spotify import * # noqa
from searx.tests.engines.test_stackoverflow import * # noqa
from searx.tests.engines.test_startpage import * # noqa
from searx.tests.engines.test_subtitleseeker import * # noqa
+from searx.tests.engines.test_swisscows import * # noqa
from searx.tests.engines.test_twitter import * # noqa
from searx.tests.engines.test_vimeo import * # noqa
from searx.tests.engines.test_www1x import * # noqa