Pārlūkot izejas kodu

add unit && robot tests

Noemi Vanyi 9 gadus atpakaļ
vecāks
revīzija
f0fd9ad628
2 mainītis faili ar 209 papildinājumiem un 0 dzēšanām
  1. 108
    0
      tests/robot/test_basic.robot
  2. 101
    0
      tests/unit/test_preferences.py

+ 108
- 0
tests/robot/test_basic.robot Parādīt failu

@@ -42,3 +42,111 @@ Change language
42 42
     Location Should Be  http://localhost:11111/
43 43
     Page Should Contain  rólunk
44 44
     Page Should Contain  beállítások
45
+
46
+Change method
47
+    Page Should Contain  about
48
+    Page Should Contain  preferences
49
+    Go To  http://localhost:11111/preferences
50
+    Select From List  method  GET
51
+    Submit Form  id=search_form
52
+    Location Should Be  http://localhost:11111/
53
+    Go To  http://localhost:11111/preferences
54
+    List Selection Should Be  method  GET
55
+    Select From List  method  POST
56
+    Submit Form  id=search_form
57
+    Location Should Be  http://localhost:11111/
58
+    Go To  http://localhost:11111/preferences
59
+    List Selection Should Be  method  POST
60
+
61
+Change theme
62
+    Page Should Contain  about
63
+    Page Should Contain  preferences
64
+    Go To  http://localhost:11111/preferences
65
+    List Selection Should Be  theme  default
66
+    Select From List  theme  oscar
67
+    Submit Form  id=search_form
68
+    Location Should Be  http://localhost:11111/
69
+    Go To  http://localhost:11111/preferences
70
+    List Selection Should Be  theme  oscar
71
+
72
+Change safesearch
73
+    Page Should Contain  about
74
+    Page Should Contain  preferences
75
+    Go To  http://localhost:11111/preferences
76
+    List Selection Should Be  safesearch  None
77
+    Select From List  safesearch  Strict
78
+    Submit Form  id=search_form
79
+    Location Should Be  http://localhost:11111/
80
+    Go To  http://localhost:11111/preferences
81
+    List Selection Should Be  safesearch  Strict
82
+
83
+Change image proxy
84
+    Page Should Contain  about
85
+    Page Should Contain  preferences
86
+    Go To  http://localhost:11111/preferences
87
+    List Selection Should Be  image_proxy  Disabled
88
+    Select From List  image_proxy  Enabled
89
+    Submit Form  id=search_form
90
+    Location Should Be  http://localhost:11111/
91
+    Go To  http://localhost:11111/preferences
92
+    List Selection Should Be  image_proxy  Enabled
93
+
94
+Change search language
95
+    Page Should Contain  about
96
+    Page Should Contain  preferences
97
+    Go To  http://localhost:11111/preferences
98
+    List Selection Should Be  language  Automatic
99
+    Select From List  language  Turkish (Turkey) - tr_TR
100
+    Submit Form  id=search_form
101
+    Location Should Be  http://localhost:11111/
102
+    Go To  http://localhost:11111/preferences
103
+    List Selection Should Be  language  Turkish (Turkey) - tr_TR
104
+
105
+Change autocomplete
106
+    Page Should Contain  about
107
+    Page Should Contain  preferences
108
+    Go To  http://localhost:11111/preferences
109
+    List Selection Should Be  autocomplete  -
110
+    Select From List  autocomplete  google
111
+    Submit Form  id=search_form
112
+    Location Should Be  http://localhost:11111/
113
+    Go To  http://localhost:11111/preferences
114
+    List Selection Should Be  autocomplete  google
115
+
116
+Change allowed/disabled engines
117
+    Page Should Contain  about
118
+    Page Should Contain  preferences
119
+    Go To  http://localhost:11111/preferences
120
+    Page Should Contain  Engine name
121
+    Element Should Contain  xpath=//label[@class="deny"][@for='engine_dummy_dummy_dummy']  Block
122
+    Element Should Contain  xpath=//label[@class="deny"][@for='engine_general_general_dummy']  Block
123
+    Click Element  xpath=//label[@class="deny"][@for='engine_general_general_dummy']
124
+    Submit Form  id=search_form
125
+    Location Should Be  http://localhost:11111/
126
+    Page Should Contain  about
127
+    Page Should Contain  preferences
128
+    Go To  http://localhost:11111/preferences
129
+    Page Should Contain  Engine name
130
+    Element Should Contain  xpath=//label[@class="deny"][@for='engine_dummy_dummy_dummy']  Block
131
+    Element Should Contain  xpath=//label[@class="deny"][@for='engine_general_general_dummy']  \
132
+
133
+Block a plugin
134
+    Page Should Contain  about
135
+    Page Should Contain  preferences
136
+    Go To  http://localhost:11111/preferences
137
+    List Selection Should Be  theme  default
138
+    Select From List  theme  oscar
139
+    Submit Form  id=search_form
140
+    Location Should Be  http://localhost:11111/
141
+    Go To  http://localhost:11111/preferences
142
+    List Selection Should Be  theme  oscar
143
+    Page Should Contain  Plugins
144
+    Click Link  Plugins
145
+    Checkbox Should Not Be Selected  id=plugin_HTTPS_rewrite
146
+    Click Element  xpath=//label[@for='plugin_HTTPS_rewrite']
147
+    Submit Form  id=search_form
148
+    Location Should Be  http://localhost:11111/
149
+    Go To  http://localhost:11111/preferences
150
+    Page Should Contain  Plugins
151
+    Click Link  Plugins
152
+    Checkbox Should Be Selected  id=plugin_HTTPS_rewrite

+ 101
- 0
tests/unit/test_preferences.py Parādīt failu

@@ -0,0 +1,101 @@
1
+from searx.preferences import (EnumStringSetting, MapSetting, MissingArgumentException,
2
+                               MultipleChoiceSetting, PluginsSetting, ValidationException)
3
+from searx.testing import SearxTestCase
4
+
5
+
6
+class PluginStub(object):
7
+    def __init__(self, id, default_on):
8
+        self.id = id
9
+        self.default_on = default_on
10
+
11
+
12
+class TestSettings(SearxTestCase):
13
+    # map settings
14
+    def test_map_setting_invalid_initialization(self):
15
+        with self.assertRaises(MissingArgumentException):
16
+            setting = MapSetting(3, wrong_argument={'0': 0})
17
+
18
+    def test_map_setting_invalid_default_value(self):
19
+        with self.assertRaises(ValidationException):
20
+            setting = MapSetting(3, map={'dog': 1, 'bat': 2})
21
+
22
+    def test_map_setting_invalid_choice(self):
23
+        setting = MapSetting(2, map={'dog': 1, 'bat': 2})
24
+        with self.assertRaises(ValidationException):
25
+            setting.parse('cat')
26
+
27
+    def test_map_setting_valid_default(self):
28
+        setting = MapSetting(3, map={'dog': 1, 'bat': 2, 'cat': 3})
29
+        self.assertEquals(setting.get_value(), 3)
30
+
31
+    def test_map_setting_valid_choice(self):
32
+        setting = MapSetting(3, map={'dog': 1, 'bat': 2, 'cat': 3})
33
+        self.assertEquals(setting.get_value(), 3)
34
+        setting.parse('bat')
35
+        self.assertEquals(setting.get_value(), 2)
36
+
37
+    def test_enum_setting_invalid_initialization(self):
38
+        with self.assertRaises(MissingArgumentException):
39
+            setting = EnumStringSetting('cat', wrong_argument=[0, 1, 2])
40
+
41
+    # enum settings
42
+    def test_enum_setting_invalid_initialization(self):
43
+        with self.assertRaises(MissingArgumentException):
44
+            setting = EnumStringSetting('cat', wrong_argument=[0, 1, 2])
45
+
46
+    def test_enum_setting_invalid_default_value(self):
47
+        with self.assertRaises(ValidationException):
48
+            setting = EnumStringSetting(3, choices=[0, 1, 2])
49
+
50
+    def test_enum_setting_invalid_choice(self):
51
+        setting = EnumStringSetting(0, choices=[0, 1, 2])
52
+        with self.assertRaises(ValidationException):
53
+            setting.parse(3)
54
+
55
+    def test_enum_setting_valid_default(self):
56
+        setting = EnumStringSetting(3, choices=[1, 2, 3])
57
+        self.assertEquals(setting.get_value(), 3)
58
+
59
+    def test_enum_setting_valid_choice(self):
60
+        setting = EnumStringSetting(3, choices=[1, 2, 3])
61
+        self.assertEquals(setting.get_value(), 3)
62
+        setting.parse(2)
63
+        self.assertEquals(setting.get_value(), 2)
64
+
65
+    # multiple choice settings
66
+    def test_multiple_setting_invalid_initialization(self):
67
+        with self.assertRaises(MissingArgumentException):
68
+            setting = MultipleChoiceSetting(['2'], wrong_argument=['0', '1', '2'])
69
+
70
+    def test_multiple_setting_invalid_default_value(self):
71
+        with self.assertRaises(ValidationException):
72
+            setting = MultipleChoiceSetting(['3', '4'], choices=['0', '1', '2'])
73
+
74
+    def test_multiple_setting_invalid_choice(self):
75
+        setting = MultipleChoiceSetting(['1', '2'], choices=['0', '1', '2'])
76
+        with self.assertRaises(ValidationException):
77
+            setting.parse('4, 3')
78
+
79
+    def test_multiple_setting_valid_default(self):
80
+        setting = MultipleChoiceSetting(['3'], choices=['1', '2', '3'])
81
+        self.assertEquals(setting.get_value(), ['3'])
82
+
83
+    def test_multiple_setting_valid_choice(self):
84
+        setting = MultipleChoiceSetting(['3'], choices=['1', '2', '3'])
85
+        self.assertEquals(setting.get_value(), ['3'])
86
+        setting.parse('2')
87
+        self.assertEquals(setting.get_value(), ['2'])
88
+
89
+    # plugins settings
90
+    def test_plugins_setting_all_default_enabled(self):
91
+        plugin1 = PluginStub('plugin1', True)
92
+        plugin2 = PluginStub('plugin2', True)
93
+        setting = PluginsSetting(['3'], choices=[plugin1, plugin2])
94
+        self.assertEquals(setting.get_enabled(), set(['plugin1', 'plugin2']))
95
+
96
+    def test_plugins_setting_few_default_enabled(self):
97
+        plugin1 = PluginStub('plugin1', True)
98
+        plugin2 = PluginStub('plugin2', False)
99
+        plugin3 = PluginStub('plugin3', True)
100
+        setting = PluginsSetting('name', choices=[plugin1, plugin2, plugin3])
101
+        self.assertEquals(setting.get_enabled(), set(['plugin1', 'plugin3']))