##// END OF EJS Templates
oss-licenses: Remove unused pytest fixture from tests.
Martin Bornhold -
r221:1cb0de52 default
parent child Browse files
Show More
@@ -1,625 +1,624 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2016 RhodeCode GmbH
3 # Copyright (C) 2010-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 import mock
21 import mock
22 import pytest
22 import pytest
23
23
24 import rhodecode
24 import rhodecode
25 from rhodecode.config.routing import ADMIN_PREFIX
25 from rhodecode.config.routing import ADMIN_PREFIX
26 from rhodecode.lib.utils2 import md5
26 from rhodecode.lib.utils2 import md5
27 from rhodecode.model.db import RhodeCodeUi
27 from rhodecode.model.db import RhodeCodeUi
28 from rhodecode.model.meta import Session
28 from rhodecode.model.meta import Session
29 from rhodecode.model.settings import SettingsModel, IssueTrackerSettingsModel
29 from rhodecode.model.settings import SettingsModel, IssueTrackerSettingsModel
30 from rhodecode.tests import url, assert_session_flash
30 from rhodecode.tests import url, assert_session_flash
31 from rhodecode.tests.utils import AssertResponse
31 from rhodecode.tests.utils import AssertResponse
32
32
33
33
34 UPDATE_DATA_QUALNAME = (
34 UPDATE_DATA_QUALNAME = (
35 'rhodecode.controllers.admin.settings.SettingsController.get_update_data')
35 'rhodecode.controllers.admin.settings.SettingsController.get_update_data')
36
36
37
37
38 @pytest.mark.usefixtures('autologin_user', 'app')
38 @pytest.mark.usefixtures('autologin_user', 'app')
39 class TestAdminSettingsController:
39 class TestAdminSettingsController:
40
40
41 @pytest.mark.parametrize('urlname', [
41 @pytest.mark.parametrize('urlname', [
42 'admin_settings_vcs',
42 'admin_settings_vcs',
43 'admin_settings_mapping',
43 'admin_settings_mapping',
44 'admin_settings_global',
44 'admin_settings_global',
45 'admin_settings_visual',
45 'admin_settings_visual',
46 'admin_settings_email',
46 'admin_settings_email',
47 'admin_settings_hooks',
47 'admin_settings_hooks',
48 'admin_settings_search',
48 'admin_settings_search',
49 'admin_settings_system',
49 'admin_settings_system',
50 ])
50 ])
51 def test_simple_get(self, urlname, app):
51 def test_simple_get(self, urlname, app):
52 app.get(url(urlname))
52 app.get(url(urlname))
53
53
54 def test_create_custom_hook(self, csrf_token):
54 def test_create_custom_hook(self, csrf_token):
55 response = self.app.post(
55 response = self.app.post(
56 url('admin_settings_hooks'),
56 url('admin_settings_hooks'),
57 params={
57 params={
58 'new_hook_ui_key': 'test_hooks_1',
58 'new_hook_ui_key': 'test_hooks_1',
59 'new_hook_ui_value': 'cd /tmp',
59 'new_hook_ui_value': 'cd /tmp',
60 'csrf_token': csrf_token})
60 'csrf_token': csrf_token})
61
61
62 response = response.follow()
62 response = response.follow()
63 response.mustcontain('test_hooks_1')
63 response.mustcontain('test_hooks_1')
64 response.mustcontain('cd /tmp')
64 response.mustcontain('cd /tmp')
65
65
66 def test_create_custom_hook_delete(self, csrf_token):
66 def test_create_custom_hook_delete(self, csrf_token):
67 response = self.app.post(
67 response = self.app.post(
68 url('admin_settings_hooks'),
68 url('admin_settings_hooks'),
69 params={
69 params={
70 'new_hook_ui_key': 'test_hooks_2',
70 'new_hook_ui_key': 'test_hooks_2',
71 'new_hook_ui_value': 'cd /tmp2',
71 'new_hook_ui_value': 'cd /tmp2',
72 'csrf_token': csrf_token})
72 'csrf_token': csrf_token})
73
73
74 response = response.follow()
74 response = response.follow()
75 response.mustcontain('test_hooks_2')
75 response.mustcontain('test_hooks_2')
76 response.mustcontain('cd /tmp2')
76 response.mustcontain('cd /tmp2')
77
77
78 hook_id = SettingsModel().get_ui_by_key('test_hooks_2').ui_id
78 hook_id = SettingsModel().get_ui_by_key('test_hooks_2').ui_id
79
79
80 # delete
80 # delete
81 self.app.post(
81 self.app.post(
82 url('admin_settings_hooks'),
82 url('admin_settings_hooks'),
83 params={'hook_id': hook_id, 'csrf_token': csrf_token})
83 params={'hook_id': hook_id, 'csrf_token': csrf_token})
84 response = self.app.get(url('admin_settings_hooks'))
84 response = self.app.get(url('admin_settings_hooks'))
85 response.mustcontain(no=['test_hooks_2'])
85 response.mustcontain(no=['test_hooks_2'])
86 response.mustcontain(no=['cd /tmp2'])
86 response.mustcontain(no=['cd /tmp2'])
87
87
88 def test_system_update_new_version(self):
88 def test_system_update_new_version(self):
89 update_data = {
89 update_data = {
90 'versions': [
90 'versions': [
91 {
91 {
92 'version': '100.3.1415926535',
92 'version': '100.3.1415926535',
93 'general': 'The latest version we are ever going to ship'
93 'general': 'The latest version we are ever going to ship'
94 },
94 },
95 {
95 {
96 'version': '0.0.0',
96 'version': '0.0.0',
97 'general': 'The first version we ever shipped'
97 'general': 'The first version we ever shipped'
98 }
98 }
99 ]
99 ]
100 }
100 }
101 with mock.patch(UPDATE_DATA_QUALNAME, return_value=update_data):
101 with mock.patch(UPDATE_DATA_QUALNAME, return_value=update_data):
102 response = self.app.get(url('admin_settings_system_update'))
102 response = self.app.get(url('admin_settings_system_update'))
103 response.mustcontain('A <b>new version</b> is available')
103 response.mustcontain('A <b>new version</b> is available')
104
104
105 def test_system_update_nothing_new(self):
105 def test_system_update_nothing_new(self):
106 update_data = {
106 update_data = {
107 'versions': [
107 'versions': [
108 {
108 {
109 'version': '0.0.0',
109 'version': '0.0.0',
110 'general': 'The first version we ever shipped'
110 'general': 'The first version we ever shipped'
111 }
111 }
112 ]
112 ]
113 }
113 }
114 with mock.patch(UPDATE_DATA_QUALNAME, return_value=update_data):
114 with mock.patch(UPDATE_DATA_QUALNAME, return_value=update_data):
115 response = self.app.get(url('admin_settings_system_update'))
115 response = self.app.get(url('admin_settings_system_update'))
116 response.mustcontain(
116 response.mustcontain(
117 'You already have the <b>latest</b> stable version.')
117 'You already have the <b>latest</b> stable version.')
118
118
119 def test_system_update_bad_response(self):
119 def test_system_update_bad_response(self):
120 with mock.patch(UPDATE_DATA_QUALNAME, side_effect=ValueError('foo')):
120 with mock.patch(UPDATE_DATA_QUALNAME, side_effect=ValueError('foo')):
121 response = self.app.get(url('admin_settings_system_update'))
121 response = self.app.get(url('admin_settings_system_update'))
122 response.mustcontain(
122 response.mustcontain(
123 'Bad data sent from update server')
123 'Bad data sent from update server')
124
124
125
125
126 @pytest.mark.usefixtures('autologin_user', 'app')
126 @pytest.mark.usefixtures('autologin_user', 'app')
127 class TestAdminSettingsGlobal:
127 class TestAdminSettingsGlobal:
128
128
129 def test_pre_post_code_code_active(self, csrf_token):
129 def test_pre_post_code_code_active(self, csrf_token):
130 pre_code = 'rc-pre-code-187652122'
130 pre_code = 'rc-pre-code-187652122'
131 post_code = 'rc-postcode-98165231'
131 post_code = 'rc-postcode-98165231'
132
132
133 response = self.post_and_verify_settings({
133 response = self.post_and_verify_settings({
134 'rhodecode_pre_code': pre_code,
134 'rhodecode_pre_code': pre_code,
135 'rhodecode_post_code': post_code,
135 'rhodecode_post_code': post_code,
136 'csrf_token': csrf_token,
136 'csrf_token': csrf_token,
137 })
137 })
138
138
139 response = response.follow()
139 response = response.follow()
140 response.mustcontain(pre_code, post_code)
140 response.mustcontain(pre_code, post_code)
141
141
142 def test_pre_post_code_code_inactive(self, csrf_token):
142 def test_pre_post_code_code_inactive(self, csrf_token):
143 pre_code = 'rc-pre-code-187652122'
143 pre_code = 'rc-pre-code-187652122'
144 post_code = 'rc-postcode-98165231'
144 post_code = 'rc-postcode-98165231'
145 response = self.post_and_verify_settings({
145 response = self.post_and_verify_settings({
146 'rhodecode_pre_code': '',
146 'rhodecode_pre_code': '',
147 'rhodecode_post_code': '',
147 'rhodecode_post_code': '',
148 'csrf_token': csrf_token,
148 'csrf_token': csrf_token,
149 })
149 })
150
150
151 response = response.follow()
151 response = response.follow()
152 response.mustcontain(no=[pre_code, post_code])
152 response.mustcontain(no=[pre_code, post_code])
153
153
154 def test_captcha_activate(self, csrf_token):
154 def test_captcha_activate(self, csrf_token):
155 self.post_and_verify_settings({
155 self.post_and_verify_settings({
156 'rhodecode_captcha_private_key': '1234567890',
156 'rhodecode_captcha_private_key': '1234567890',
157 'rhodecode_captcha_public_key': '1234567890',
157 'rhodecode_captcha_public_key': '1234567890',
158 'csrf_token': csrf_token,
158 'csrf_token': csrf_token,
159 })
159 })
160
160
161 response = self.app.get(ADMIN_PREFIX + '/register')
161 response = self.app.get(ADMIN_PREFIX + '/register')
162 response.mustcontain('captcha')
162 response.mustcontain('captcha')
163
163
164 def test_captcha_deactivate(self, csrf_token):
164 def test_captcha_deactivate(self, csrf_token):
165 self.post_and_verify_settings({
165 self.post_and_verify_settings({
166 'rhodecode_captcha_private_key': '',
166 'rhodecode_captcha_private_key': '',
167 'rhodecode_captcha_public_key': '1234567890',
167 'rhodecode_captcha_public_key': '1234567890',
168 'csrf_token': csrf_token,
168 'csrf_token': csrf_token,
169 })
169 })
170
170
171 response = self.app.get(ADMIN_PREFIX + '/register')
171 response = self.app.get(ADMIN_PREFIX + '/register')
172 response.mustcontain(no=['captcha'])
172 response.mustcontain(no=['captcha'])
173
173
174 def test_title_change(self, csrf_token):
174 def test_title_change(self, csrf_token):
175 old_title = 'RhodeCode'
175 old_title = 'RhodeCode'
176 new_title = old_title + '_changed'
176 new_title = old_title + '_changed'
177
177
178 for new_title in ['Changed', 'Ε»Γ³Ε‚wik', old_title]:
178 for new_title in ['Changed', 'Ε»Γ³Ε‚wik', old_title]:
179 response = self.post_and_verify_settings({
179 response = self.post_and_verify_settings({
180 'rhodecode_title': new_title,
180 'rhodecode_title': new_title,
181 'csrf_token': csrf_token,
181 'csrf_token': csrf_token,
182 })
182 })
183
183
184 response = response.follow()
184 response = response.follow()
185 response.mustcontain(
185 response.mustcontain(
186 """<div class="branding">- %s</div>""" % new_title)
186 """<div class="branding">- %s</div>""" % new_title)
187
187
188 def post_and_verify_settings(self, settings):
188 def post_and_verify_settings(self, settings):
189 old_title = 'RhodeCode'
189 old_title = 'RhodeCode'
190 old_realm = 'RhodeCode authentication'
190 old_realm = 'RhodeCode authentication'
191 params = {
191 params = {
192 'rhodecode_title': old_title,
192 'rhodecode_title': old_title,
193 'rhodecode_realm': old_realm,
193 'rhodecode_realm': old_realm,
194 'rhodecode_pre_code': '',
194 'rhodecode_pre_code': '',
195 'rhodecode_post_code': '',
195 'rhodecode_post_code': '',
196 'rhodecode_captcha_private_key': '',
196 'rhodecode_captcha_private_key': '',
197 'rhodecode_captcha_public_key': '',
197 'rhodecode_captcha_public_key': '',
198 }
198 }
199 params.update(settings)
199 params.update(settings)
200 response = self.app.post(url('admin_settings_global'), params=params)
200 response = self.app.post(url('admin_settings_global'), params=params)
201
201
202 assert_session_flash(response, 'Updated application settings')
202 assert_session_flash(response, 'Updated application settings')
203 app_settings = SettingsModel().get_all_settings()
203 app_settings = SettingsModel().get_all_settings()
204 del settings['csrf_token']
204 del settings['csrf_token']
205 for key, value in settings.iteritems():
205 for key, value in settings.iteritems():
206 assert app_settings[key] == value.decode('utf-8')
206 assert app_settings[key] == value.decode('utf-8')
207
207
208 return response
208 return response
209
209
210
210
211 @pytest.mark.usefixtures('autologin_user', 'app')
211 @pytest.mark.usefixtures('autologin_user', 'app')
212 class TestAdminSettingsVcs:
212 class TestAdminSettingsVcs:
213
213
214 def test_contains_svn_default_patterns(self, app):
214 def test_contains_svn_default_patterns(self, app):
215 response = app.get(url('admin_settings_vcs'))
215 response = app.get(url('admin_settings_vcs'))
216 expected_patterns = [
216 expected_patterns = [
217 '/trunk',
217 '/trunk',
218 '/branches/*',
218 '/branches/*',
219 '/tags/*',
219 '/tags/*',
220 ]
220 ]
221 for pattern in expected_patterns:
221 for pattern in expected_patterns:
222 response.mustcontain(pattern)
222 response.mustcontain(pattern)
223
223
224 def test_add_new_svn_branch_and_tag_pattern(
224 def test_add_new_svn_branch_and_tag_pattern(
225 self, app, backend_svn, form_defaults, disable_sql_cache,
225 self, app, backend_svn, form_defaults, disable_sql_cache,
226 csrf_token):
226 csrf_token):
227 form_defaults.update({
227 form_defaults.update({
228 'new_svn_branch': '/exp/branches/*',
228 'new_svn_branch': '/exp/branches/*',
229 'new_svn_tag': '/important_tags/*',
229 'new_svn_tag': '/important_tags/*',
230 'csrf_token': csrf_token,
230 'csrf_token': csrf_token,
231 })
231 })
232
232
233 response = app.post(
233 response = app.post(
234 url('admin_settings_vcs'), params=form_defaults, status=302)
234 url('admin_settings_vcs'), params=form_defaults, status=302)
235 response = response.follow()
235 response = response.follow()
236
236
237 # Expect to find the new values on the page
237 # Expect to find the new values on the page
238 response.mustcontain('/exp/branches/*')
238 response.mustcontain('/exp/branches/*')
239 response.mustcontain('/important_tags/*')
239 response.mustcontain('/important_tags/*')
240
240
241 # Expect that those patterns are used to match branches and tags now
241 # Expect that those patterns are used to match branches and tags now
242 repo = backend_svn['svn-simple-layout'].scm_instance()
242 repo = backend_svn['svn-simple-layout'].scm_instance()
243 assert 'exp/branches/exp-sphinx-docs' in repo.branches
243 assert 'exp/branches/exp-sphinx-docs' in repo.branches
244 assert 'important_tags/v0.5' in repo.tags
244 assert 'important_tags/v0.5' in repo.tags
245
245
246 def test_add_same_svn_value_twice_shows_an_error_message(
246 def test_add_same_svn_value_twice_shows_an_error_message(
247 self, app, form_defaults, csrf_token, settings_util):
247 self, app, form_defaults, csrf_token, settings_util):
248 settings_util.create_rhodecode_ui('vcs_svn_branch', '/test')
248 settings_util.create_rhodecode_ui('vcs_svn_branch', '/test')
249 settings_util.create_rhodecode_ui('vcs_svn_tag', '/test')
249 settings_util.create_rhodecode_ui('vcs_svn_tag', '/test')
250
250
251 response = app.post(
251 response = app.post(
252 url('admin_settings_vcs'),
252 url('admin_settings_vcs'),
253 params={
253 params={
254 'paths_root_path': form_defaults['paths_root_path'],
254 'paths_root_path': form_defaults['paths_root_path'],
255 'new_svn_branch': '/test',
255 'new_svn_branch': '/test',
256 'new_svn_tag': '/test',
256 'new_svn_tag': '/test',
257 'csrf_token': csrf_token,
257 'csrf_token': csrf_token,
258 },
258 },
259 status=200)
259 status=200)
260
260
261 response.mustcontain("Pattern already exists")
261 response.mustcontain("Pattern already exists")
262 response.mustcontain("Some form inputs contain invalid data.")
262 response.mustcontain("Some form inputs contain invalid data.")
263
263
264 @pytest.mark.parametrize('section', [
264 @pytest.mark.parametrize('section', [
265 'vcs_svn_branch',
265 'vcs_svn_branch',
266 'vcs_svn_tag',
266 'vcs_svn_tag',
267 ])
267 ])
268 def test_delete_svn_patterns(
268 def test_delete_svn_patterns(
269 self, section, app, csrf_token, settings_util):
269 self, section, app, csrf_token, settings_util):
270 setting = settings_util.create_rhodecode_ui(
270 setting = settings_util.create_rhodecode_ui(
271 section, '/test_delete', cleanup=False)
271 section, '/test_delete', cleanup=False)
272
272
273 app.post(
273 app.post(
274 url('admin_settings_vcs'),
274 url('admin_settings_vcs'),
275 params={
275 params={
276 '_method': 'delete',
276 '_method': 'delete',
277 'delete_svn_pattern': setting.ui_id,
277 'delete_svn_pattern': setting.ui_id,
278 'csrf_token': csrf_token},
278 'csrf_token': csrf_token},
279 headers={'X-REQUESTED-WITH': 'XMLHttpRequest'})
279 headers={'X-REQUESTED-WITH': 'XMLHttpRequest'})
280
280
281 @pytest.mark.parametrize('section', [
281 @pytest.mark.parametrize('section', [
282 'vcs_svn_branch',
282 'vcs_svn_branch',
283 'vcs_svn_tag',
283 'vcs_svn_tag',
284 ])
284 ])
285 def test_delete_svn_patterns_raises_400_when_no_xhr(
285 def test_delete_svn_patterns_raises_400_when_no_xhr(
286 self, section, app, csrf_token, settings_util):
286 self, section, app, csrf_token, settings_util):
287 setting = settings_util.create_rhodecode_ui(section, '/test_delete')
287 setting = settings_util.create_rhodecode_ui(section, '/test_delete')
288
288
289 app.post(
289 app.post(
290 url('admin_settings_vcs'),
290 url('admin_settings_vcs'),
291 params={
291 params={
292 '_method': 'delete',
292 '_method': 'delete',
293 'delete_svn_pattern': setting.ui_id,
293 'delete_svn_pattern': setting.ui_id,
294 'csrf_token': csrf_token},
294 'csrf_token': csrf_token},
295 status=400)
295 status=400)
296
296
297 def test_extensions_hgsubversion(self, app, form_defaults, csrf_token):
297 def test_extensions_hgsubversion(self, app, form_defaults, csrf_token):
298 form_defaults.update({
298 form_defaults.update({
299 'csrf_token': csrf_token,
299 'csrf_token': csrf_token,
300 'extensions_hgsubversion': 'True',
300 'extensions_hgsubversion': 'True',
301 })
301 })
302 response = app.post(
302 response = app.post(
303 url('admin_settings_vcs'),
303 url('admin_settings_vcs'),
304 params=form_defaults,
304 params=form_defaults,
305 status=302)
305 status=302)
306
306
307 response = response.follow()
307 response = response.follow()
308 extensions_input = (
308 extensions_input = (
309 '<input id="extensions_hgsubversion" '
309 '<input id="extensions_hgsubversion" '
310 'name="extensions_hgsubversion" type="checkbox" '
310 'name="extensions_hgsubversion" type="checkbox" '
311 'value="True" checked="checked" />')
311 'value="True" checked="checked" />')
312 response.mustcontain(extensions_input)
312 response.mustcontain(extensions_input)
313
313
314 def test_has_a_section_for_pull_request_settings(self, app):
314 def test_has_a_section_for_pull_request_settings(self, app):
315 response = app.get(url('admin_settings_vcs'))
315 response = app.get(url('admin_settings_vcs'))
316 response.mustcontain('Pull Request Settings')
316 response.mustcontain('Pull Request Settings')
317
317
318 def test_has_an_input_for_invalidation_of_inline_comments(
318 def test_has_an_input_for_invalidation_of_inline_comments(
319 self, app):
319 self, app):
320 response = app.get(url('admin_settings_vcs'))
320 response = app.get(url('admin_settings_vcs'))
321 assert_response = AssertResponse(response)
321 assert_response = AssertResponse(response)
322 assert_response.one_element_exists(
322 assert_response.one_element_exists(
323 '[name=rhodecode_use_outdated_comments]')
323 '[name=rhodecode_use_outdated_comments]')
324
324
325 @pytest.mark.parametrize('new_value', [True, False])
325 @pytest.mark.parametrize('new_value', [True, False])
326 def test_allows_to_change_invalidation_of_inline_comments(
326 def test_allows_to_change_invalidation_of_inline_comments(
327 self, app, form_defaults, csrf_token, new_value):
327 self, app, form_defaults, csrf_token, new_value):
328 setting_key = 'use_outdated_comments'
328 setting_key = 'use_outdated_comments'
329 setting = SettingsModel().create_or_update_setting(
329 setting = SettingsModel().create_or_update_setting(
330 setting_key, not new_value, 'bool')
330 setting_key, not new_value, 'bool')
331 Session().add(setting)
331 Session().add(setting)
332 Session().commit()
332 Session().commit()
333
333
334 form_defaults.update({
334 form_defaults.update({
335 'csrf_token': csrf_token,
335 'csrf_token': csrf_token,
336 'rhodecode_use_outdated_comments': str(new_value),
336 'rhodecode_use_outdated_comments': str(new_value),
337 })
337 })
338 response = app.post(
338 response = app.post(
339 url('admin_settings_vcs'),
339 url('admin_settings_vcs'),
340 params=form_defaults,
340 params=form_defaults,
341 status=302)
341 status=302)
342 response = response.follow()
342 response = response.follow()
343 setting = SettingsModel().get_setting_by_name(setting_key)
343 setting = SettingsModel().get_setting_by_name(setting_key)
344 assert setting.app_settings_value is new_value
344 assert setting.app_settings_value is new_value
345
345
346 @pytest.fixture
346 @pytest.fixture
347 def disable_sql_cache(self, request):
347 def disable_sql_cache(self, request):
348 patcher = mock.patch(
348 patcher = mock.patch(
349 'rhodecode.lib.caching_query.FromCache.process_query')
349 'rhodecode.lib.caching_query.FromCache.process_query')
350 request.addfinalizer(patcher.stop)
350 request.addfinalizer(patcher.stop)
351 patcher.start()
351 patcher.start()
352
352
353 @pytest.fixture
353 @pytest.fixture
354 def form_defaults(self):
354 def form_defaults(self):
355 from rhodecode.controllers.admin.settings import SettingsController
355 from rhodecode.controllers.admin.settings import SettingsController
356 controller = SettingsController()
356 controller = SettingsController()
357 return controller._form_defaults()
357 return controller._form_defaults()
358
358
359 # TODO: johbo: What we really want is to checkpoint before a test run and
359 # TODO: johbo: What we really want is to checkpoint before a test run and
360 # reset the session afterwards.
360 # reset the session afterwards.
361 @pytest.fixture(scope='class', autouse=True)
361 @pytest.fixture(scope='class', autouse=True)
362 def cleanup_settings(self, request, pylonsapp):
362 def cleanup_settings(self, request, pylonsapp):
363 ui_id = RhodeCodeUi.ui_id
363 ui_id = RhodeCodeUi.ui_id
364 original_ids = list(
364 original_ids = list(
365 r.ui_id for r in RhodeCodeUi.query().values(ui_id))
365 r.ui_id for r in RhodeCodeUi.query().values(ui_id))
366
366
367 @request.addfinalizer
367 @request.addfinalizer
368 def cleanup():
368 def cleanup():
369 RhodeCodeUi.query().filter(
369 RhodeCodeUi.query().filter(
370 ui_id.notin_(original_ids)).delete(False)
370 ui_id.notin_(original_ids)).delete(False)
371
371
372
372
373 @pytest.mark.usefixtures('autologin_user', 'app')
373 @pytest.mark.usefixtures('autologin_user', 'app')
374 class TestLabsSettings(object):
374 class TestLabsSettings(object):
375 def test_get_settings_page_disabled(self):
375 def test_get_settings_page_disabled(self):
376 with mock.patch.dict(rhodecode.CONFIG,
376 with mock.patch.dict(rhodecode.CONFIG,
377 {'labs_settings_active': 'false'}):
377 {'labs_settings_active': 'false'}):
378 response = self.app.get(url('admin_settings_labs'), status=302)
378 response = self.app.get(url('admin_settings_labs'), status=302)
379
379
380 assert response.location.endswith(url('admin_settings'))
380 assert response.location.endswith(url('admin_settings'))
381
381
382 def test_get_settings_page_enabled(self):
382 def test_get_settings_page_enabled(self):
383 from rhodecode.controllers.admin import settings
383 from rhodecode.controllers.admin import settings
384 lab_settings = [
384 lab_settings = [
385 settings.LabSetting(
385 settings.LabSetting(
386 key='rhodecode_bool',
386 key='rhodecode_bool',
387 type='bool',
387 type='bool',
388 group='bool group',
388 group='bool group',
389 label='bool label',
389 label='bool label',
390 help='bool help'
390 help='bool help'
391 ),
391 ),
392 settings.LabSetting(
392 settings.LabSetting(
393 key='rhodecode_text',
393 key='rhodecode_text',
394 type='unicode',
394 type='unicode',
395 group='text group',
395 group='text group',
396 label='text label',
396 label='text label',
397 help='text help'
397 help='text help'
398 ),
398 ),
399 ]
399 ]
400 with mock.patch.dict(rhodecode.CONFIG,
400 with mock.patch.dict(rhodecode.CONFIG,
401 {'labs_settings_active': 'true'}):
401 {'labs_settings_active': 'true'}):
402 with mock.patch.object(settings, '_LAB_SETTINGS', lab_settings):
402 with mock.patch.object(settings, '_LAB_SETTINGS', lab_settings):
403 response = self.app.get(url('admin_settings_labs'))
403 response = self.app.get(url('admin_settings_labs'))
404
404
405 assert '<label>bool group:</label>' in response
405 assert '<label>bool group:</label>' in response
406 assert '<label for="rhodecode_bool">bool label</label>' in response
406 assert '<label for="rhodecode_bool">bool label</label>' in response
407 assert '<p class="help-block">bool help</p>' in response
407 assert '<p class="help-block">bool help</p>' in response
408 assert 'name="rhodecode_bool" type="checkbox"' in response
408 assert 'name="rhodecode_bool" type="checkbox"' in response
409
409
410 assert '<label>text group:</label>' in response
410 assert '<label>text group:</label>' in response
411 assert '<label for="rhodecode_text">text label</label>' in response
411 assert '<label for="rhodecode_text">text label</label>' in response
412 assert '<p class="help-block">text help</p>' in response
412 assert '<p class="help-block">text help</p>' in response
413 assert 'name="rhodecode_text" size="60" type="text"' in response
413 assert 'name="rhodecode_text" size="60" type="text"' in response
414
414
415 @pytest.mark.parametrize('setting_name', [
415 @pytest.mark.parametrize('setting_name', [
416 'proxy_subversion_http_requests',
416 'proxy_subversion_http_requests',
417 'hg_use_rebase_for_merging',
417 'hg_use_rebase_for_merging',
418 ])
418 ])
419 def test_update_boolean_settings(self, csrf_token, setting_name):
419 def test_update_boolean_settings(self, csrf_token, setting_name):
420 self.app.post(
420 self.app.post(
421 url('admin_settings_labs'),
421 url('admin_settings_labs'),
422 params={
422 params={
423 'rhodecode_{}'.format(setting_name): 'true',
423 'rhodecode_{}'.format(setting_name): 'true',
424 'csrf_token': csrf_token,
424 'csrf_token': csrf_token,
425 })
425 })
426 setting = SettingsModel().get_setting_by_name(setting_name)
426 setting = SettingsModel().get_setting_by_name(setting_name)
427 assert setting.app_settings_value
427 assert setting.app_settings_value
428
428
429 self.app.post(
429 self.app.post(
430 url('admin_settings_labs'),
430 url('admin_settings_labs'),
431 params={
431 params={
432 'rhodecode_{}'.format(setting_name): 'false',
432 'rhodecode_{}'.format(setting_name): 'false',
433 'csrf_token': csrf_token,
433 'csrf_token': csrf_token,
434 })
434 })
435 setting = SettingsModel().get_setting_by_name(setting_name)
435 setting = SettingsModel().get_setting_by_name(setting_name)
436 assert not setting.app_settings_value
436 assert not setting.app_settings_value
437
437
438 @pytest.mark.parametrize('setting_name', [
438 @pytest.mark.parametrize('setting_name', [
439 'subversion_http_server_url',
439 'subversion_http_server_url',
440 ])
440 ])
441 def test_update_string_settings(self, csrf_token, setting_name):
441 def test_update_string_settings(self, csrf_token, setting_name):
442 self.app.post(
442 self.app.post(
443 url('admin_settings_labs'),
443 url('admin_settings_labs'),
444 params={
444 params={
445 'rhodecode_{}'.format(setting_name): 'Test 1',
445 'rhodecode_{}'.format(setting_name): 'Test 1',
446 'csrf_token': csrf_token,
446 'csrf_token': csrf_token,
447 })
447 })
448 setting = SettingsModel().get_setting_by_name(setting_name)
448 setting = SettingsModel().get_setting_by_name(setting_name)
449 assert setting.app_settings_value == 'Test 1'
449 assert setting.app_settings_value == 'Test 1'
450
450
451 self.app.post(
451 self.app.post(
452 url('admin_settings_labs'),
452 url('admin_settings_labs'),
453 params={
453 params={
454 'rhodecode_{}'.format(setting_name): ' Test 2 ',
454 'rhodecode_{}'.format(setting_name): ' Test 2 ',
455 'csrf_token': csrf_token,
455 'csrf_token': csrf_token,
456 })
456 })
457 setting = SettingsModel().get_setting_by_name(setting_name)
457 setting = SettingsModel().get_setting_by_name(setting_name)
458 assert setting.app_settings_value == 'Test 2'
458 assert setting.app_settings_value == 'Test 2'
459
459
460
460
461 @pytest.mark.usefixtures('app')
461 @pytest.mark.usefixtures('app')
462 class TestOpenSourceLicenses(object):
462 class TestOpenSourceLicenses(object):
463
463
464 def _get_url(self, request):
464 def _get_url(self):
465 return ADMIN_PREFIX + '/settings/open_source'
465 return ADMIN_PREFIX + '/settings/open_source'
466
466
467 def test_records_are_displayed(self, autologin_user, request_stub):
467 def test_records_are_displayed(self, autologin_user):
468 sample_licenses = {
468 sample_licenses = {
469 "python2.7-pytest-2.7.1": {
469 "python2.7-pytest-2.7.1": {
470 "UNKNOWN": None
470 "UNKNOWN": None
471 },
471 },
472 "python2.7-Markdown-2.6.2": {
472 "python2.7-Markdown-2.6.2": {
473 "BSD-3-Clause": "http://spdx.org/licenses/BSD-3-Clause"
473 "BSD-3-Clause": "http://spdx.org/licenses/BSD-3-Clause"
474 }
474 }
475 }
475 }
476 read_licenses_patch = mock.patch(
476 read_licenses_patch = mock.patch(
477 'rhodecode.admin.views.read_opensource_licenses',
477 'rhodecode.admin.views.read_opensource_licenses',
478 return_value=sample_licenses)
478 return_value=sample_licenses)
479 with read_licenses_patch:
479 with read_licenses_patch:
480 response = self.app.get(self._get_url(request_stub), status=200)
480 response = self.app.get(self._get_url(), status=200)
481
481
482 assert_response = AssertResponse(response)
482 assert_response = AssertResponse(response)
483 assert_response.element_contains(
483 assert_response.element_contains(
484 '.panel-heading', 'Licenses of Third Party Packages')
484 '.panel-heading', 'Licenses of Third Party Packages')
485 for name in sample_licenses:
485 for name in sample_licenses:
486 response.mustcontain(name)
486 response.mustcontain(name)
487 for license in sample_licenses[name]:
487 for license in sample_licenses[name]:
488 assert_response.element_contains('.panel-body', license)
488 assert_response.element_contains('.panel-body', license)
489
489
490 def test_records_can_be_read(self, autologin_user, request_stub):
490 def test_records_can_be_read(self, autologin_user):
491 response = self.app.get(self._get_url(request_stub), status=200)
491 response = self.app.get(self._get_url(), status=200)
492 assert_response = AssertResponse(response)
492 assert_response = AssertResponse(response)
493 assert_response.element_contains(
493 assert_response.element_contains(
494 '.panel-heading', 'Licenses of Third Party Packages')
494 '.panel-heading', 'Licenses of Third Party Packages')
495
495
496 def test_forbidden_when_normal_user(self, autologin_regular_user,
496 def test_forbidden_when_normal_user(self, autologin_regular_user):
497 request_stub):
497 self.app.get(self._get_url(), status=403)
498 self.app.get(self._get_url(request_stub), status=403)
499
498
500
499
501 @pytest.mark.usefixtures("app")
500 @pytest.mark.usefixtures("app")
502 class TestAdminSettingsIssueTracker:
501 class TestAdminSettingsIssueTracker:
503 RC_PREFIX = 'rhodecode_'
502 RC_PREFIX = 'rhodecode_'
504 SHORT_PATTERN_KEY = 'issuetracker_pat_'
503 SHORT_PATTERN_KEY = 'issuetracker_pat_'
505 PATTERN_KEY = RC_PREFIX + SHORT_PATTERN_KEY
504 PATTERN_KEY = RC_PREFIX + SHORT_PATTERN_KEY
506
505
507 def test_issuetracker_index(self, autologin_user):
506 def test_issuetracker_index(self, autologin_user):
508 response = self.app.get(url('admin_settings_issuetracker'))
507 response = self.app.get(url('admin_settings_issuetracker'))
509 assert response.status_code == 200
508 assert response.status_code == 200
510
509
511 def test_add_issuetracker_pattern(
510 def test_add_issuetracker_pattern(
512 self, request, autologin_user, csrf_token):
511 self, request, autologin_user, csrf_token):
513 pattern = 'issuetracker_pat'
512 pattern = 'issuetracker_pat'
514 another_pattern = pattern+'1'
513 another_pattern = pattern+'1'
515 post_url = url('admin_settings_issuetracker_save')
514 post_url = url('admin_settings_issuetracker_save')
516 post_data = {
515 post_data = {
517 'new_pattern_pattern_0': pattern,
516 'new_pattern_pattern_0': pattern,
518 'new_pattern_url_0': 'url',
517 'new_pattern_url_0': 'url',
519 'new_pattern_prefix_0': 'prefix',
518 'new_pattern_prefix_0': 'prefix',
520 'new_pattern_description_0': 'description',
519 'new_pattern_description_0': 'description',
521 'new_pattern_pattern_1': another_pattern,
520 'new_pattern_pattern_1': another_pattern,
522 'new_pattern_url_1': 'url1',
521 'new_pattern_url_1': 'url1',
523 'new_pattern_prefix_1': 'prefix1',
522 'new_pattern_prefix_1': 'prefix1',
524 'new_pattern_description_1': 'description1',
523 'new_pattern_description_1': 'description1',
525 'csrf_token': csrf_token
524 'csrf_token': csrf_token
526 }
525 }
527 self.app.post(post_url, post_data, status=302)
526 self.app.post(post_url, post_data, status=302)
528 settings = SettingsModel().get_all_settings()
527 settings = SettingsModel().get_all_settings()
529 self.uid = md5(pattern)
528 self.uid = md5(pattern)
530 assert settings[self.PATTERN_KEY+self.uid] == pattern
529 assert settings[self.PATTERN_KEY+self.uid] == pattern
531 self.another_uid = md5(another_pattern)
530 self.another_uid = md5(another_pattern)
532 assert settings[self.PATTERN_KEY+self.another_uid] == another_pattern
531 assert settings[self.PATTERN_KEY+self.another_uid] == another_pattern
533
532
534 @request.addfinalizer
533 @request.addfinalizer
535 def cleanup():
534 def cleanup():
536 defaults = SettingsModel().get_all_settings()
535 defaults = SettingsModel().get_all_settings()
537
536
538 entries = [name for name in defaults if (
537 entries = [name for name in defaults if (
539 (self.uid in name) or (self.another_uid) in name)]
538 (self.uid in name) or (self.another_uid) in name)]
540 start = len(self.RC_PREFIX)
539 start = len(self.RC_PREFIX)
541 for del_key in entries:
540 for del_key in entries:
542 # TODO: anderson: get_by_name needs name without prefix
541 # TODO: anderson: get_by_name needs name without prefix
543 entry = SettingsModel().get_setting_by_name(del_key[start:])
542 entry = SettingsModel().get_setting_by_name(del_key[start:])
544 Session().delete(entry)
543 Session().delete(entry)
545
544
546 Session().commit()
545 Session().commit()
547
546
548 def test_edit_issuetracker_pattern(
547 def test_edit_issuetracker_pattern(
549 self, autologin_user, backend, csrf_token, request):
548 self, autologin_user, backend, csrf_token, request):
550 old_pattern = 'issuetracker_pat'
549 old_pattern = 'issuetracker_pat'
551 old_uid = md5(old_pattern)
550 old_uid = md5(old_pattern)
552 pattern = 'issuetracker_pat_new'
551 pattern = 'issuetracker_pat_new'
553 self.new_uid = md5(pattern)
552 self.new_uid = md5(pattern)
554
553
555 SettingsModel().create_or_update_setting(
554 SettingsModel().create_or_update_setting(
556 self.SHORT_PATTERN_KEY+old_uid, old_pattern, 'unicode')
555 self.SHORT_PATTERN_KEY+old_uid, old_pattern, 'unicode')
557
556
558 post_url = url('admin_settings_issuetracker_save')
557 post_url = url('admin_settings_issuetracker_save')
559 post_data = {
558 post_data = {
560 'new_pattern_pattern_0': pattern,
559 'new_pattern_pattern_0': pattern,
561 'new_pattern_url_0': 'url',
560 'new_pattern_url_0': 'url',
562 'new_pattern_prefix_0': 'prefix',
561 'new_pattern_prefix_0': 'prefix',
563 'new_pattern_description_0': 'description',
562 'new_pattern_description_0': 'description',
564 'uid': old_uid,
563 'uid': old_uid,
565 'csrf_token': csrf_token
564 'csrf_token': csrf_token
566 }
565 }
567 self.app.post(post_url, post_data, status=302)
566 self.app.post(post_url, post_data, status=302)
568 settings = SettingsModel().get_all_settings()
567 settings = SettingsModel().get_all_settings()
569 assert settings[self.PATTERN_KEY+self.new_uid] == pattern
568 assert settings[self.PATTERN_KEY+self.new_uid] == pattern
570 assert self.PATTERN_KEY+old_uid not in settings
569 assert self.PATTERN_KEY+old_uid not in settings
571
570
572 @request.addfinalizer
571 @request.addfinalizer
573 def cleanup():
572 def cleanup():
574 IssueTrackerSettingsModel().delete_entries(self.new_uid)
573 IssueTrackerSettingsModel().delete_entries(self.new_uid)
575
574
576 def test_replace_issuetracker_pattern_description(
575 def test_replace_issuetracker_pattern_description(
577 self, autologin_user, csrf_token, request, settings_util):
576 self, autologin_user, csrf_token, request, settings_util):
578 prefix = 'issuetracker'
577 prefix = 'issuetracker'
579 pattern = 'issuetracker_pat'
578 pattern = 'issuetracker_pat'
580 self.uid = md5(pattern)
579 self.uid = md5(pattern)
581 pattern_key = '_'.join([prefix, 'pat', self.uid])
580 pattern_key = '_'.join([prefix, 'pat', self.uid])
582 rc_pattern_key = '_'.join(['rhodecode', pattern_key])
581 rc_pattern_key = '_'.join(['rhodecode', pattern_key])
583 desc_key = '_'.join([prefix, 'desc', self.uid])
582 desc_key = '_'.join([prefix, 'desc', self.uid])
584 rc_desc_key = '_'.join(['rhodecode', desc_key])
583 rc_desc_key = '_'.join(['rhodecode', desc_key])
585 new_description = 'new_description'
584 new_description = 'new_description'
586
585
587 settings_util.create_rhodecode_setting(
586 settings_util.create_rhodecode_setting(
588 pattern_key, pattern, 'unicode', cleanup=False)
587 pattern_key, pattern, 'unicode', cleanup=False)
589 settings_util.create_rhodecode_setting(
588 settings_util.create_rhodecode_setting(
590 desc_key, 'old description', 'unicode', cleanup=False)
589 desc_key, 'old description', 'unicode', cleanup=False)
591
590
592 post_url = url('admin_settings_issuetracker_save')
591 post_url = url('admin_settings_issuetracker_save')
593 post_data = {
592 post_data = {
594 'new_pattern_pattern_0': pattern,
593 'new_pattern_pattern_0': pattern,
595 'new_pattern_url_0': 'url',
594 'new_pattern_url_0': 'url',
596 'new_pattern_prefix_0': 'prefix',
595 'new_pattern_prefix_0': 'prefix',
597 'new_pattern_description_0': new_description,
596 'new_pattern_description_0': new_description,
598 'uid': self.uid,
597 'uid': self.uid,
599 'csrf_token': csrf_token
598 'csrf_token': csrf_token
600 }
599 }
601 self.app.post(post_url, post_data, status=302)
600 self.app.post(post_url, post_data, status=302)
602 settings = SettingsModel().get_all_settings()
601 settings = SettingsModel().get_all_settings()
603 assert settings[rc_pattern_key] == pattern
602 assert settings[rc_pattern_key] == pattern
604 assert settings[rc_desc_key] == new_description
603 assert settings[rc_desc_key] == new_description
605
604
606 @request.addfinalizer
605 @request.addfinalizer
607 def cleanup():
606 def cleanup():
608 IssueTrackerSettingsModel().delete_entries(self.uid)
607 IssueTrackerSettingsModel().delete_entries(self.uid)
609
608
610 def test_delete_issuetracker_pattern(
609 def test_delete_issuetracker_pattern(
611 self, autologin_user, backend, csrf_token, settings_util):
610 self, autologin_user, backend, csrf_token, settings_util):
612 pattern = 'issuetracker_pat'
611 pattern = 'issuetracker_pat'
613 uid = md5(pattern)
612 uid = md5(pattern)
614 settings_util.create_rhodecode_setting(
613 settings_util.create_rhodecode_setting(
615 self.SHORT_PATTERN_KEY+uid, pattern, 'unicode', cleanup=False)
614 self.SHORT_PATTERN_KEY+uid, pattern, 'unicode', cleanup=False)
616
615
617 post_url = url('admin_issuetracker_delete')
616 post_url = url('admin_issuetracker_delete')
618 post_data = {
617 post_data = {
619 '_method': 'delete',
618 '_method': 'delete',
620 'uid': uid,
619 'uid': uid,
621 'csrf_token': csrf_token
620 'csrf_token': csrf_token
622 }
621 }
623 self.app.post(post_url, post_data, status=302)
622 self.app.post(post_url, post_data, status=302)
624 settings = SettingsModel().get_all_settings()
623 settings = SettingsModel().get_all_settings()
625 assert 'rhodecode_%s%s' % (self.SHORT_PATTERN_KEY, uid) not in settings
624 assert 'rhodecode_%s%s' % (self.SHORT_PATTERN_KEY, uid) not in settings
General Comments 0
You need to be logged in to leave comments. Login now