summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/robot/test_basic.robot108
-rw-r--r--tests/unit/engines/test_google_images.py6
-rw-r--r--tests/unit/test_preferences.py101
-rw-r--r--tests/unit/test_webapp.py6
4 files changed, 217 insertions, 4 deletions
diff --git a/tests/robot/test_basic.robot b/tests/robot/test_basic.robot
index 1b8e78fff..4a20d0ba2 100644
--- a/tests/robot/test_basic.robot
+++ b/tests/robot/test_basic.robot
@@ -42,3 +42,111 @@ Change language
Location Should Be http://localhost:11111/
Page Should Contain rólunk
Page Should Contain beállítások
+
+Change method
+ Page Should Contain about
+ Page Should Contain preferences
+ Go To http://localhost:11111/preferences
+ Select From List method GET
+ Submit Form id=search_form
+ Location Should Be http://localhost:11111/
+ Go To http://localhost:11111/preferences
+ List Selection Should Be method GET
+ Select From List method POST
+ Submit Form id=search_form
+ Location Should Be http://localhost:11111/
+ Go To http://localhost:11111/preferences
+ List Selection Should Be method POST
+
+Change theme
+ Page Should Contain about
+ Page Should Contain preferences
+ Go To http://localhost:11111/preferences
+ List Selection Should Be theme default
+ Select From List theme oscar
+ Submit Form id=search_form
+ Location Should Be http://localhost:11111/
+ Go To http://localhost:11111/preferences
+ List Selection Should Be theme oscar
+
+Change safesearch
+ Page Should Contain about
+ Page Should Contain preferences
+ Go To http://localhost:11111/preferences
+ List Selection Should Be safesearch None
+ Select From List safesearch Strict
+ Submit Form id=search_form
+ Location Should Be http://localhost:11111/
+ Go To http://localhost:11111/preferences
+ List Selection Should Be safesearch Strict
+
+Change image proxy
+ Page Should Contain about
+ Page Should Contain preferences
+ Go To http://localhost:11111/preferences
+ List Selection Should Be image_proxy Disabled
+ Select From List image_proxy Enabled
+ Submit Form id=search_form
+ Location Should Be http://localhost:11111/
+ Go To http://localhost:11111/preferences
+ List Selection Should Be image_proxy Enabled
+
+Change search language
+ Page Should Contain about
+ Page Should Contain preferences
+ Go To http://localhost:11111/preferences
+ List Selection Should Be language Automatic
+ Select From List language Turkish (Turkey) - tr_TR
+ Submit Form id=search_form
+ Location Should Be http://localhost:11111/
+ Go To http://localhost:11111/preferences
+ List Selection Should Be language Turkish (Turkey) - tr_TR
+
+Change autocomplete
+ Page Should Contain about
+ Page Should Contain preferences
+ Go To http://localhost:11111/preferences
+ List Selection Should Be autocomplete -
+ Select From List autocomplete google
+ Submit Form id=search_form
+ Location Should Be http://localhost:11111/
+ Go To http://localhost:11111/preferences
+ List Selection Should Be autocomplete google
+
+Change allowed/disabled engines
+ Page Should Contain about
+ Page Should Contain preferences
+ Go To http://localhost:11111/preferences
+ Page Should Contain Engine name
+ Element Should Contain xpath=//label[@class="deny"][@for='engine_dummy_dummy_dummy'] Block
+ Element Should Contain xpath=//label[@class="deny"][@for='engine_general_general_dummy'] Block
+ Click Element xpath=//label[@class="deny"][@for='engine_general_general_dummy']
+ Submit Form id=search_form
+ Location Should Be http://localhost:11111/
+ Page Should Contain about
+ Page Should Contain preferences
+ Go To http://localhost:11111/preferences
+ Page Should Contain Engine name
+ Element Should Contain xpath=//label[@class="deny"][@for='engine_dummy_dummy_dummy'] Block
+ Element Should Contain xpath=//label[@class="deny"][@for='engine_general_general_dummy'] \
+
+Block a plugin
+ Page Should Contain about
+ Page Should Contain preferences
+ Go To http://localhost:11111/preferences
+ List Selection Should Be theme default
+ Select From List theme oscar
+ Submit Form id=search_form
+ Location Should Be http://localhost:11111/
+ Go To http://localhost:11111/preferences
+ List Selection Should Be theme oscar
+ Page Should Contain Plugins
+ Click Link Plugins
+ Checkbox Should Not Be Selected id=plugin_HTTPS_rewrite
+ Click Element xpath=//label[@for='plugin_HTTPS_rewrite']
+ Submit Form id=search_form
+ Location Should Be http://localhost:11111/
+ Go To http://localhost:11111/preferences
+ Page Should Contain Plugins
+ Click Link Plugins
+ Checkbox Should Be Selected id=plugin_HTTPS_rewrite
diff --git a/tests/unit/engines/test_google_images.py b/tests/unit/engines/test_google_images.py
index 876d0af1e..5f184e00c 100644
--- a/tests/unit/engines/test_google_images.py
+++ b/tests/unit/engines/test_google_images.py
@@ -41,7 +41,7 @@ class TestGoogleImagesEngine(SearxTestCase):
</div>
</a>
<div class="rg_meta">
- {"id":"bQWQ9wz9loJmjM:","isu":"clker.com","ity":"png","md":"/search?tbs\u003dsbi:AMhZZit7u1mHyop9pQisu-5idR-8W_1Itvwc3afChmsjQYPx_1yYMzBvUZgtkcGoojqekKZ-6n_1rjX9ySH0OWA_1eO5OijFY6BBDw_1GApr6xxb1bXJcBcj-DiguMoXWW7cZSG7MRQbwnI5SoDZNXcv_1xGszy886I7NVb_1oRKSliTHtzqbXAxhvYreM","msu":"/search?q\u003dsouth\u0026biw\u003d1364\u0026bih\u003d235\u0026tbm\u003disch\u0026tbs\u003dsimg:CAQSEgltBZD3DP2WgiG-U42R4G0RFw","oh":598,"os":"13KB","ow":504,"pt":"South Arrow Clip Art at Clker.com - vector clip art online ...","rid":"vlONkeBtERfDuM","s":"Download this image as:","sc":1,"si":"/search?q\u003dsouth\u0026biw\u003d1364\u0026bih\u003d235\u0026tbm\u003disch\u0026tbs\u003dsimg:CAESEgltBZD3DP2WgiG-U42R4G0RFw","th":245,"tu":"https://thumbnail.url/","tw":206}
+ {"id":"bQWQ9wz9loJmjM:","isu":"clker.com","ity":"png","md":"/search?tbs\u003dsbi:AMhZZit7u1mHyop9pQisu-5idR-8W_1Itvwc3afChmsjQYPx_1yYMzBvUZgtkcGoojqekKZ-6n_1rjX9ySH0OWA_1eO5OijFY6BBDw_1GApr6xxb1bXJcBcj-DiguMoXWW7cZSG7MRQbwnI5SoDZNXcv_1xGszy886I7NVb_1oRKSliTHtzqbXAxhvYreM","msu":"/search?q\u003dsouth\u0026biw\u003d1364\u0026bih\u003d235\u0026tbm\u003disch\u0026tbs\u003dsimg:CAQSEgltBZD3DP2WgiG-U42R4G0RFw","oh":598,"os":"13KB","ow":504,"pt":"South Arrow Clip Art at Clker.com - vector clip art online ...","rid":"vlONkeBtERfDuM","s":"Download this image as:","sc":1,"si":"/search?q\u003dsouth\u0026biw\u003d1364\u0026bih\u003d235\u0026tbm\u003disch\u0026tbs\u003dsimg:CAESEgltBZD3DP2WgiG-U42R4G0RFw","th":245,"tu":"https://thumbnail.url/","tw":206,"ru":"a","ou":"b"}
</div>
</div><!--n--><!--m-->
</div>
@@ -52,7 +52,7 @@ class TestGoogleImagesEngine(SearxTestCase):
self.assertEqual(type(results), list)
self.assertEqual(len(results), 1)
self.assertEqual(results[0]['title'], u'South Arrow Clip Art at Clker.com - vector clip art online ...')
- self.assertEqual(results[0]['url'], 'http://www.clker.com/clipart-south-arrow.html')
+ self.assertEqual(results[0]['url'], 'a')
self.assertEqual(results[0]['thumbnail_src'], 'https://thumbnail.url/')
- self.assertEqual(results[0]['img_src'], 'http://www.clker.com/cliparts/H/X/l/b/0/0/south-arrow-hi.png')
+ self.assertEqual(results[0]['img_src'], 'b')
self.assertEqual(results[0]['content'], 'Download this image as:')
diff --git a/tests/unit/test_preferences.py b/tests/unit/test_preferences.py
new file mode 100644
index 000000000..e418c0af4
--- /dev/null
+++ b/tests/unit/test_preferences.py
@@ -0,0 +1,101 @@
+from searx.preferences import (EnumStringSetting, MapSetting, MissingArgumentException,
+ MultipleChoiceSetting, PluginsSetting, ValidationException)
+from searx.testing import SearxTestCase
+
+
+class PluginStub(object):
+ def __init__(self, id, default_on):
+ self.id = id
+ self.default_on = default_on
+
+
+class TestSettings(SearxTestCase):
+ # map settings
+ def test_map_setting_invalid_initialization(self):
+ with self.assertRaises(MissingArgumentException):
+ setting = MapSetting(3, wrong_argument={'0': 0})
+
+ def test_map_setting_invalid_default_value(self):
+ with self.assertRaises(ValidationException):
+ setting = MapSetting(3, map={'dog': 1, 'bat': 2})
+
+ def test_map_setting_invalid_choice(self):
+ setting = MapSetting(2, map={'dog': 1, 'bat': 2})
+ with self.assertRaises(ValidationException):
+ setting.parse('cat')
+
+ def test_map_setting_valid_default(self):
+ setting = MapSetting(3, map={'dog': 1, 'bat': 2, 'cat': 3})
+ self.assertEquals(setting.get_value(), 3)
+
+ def test_map_setting_valid_choice(self):
+ setting = MapSetting(3, map={'dog': 1, 'bat': 2, 'cat': 3})
+ self.assertEquals(setting.get_value(), 3)
+ setting.parse('bat')
+ self.assertEquals(setting.get_value(), 2)
+
+ def test_enum_setting_invalid_initialization(self):
+ with self.assertRaises(MissingArgumentException):
+ setting = EnumStringSetting('cat', wrong_argument=[0, 1, 2])
+
+ # enum settings
+ def test_enum_setting_invalid_initialization(self):
+ with self.assertRaises(MissingArgumentException):
+ setting = EnumStringSetting('cat', wrong_argument=[0, 1, 2])
+
+ def test_enum_setting_invalid_default_value(self):
+ with self.assertRaises(ValidationException):
+ setting = EnumStringSetting(3, choices=[0, 1, 2])
+
+ def test_enum_setting_invalid_choice(self):
+ setting = EnumStringSetting(0, choices=[0, 1, 2])
+ with self.assertRaises(ValidationException):
+ setting.parse(3)
+
+ def test_enum_setting_valid_default(self):
+ setting = EnumStringSetting(3, choices=[1, 2, 3])
+ self.assertEquals(setting.get_value(), 3)
+
+ def test_enum_setting_valid_choice(self):
+ setting = EnumStringSetting(3, choices=[1, 2, 3])
+ self.assertEquals(setting.get_value(), 3)
+ setting.parse(2)
+ self.assertEquals(setting.get_value(), 2)
+
+ # multiple choice settings
+ def test_multiple_setting_invalid_initialization(self):
+ with self.assertRaises(MissingArgumentException):
+ setting = MultipleChoiceSetting(['2'], wrong_argument=['0', '1', '2'])
+
+ def test_multiple_setting_invalid_default_value(self):
+ with self.assertRaises(ValidationException):
+ setting = MultipleChoiceSetting(['3', '4'], choices=['0', '1', '2'])
+
+ def test_multiple_setting_invalid_choice(self):
+ setting = MultipleChoiceSetting(['1', '2'], choices=['0', '1', '2'])
+ with self.assertRaises(ValidationException):
+ setting.parse('4, 3')
+
+ def test_multiple_setting_valid_default(self):
+ setting = MultipleChoiceSetting(['3'], choices=['1', '2', '3'])
+ self.assertEquals(setting.get_value(), ['3'])
+
+ def test_multiple_setting_valid_choice(self):
+ setting = MultipleChoiceSetting(['3'], choices=['1', '2', '3'])
+ self.assertEquals(setting.get_value(), ['3'])
+ setting.parse('2')
+ self.assertEquals(setting.get_value(), ['2'])
+
+ # plugins settings
+ def test_plugins_setting_all_default_enabled(self):
+ plugin1 = PluginStub('plugin1', True)
+ plugin2 = PluginStub('plugin2', True)
+ setting = PluginsSetting(['3'], choices=[plugin1, plugin2])
+ self.assertEquals(setting.get_enabled(), set(['plugin1', 'plugin2']))
+
+ def test_plugins_setting_few_default_enabled(self):
+ plugin1 = PluginStub('plugin1', True)
+ plugin2 = PluginStub('plugin2', False)
+ plugin3 = PluginStub('plugin3', True)
+ setting = PluginsSetting('name', choices=[plugin1, plugin2, plugin3])
+ self.assertEquals(setting.get_enabled(), set(['plugin1', 'plugin3']))
diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py
index 071c01df3..5697017d9 100644
--- a/tests/unit/test_webapp.py
+++ b/tests/unit/test_webapp.py
@@ -12,7 +12,6 @@ class ViewsTestCase(SearxTestCase):
def setUp(self):
webapp.app.config['TESTING'] = True # to get better error messages
self.app = webapp.app.test_client()
- webapp.default_theme = 'default'
# set some defaults
self.test_results = [
@@ -43,6 +42,11 @@ class ViewsTestCase(SearxTestCase):
webapp.Search.search = search_mock
+ def get_current_theme_name_mock(override=None):
+ return 'default'
+
+ webapp.get_current_theme_name = get_current_theme_name_mock
+
self.maxDiff = None # to see full diffs
def test_index_empty(self):