##// END OF EJS Templates
tests: Change default settings in tests to 'http'
Martin Bornhold -
r966:d114dcc6 default
parent child Browse files
Show More
@@ -1,202 +1,203 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2016 RhodeCode GmbH
3 # Copyright (C) 2016-2016 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21
21
22 import pytest
22 import pytest
23
23
24 from rhodecode.config.middleware import (
24 from rhodecode.config.middleware import (
25 _sanitize_vcs_settings, _bool_setting, _string_setting, _list_setting,
25 _sanitize_vcs_settings, _bool_setting, _string_setting, _list_setting,
26 _int_setting)
26 _int_setting)
27
27
28
28
29 class TestHelperFunctions(object):
29 class TestHelperFunctions(object):
30 @pytest.mark.parametrize('raw, expected', [
30 @pytest.mark.parametrize('raw, expected', [
31 ('true', True), (u'true', True),
31 ('true', True), (u'true', True),
32 ('yes', True), (u'yes', True),
32 ('yes', True), (u'yes', True),
33 ('on', True), (u'on', True),
33 ('on', True), (u'on', True),
34 ('false', False), (u'false', False),
34 ('false', False), (u'false', False),
35 ('no', False), (u'no', False),
35 ('no', False), (u'no', False),
36 ('off', False), (u'off', False),
36 ('off', False), (u'off', False),
37 ('invalid-bool-value', False),
37 ('invalid-bool-value', False),
38 ('invalid-∫øø@-√Γ₯@¨€', False),
38 ('invalid-∫øø@-√Γ₯@¨€', False),
39 (u'invalid-∫øø@-√Γ₯@¨€', False),
39 (u'invalid-∫øø@-√Γ₯@¨€', False),
40 ])
40 ])
41 def test_bool_setting_helper(self, raw, expected):
41 def test_bool_setting_helper(self, raw, expected):
42 key = 'dummy-key'
42 key = 'dummy-key'
43 settings = {key: raw}
43 settings = {key: raw}
44 _bool_setting(settings, key, None)
44 _bool_setting(settings, key, None)
45 assert settings[key] is expected
45 assert settings[key] is expected
46
46
47 @pytest.mark.parametrize('raw, expected', [
47 @pytest.mark.parametrize('raw, expected', [
48 ('', ''),
48 ('', ''),
49 ('test-string', 'test-string'),
49 ('test-string', 'test-string'),
50 ('CaSe-TeSt', 'case-test'),
50 ('CaSe-TeSt', 'case-test'),
51 ('test-string-烩€', 'test-string-烩€'),
51 ('test-string-烩€', 'test-string-烩€'),
52 (u'test-string-烩€', u'test-string-烩€'),
52 (u'test-string-烩€', u'test-string-烩€'),
53 ])
53 ])
54 def test_string_setting_helper(self, raw, expected):
54 def test_string_setting_helper(self, raw, expected):
55 key = 'dummy-key'
55 key = 'dummy-key'
56 settings = {key: raw}
56 settings = {key: raw}
57 _string_setting(settings, key, None)
57 _string_setting(settings, key, None)
58 assert settings[key] == expected
58 assert settings[key] == expected
59
59
60 @pytest.mark.parametrize('raw, expected', [
60 @pytest.mark.parametrize('raw, expected', [
61 ('', []),
61 ('', []),
62 ('test', ['test']),
62 ('test', ['test']),
63 ('CaSe-TeSt', ['CaSe-TeSt']),
63 ('CaSe-TeSt', ['CaSe-TeSt']),
64 ('test-string-烩€', ['test-string-烩€']),
64 ('test-string-烩€', ['test-string-烩€']),
65 (u'test-string-烩€', [u'test-string-烩€']),
65 (u'test-string-烩€', [u'test-string-烩€']),
66 ('hg git svn', ['hg', 'git', 'svn']),
66 ('hg git svn', ['hg', 'git', 'svn']),
67 ('hg,git,svn', ['hg', 'git', 'svn']),
67 ('hg,git,svn', ['hg', 'git', 'svn']),
68 ('hg, git, svn', ['hg', 'git', 'svn']),
68 ('hg, git, svn', ['hg', 'git', 'svn']),
69 ('hg\ngit\nsvn', ['hg', 'git', 'svn']),
69 ('hg\ngit\nsvn', ['hg', 'git', 'svn']),
70 (' hg\n git\n svn ', ['hg', 'git', 'svn']),
70 (' hg\n git\n svn ', ['hg', 'git', 'svn']),
71 (', hg , git , svn , ', ['', 'hg', 'git', 'svn', '']),
71 (', hg , git , svn , ', ['', 'hg', 'git', 'svn', '']),
72 ('cheese,free node,other', ['cheese', 'free node', 'other']),
72 ('cheese,free node,other', ['cheese', 'free node', 'other']),
73 ])
73 ])
74 def test_list_setting_helper(self, raw, expected):
74 def test_list_setting_helper(self, raw, expected):
75 key = 'dummy-key'
75 key = 'dummy-key'
76 settings = {key: raw}
76 settings = {key: raw}
77 _list_setting(settings, key, None)
77 _list_setting(settings, key, None)
78 assert settings[key] == expected
78 assert settings[key] == expected
79
79
80 @pytest.mark.parametrize('raw, expected', [
80 @pytest.mark.parametrize('raw, expected', [
81 ('0', 0),
81 ('0', 0),
82 ('-0', 0),
82 ('-0', 0),
83 ('12345', 12345),
83 ('12345', 12345),
84 ('-12345', -12345),
84 ('-12345', -12345),
85 (u'-12345', -12345),
85 (u'-12345', -12345),
86 ])
86 ])
87 def test_int_setting_helper(self, raw, expected):
87 def test_int_setting_helper(self, raw, expected):
88 key = 'dummy-key'
88 key = 'dummy-key'
89 settings = {key: raw}
89 settings = {key: raw}
90 _int_setting(settings, key, None)
90 _int_setting(settings, key, None)
91 assert settings[key] == expected
91 assert settings[key] == expected
92
92
93 @pytest.mark.parametrize('raw', [
93 @pytest.mark.parametrize('raw', [
94 ('0xff'),
94 ('0xff'),
95 (''),
95 (''),
96 ('invalid-int'),
96 ('invalid-int'),
97 ('invalid-⁄~†'),
97 ('invalid-⁄~†'),
98 (u'invalid-⁄~†'),
98 (u'invalid-⁄~†'),
99 ])
99 ])
100 def test_int_setting_helper_invalid_input(self, raw):
100 def test_int_setting_helper_invalid_input(self, raw):
101 key = 'dummy-key'
101 key = 'dummy-key'
102 settings = {key: raw}
102 settings = {key: raw}
103 with pytest.raises(Exception):
103 with pytest.raises(Exception):
104 _int_setting(settings, key, None)
104 _int_setting(settings, key, None)
105
105
106
106
107 class TestSanitizeVcsSettings(object):
107 class TestSanitizeVcsSettings(object):
108 _bool_settings = [
108 _bool_settings = [
109 ('vcs.hooks.direct_calls', False),
109 ('vcs.hooks.direct_calls', False),
110 ('vcs.server.enable', True),
110 ('vcs.server.enable', True),
111 ('vcs.start_server', False),
111 ('vcs.start_server', False),
112 ('startup.import_repos', False),
112 ('startup.import_repos', False),
113 ]
113 ]
114
114
115 _string_settings = [
115 _string_settings = [
116 ('vcs.svn.compatible_version', ''),
116 ('vcs.svn.compatible_version', ''),
117 ('git_rev_filter', '--all'),
117 ('git_rev_filter', '--all'),
118 ('vcs.hooks.protocol', 'pyro4'),
118 ('vcs.hooks.protocol', 'http'),
119 ('vcs.scm_app_implementation', 'http'),
119 ('vcs.server', ''),
120 ('vcs.server', ''),
120 ('vcs.server.log_level', 'debug'),
121 ('vcs.server.log_level', 'debug'),
121 ('vcs.server.protocol', 'pyro4'),
122 ('vcs.server.protocol', 'http'),
122 ]
123 ]
123
124
124 _list_settings = [
125 _list_settings = [
125 ('vcs.backends', 'hg git'),
126 ('vcs.backends', 'hg git'),
126 ]
127 ]
127
128
128 @pytest.mark.parametrize('key, default', _list_settings)
129 @pytest.mark.parametrize('key, default', _list_settings)
129 def test_list_setting_spacesep_list(self, key, default):
130 def test_list_setting_spacesep_list(self, key, default):
130 test_list = ['test', 'list', 'values', 'for', key]
131 test_list = ['test', 'list', 'values', 'for', key]
131 input_value = ' '.join(test_list)
132 input_value = ' '.join(test_list)
132 settings = {key: input_value}
133 settings = {key: input_value}
133 _sanitize_vcs_settings(settings)
134 _sanitize_vcs_settings(settings)
134 assert settings[key] == test_list
135 assert settings[key] == test_list
135
136
136 @pytest.mark.parametrize('key, default', _list_settings)
137 @pytest.mark.parametrize('key, default', _list_settings)
137 def test_list_setting_newlinesep_list(self, key, default):
138 def test_list_setting_newlinesep_list(self, key, default):
138 test_list = ['test', 'list', 'values', 'for', key]
139 test_list = ['test', 'list', 'values', 'for', key]
139 input_value = '\n'.join(test_list)
140 input_value = '\n'.join(test_list)
140 settings = {key: input_value}
141 settings = {key: input_value}
141 _sanitize_vcs_settings(settings)
142 _sanitize_vcs_settings(settings)
142 assert settings[key] == test_list
143 assert settings[key] == test_list
143
144
144 @pytest.mark.parametrize('key, default', _list_settings)
145 @pytest.mark.parametrize('key, default', _list_settings)
145 def test_list_setting_commasep_list(self, key, default):
146 def test_list_setting_commasep_list(self, key, default):
146 test_list = ['test', 'list', 'values', 'for', key]
147 test_list = ['test', 'list', 'values', 'for', key]
147 input_value = ','.join(test_list)
148 input_value = ','.join(test_list)
148 settings = {key: input_value}
149 settings = {key: input_value}
149 _sanitize_vcs_settings(settings)
150 _sanitize_vcs_settings(settings)
150 assert settings[key] == test_list
151 assert settings[key] == test_list
151
152
152 @pytest.mark.parametrize('key, default', _list_settings)
153 @pytest.mark.parametrize('key, default', _list_settings)
153 def test_list_setting_comma_and_space_sep_list(self, key, default):
154 def test_list_setting_comma_and_space_sep_list(self, key, default):
154 test_list = ['test', 'list', 'values', 'for', key]
155 test_list = ['test', 'list', 'values', 'for', key]
155 input_value = ', '.join(test_list)
156 input_value = ', '.join(test_list)
156 settings = {key: input_value}
157 settings = {key: input_value}
157 _sanitize_vcs_settings(settings)
158 _sanitize_vcs_settings(settings)
158 assert settings[key] == test_list
159 assert settings[key] == test_list
159
160
160 @pytest.mark.parametrize('key, default', _string_settings)
161 @pytest.mark.parametrize('key, default', _string_settings)
161 def test_string_setting_string(self, key, default):
162 def test_string_setting_string(self, key, default):
162 test_value = 'test-string-for-{}'.format(key)
163 test_value = 'test-string-for-{}'.format(key)
163 settings = {key: test_value}
164 settings = {key: test_value}
164 _sanitize_vcs_settings(settings)
165 _sanitize_vcs_settings(settings)
165 assert settings[key] == test_value
166 assert settings[key] == test_value
166
167
167 @pytest.mark.parametrize('key, default', _string_settings)
168 @pytest.mark.parametrize('key, default', _string_settings)
168 def test_string_setting_default(self, key, default):
169 def test_string_setting_default(self, key, default):
169 settings = {}
170 settings = {}
170 _sanitize_vcs_settings(settings)
171 _sanitize_vcs_settings(settings)
171 assert settings[key] == default
172 assert settings[key] == default
172
173
173 @pytest.mark.parametrize('key, default', _string_settings)
174 @pytest.mark.parametrize('key, default', _string_settings)
174 def test_string_setting_lowercase(self, key, default):
175 def test_string_setting_lowercase(self, key, default):
175 test_value = 'Test-String-For-{}'.format(key)
176 test_value = 'Test-String-For-{}'.format(key)
176 settings = {key: test_value}
177 settings = {key: test_value}
177 _sanitize_vcs_settings(settings)
178 _sanitize_vcs_settings(settings)
178 assert settings[key] == test_value.lower()
179 assert settings[key] == test_value.lower()
179
180
180 @pytest.mark.parametrize('key, default', _bool_settings)
181 @pytest.mark.parametrize('key, default', _bool_settings)
181 def test_bool_setting_true(self, key, default):
182 def test_bool_setting_true(self, key, default):
182 settings = {key: 'true'}
183 settings = {key: 'true'}
183 _sanitize_vcs_settings(settings)
184 _sanitize_vcs_settings(settings)
184 assert settings[key] is True
185 assert settings[key] is True
185
186
186 @pytest.mark.parametrize('key, default', _bool_settings)
187 @pytest.mark.parametrize('key, default', _bool_settings)
187 def test_bool_setting_false(self, key, default):
188 def test_bool_setting_false(self, key, default):
188 settings = {key: 'false'}
189 settings = {key: 'false'}
189 _sanitize_vcs_settings(settings)
190 _sanitize_vcs_settings(settings)
190 assert settings[key] is False
191 assert settings[key] is False
191
192
192 @pytest.mark.parametrize('key, default', _bool_settings)
193 @pytest.mark.parametrize('key, default', _bool_settings)
193 def test_bool_setting_invalid_string(self, key, default):
194 def test_bool_setting_invalid_string(self, key, default):
194 settings = {key: 'no-bool-val-string'}
195 settings = {key: 'no-bool-val-string'}
195 _sanitize_vcs_settings(settings)
196 _sanitize_vcs_settings(settings)
196 assert settings[key] is False
197 assert settings[key] is False
197
198
198 @pytest.mark.parametrize('key, default', _bool_settings)
199 @pytest.mark.parametrize('key, default', _bool_settings)
199 def test_bool_setting_default(self, key, default):
200 def test_bool_setting_default(self, key, default):
200 settings = {}
201 settings = {}
201 _sanitize_vcs_settings(settings)
202 _sanitize_vcs_settings(settings)
202 assert settings[key] is default
203 assert settings[key] is default
General Comments 0
You need to be logged in to leave comments. Login now