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