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