##// END OF EJS Templates
tests: Fix tests for moved labs setting....
Martin Bornhold -
r371:47b7ed9f default
parent child Browse files
Show More
@@ -1,624 +1,655 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 198 }
199 199 params.update(settings)
200 200 response = self.app.post(url('admin_settings_global'), params=params)
201 201
202 202 assert_session_flash(response, 'Updated application settings')
203 203 app_settings = SettingsModel().get_all_settings()
204 204 del settings['csrf_token']
205 205 for key, value in settings.iteritems():
206 206 assert app_settings[key] == value.decode('utf-8')
207 207
208 208 return response
209 209
210 210
211 211 @pytest.mark.usefixtures('autologin_user', 'app')
212 212 class TestAdminSettingsVcs:
213 213
214 214 def test_contains_svn_default_patterns(self, app):
215 215 response = app.get(url('admin_settings_vcs'))
216 216 expected_patterns = [
217 217 '/trunk',
218 218 '/branches/*',
219 219 '/tags/*',
220 220 ]
221 221 for pattern in expected_patterns:
222 222 response.mustcontain(pattern)
223 223
224 224 def test_add_new_svn_branch_and_tag_pattern(
225 225 self, app, backend_svn, form_defaults, disable_sql_cache,
226 226 csrf_token):
227 227 form_defaults.update({
228 228 'new_svn_branch': '/exp/branches/*',
229 229 'new_svn_tag': '/important_tags/*',
230 230 'csrf_token': csrf_token,
231 231 })
232 232
233 233 response = app.post(
234 234 url('admin_settings_vcs'), params=form_defaults, status=302)
235 235 response = response.follow()
236 236
237 237 # Expect to find the new values on the page
238 238 response.mustcontain('/exp/branches/*')
239 239 response.mustcontain('/important_tags/*')
240 240
241 241 # Expect that those patterns are used to match branches and tags now
242 242 repo = backend_svn['svn-simple-layout'].scm_instance()
243 243 assert 'exp/branches/exp-sphinx-docs' in repo.branches
244 244 assert 'important_tags/v0.5' in repo.tags
245 245
246 246 def test_add_same_svn_value_twice_shows_an_error_message(
247 247 self, app, form_defaults, csrf_token, settings_util):
248 248 settings_util.create_rhodecode_ui('vcs_svn_branch', '/test')
249 249 settings_util.create_rhodecode_ui('vcs_svn_tag', '/test')
250 250
251 251 response = app.post(
252 252 url('admin_settings_vcs'),
253 253 params={
254 254 'paths_root_path': form_defaults['paths_root_path'],
255 255 'new_svn_branch': '/test',
256 256 'new_svn_tag': '/test',
257 257 'csrf_token': csrf_token,
258 258 },
259 259 status=200)
260 260
261 261 response.mustcontain("Pattern already exists")
262 262 response.mustcontain("Some form inputs contain invalid data.")
263 263
264 264 @pytest.mark.parametrize('section', [
265 265 'vcs_svn_branch',
266 266 'vcs_svn_tag',
267 267 ])
268 268 def test_delete_svn_patterns(
269 269 self, section, app, csrf_token, settings_util):
270 270 setting = settings_util.create_rhodecode_ui(
271 271 section, '/test_delete', cleanup=False)
272 272
273 273 app.post(
274 274 url('admin_settings_vcs'),
275 275 params={
276 276 '_method': 'delete',
277 277 'delete_svn_pattern': setting.ui_id,
278 278 'csrf_token': csrf_token},
279 279 headers={'X-REQUESTED-WITH': 'XMLHttpRequest'})
280 280
281 281 @pytest.mark.parametrize('section', [
282 282 'vcs_svn_branch',
283 283 'vcs_svn_tag',
284 284 ])
285 285 def test_delete_svn_patterns_raises_400_when_no_xhr(
286 286 self, section, app, csrf_token, settings_util):
287 287 setting = settings_util.create_rhodecode_ui(section, '/test_delete')
288 288
289 289 app.post(
290 290 url('admin_settings_vcs'),
291 291 params={
292 292 '_method': 'delete',
293 293 'delete_svn_pattern': setting.ui_id,
294 294 'csrf_token': csrf_token},
295 295 status=400)
296 296
297 297 def test_extensions_hgsubversion(self, app, form_defaults, csrf_token):
298 298 form_defaults.update({
299 299 'csrf_token': csrf_token,
300 300 'extensions_hgsubversion': 'True',
301 301 })
302 302 response = app.post(
303 303 url('admin_settings_vcs'),
304 304 params=form_defaults,
305 305 status=302)
306 306
307 307 response = response.follow()
308 308 extensions_input = (
309 309 '<input id="extensions_hgsubversion" '
310 310 'name="extensions_hgsubversion" type="checkbox" '
311 311 'value="True" checked="checked" />')
312 312 response.mustcontain(extensions_input)
313 313
314 314 def test_has_a_section_for_pull_request_settings(self, app):
315 315 response = app.get(url('admin_settings_vcs'))
316 316 response.mustcontain('Pull Request Settings')
317 317
318 318 def test_has_an_input_for_invalidation_of_inline_comments(
319 319 self, app):
320 320 response = app.get(url('admin_settings_vcs'))
321 321 assert_response = AssertResponse(response)
322 322 assert_response.one_element_exists(
323 323 '[name=rhodecode_use_outdated_comments]')
324 324
325 325 @pytest.mark.parametrize('new_value', [True, False])
326 326 def test_allows_to_change_invalidation_of_inline_comments(
327 327 self, app, form_defaults, csrf_token, new_value):
328 328 setting_key = 'use_outdated_comments'
329 329 setting = SettingsModel().create_or_update_setting(
330 330 setting_key, not new_value, 'bool')
331 331 Session().add(setting)
332 332 Session().commit()
333 333
334 334 form_defaults.update({
335 335 'csrf_token': csrf_token,
336 336 'rhodecode_use_outdated_comments': str(new_value),
337 337 })
338 338 response = app.post(
339 339 url('admin_settings_vcs'),
340 340 params=form_defaults,
341 341 status=302)
342 342 response = response.follow()
343 343 setting = SettingsModel().get_setting_by_name(setting_key)
344 344 assert setting.app_settings_value is new_value
345 345
346 def test_has_a_section_for_labs_settings_if_enabled(self, app):
347 with mock.patch.dict(
348 rhodecode.CONFIG, {'labs_settings_active': 'true'}):
349 response = self.app.get(url('admin_settings_vcs'))
350 response.mustcontain('Labs settings:')
351
352 def test_has_not_a_section_for_labs_settings_if_disables(self, app):
353 with mock.patch.dict(
354 rhodecode.CONFIG, {'labs_settings_active': 'false'}):
355 response = self.app.get(url('admin_settings_vcs'))
356 response.mustcontain(no='Labs settings:')
357
358 @pytest.mark.parametrize('new_value', [True, False])
359 def test_allows_to_change_hg_rebase_merge_strategy(
360 self, app, form_defaults, csrf_token, new_value):
361 setting_key = 'hg_use_rebase_for_merging'
362
363 form_defaults.update({
364 'csrf_token': csrf_token,
365 'rhodecode_' + setting_key: str(new_value),
366 })
367
368 with mock.patch.dict(
369 rhodecode.CONFIG, {'labs_settings_active': 'true'}):
370 app.post(
371 url('admin_settings_vcs'),
372 params=form_defaults,
373 status=302)
374
375 setting = SettingsModel().get_setting_by_name(setting_key)
376 assert setting.app_settings_value is new_value
377
346 378 @pytest.fixture
347 379 def disable_sql_cache(self, request):
348 380 patcher = mock.patch(
349 381 'rhodecode.lib.caching_query.FromCache.process_query')
350 382 request.addfinalizer(patcher.stop)
351 383 patcher.start()
352 384
353 385 @pytest.fixture
354 386 def form_defaults(self):
355 387 from rhodecode.controllers.admin.settings import SettingsController
356 388 controller = SettingsController()
357 389 return controller._form_defaults()
358 390
359 391 # TODO: johbo: What we really want is to checkpoint before a test run and
360 392 # reset the session afterwards.
361 393 @pytest.fixture(scope='class', autouse=True)
362 394 def cleanup_settings(self, request, pylonsapp):
363 395 ui_id = RhodeCodeUi.ui_id
364 396 original_ids = list(
365 397 r.ui_id for r in RhodeCodeUi.query().values(ui_id))
366 398
367 399 @request.addfinalizer
368 400 def cleanup():
369 401 RhodeCodeUi.query().filter(
370 402 ui_id.notin_(original_ids)).delete(False)
371 403
372 404
373 405 @pytest.mark.usefixtures('autologin_user', 'app')
374 406 class TestLabsSettings(object):
375 407 def test_get_settings_page_disabled(self):
376 408 with mock.patch.dict(rhodecode.CONFIG,
377 409 {'labs_settings_active': 'false'}):
378 410 response = self.app.get(url('admin_settings_labs'), status=302)
379 411
380 412 assert response.location.endswith(url('admin_settings'))
381 413
382 414 def test_get_settings_page_enabled(self):
383 415 from rhodecode.controllers.admin import settings
384 416 lab_settings = [
385 417 settings.LabSetting(
386 418 key='rhodecode_bool',
387 419 type='bool',
388 420 group='bool group',
389 421 label='bool label',
390 422 help='bool help'
391 423 ),
392 424 settings.LabSetting(
393 425 key='rhodecode_text',
394 426 type='unicode',
395 427 group='text group',
396 428 label='text label',
397 429 help='text help'
398 430 ),
399 431 ]
400 432 with mock.patch.dict(rhodecode.CONFIG,
401 433 {'labs_settings_active': 'true'}):
402 434 with mock.patch.object(settings, '_LAB_SETTINGS', lab_settings):
403 435 response = self.app.get(url('admin_settings_labs'))
404 436
405 437 assert '<label>bool group:</label>' in response
406 438 assert '<label for="rhodecode_bool">bool label</label>' in response
407 439 assert '<p class="help-block">bool help</p>' in response
408 440 assert 'name="rhodecode_bool" type="checkbox"' in response
409 441
410 442 assert '<label>text group:</label>' in response
411 443 assert '<label for="rhodecode_text">text label</label>' in response
412 444 assert '<p class="help-block">text help</p>' in response
413 445 assert 'name="rhodecode_text" size="60" type="text"' in response
414 446
415 447 @pytest.mark.parametrize('setting_name', [
416 448 'proxy_subversion_http_requests',
417 'hg_use_rebase_for_merging',
418 449 ])
419 450 def test_update_boolean_settings(self, csrf_token, setting_name):
420 451 self.app.post(
421 452 url('admin_settings_labs'),
422 453 params={
423 454 'rhodecode_{}'.format(setting_name): 'true',
424 455 'csrf_token': csrf_token,
425 456 })
426 457 setting = SettingsModel().get_setting_by_name(setting_name)
427 458 assert setting.app_settings_value
428 459
429 460 self.app.post(
430 461 url('admin_settings_labs'),
431 462 params={
432 463 'rhodecode_{}'.format(setting_name): 'false',
433 464 'csrf_token': csrf_token,
434 465 })
435 466 setting = SettingsModel().get_setting_by_name(setting_name)
436 467 assert not setting.app_settings_value
437 468
438 469 @pytest.mark.parametrize('setting_name', [
439 470 'subversion_http_server_url',
440 471 ])
441 472 def test_update_string_settings(self, csrf_token, setting_name):
442 473 self.app.post(
443 474 url('admin_settings_labs'),
444 475 params={
445 476 'rhodecode_{}'.format(setting_name): 'Test 1',
446 477 'csrf_token': csrf_token,
447 478 })
448 479 setting = SettingsModel().get_setting_by_name(setting_name)
449 480 assert setting.app_settings_value == 'Test 1'
450 481
451 482 self.app.post(
452 483 url('admin_settings_labs'),
453 484 params={
454 485 'rhodecode_{}'.format(setting_name): ' Test 2 ',
455 486 'csrf_token': csrf_token,
456 487 })
457 488 setting = SettingsModel().get_setting_by_name(setting_name)
458 489 assert setting.app_settings_value == 'Test 2'
459 490
460 491
461 492 @pytest.mark.usefixtures('app')
462 493 class TestOpenSourceLicenses(object):
463 494
464 495 def _get_url(self):
465 496 return ADMIN_PREFIX + '/settings/open_source'
466 497
467 498 def test_records_are_displayed(self, autologin_user):
468 499 sample_licenses = {
469 500 "python2.7-pytest-2.7.1": {
470 501 "UNKNOWN": None
471 502 },
472 503 "python2.7-Markdown-2.6.2": {
473 504 "BSD-3-Clause": "http://spdx.org/licenses/BSD-3-Clause"
474 505 }
475 506 }
476 507 read_licenses_patch = mock.patch(
477 508 'rhodecode.admin.views.read_opensource_licenses',
478 509 return_value=sample_licenses)
479 510 with read_licenses_patch:
480 511 response = self.app.get(self._get_url(), status=200)
481 512
482 513 assert_response = AssertResponse(response)
483 514 assert_response.element_contains(
484 515 '.panel-heading', 'Licenses of Third Party Packages')
485 516 for name in sample_licenses:
486 517 response.mustcontain(name)
487 518 for license in sample_licenses[name]:
488 519 assert_response.element_contains('.panel-body', license)
489 520
490 521 def test_records_can_be_read(self, autologin_user):
491 522 response = self.app.get(self._get_url(), status=200)
492 523 assert_response = AssertResponse(response)
493 524 assert_response.element_contains(
494 525 '.panel-heading', 'Licenses of Third Party Packages')
495 526
496 527 def test_forbidden_when_normal_user(self, autologin_regular_user):
497 528 self.app.get(self._get_url(), status=403)
498 529
499 530
500 531 @pytest.mark.usefixtures("app")
501 532 class TestAdminSettingsIssueTracker:
502 533 RC_PREFIX = 'rhodecode_'
503 534 SHORT_PATTERN_KEY = 'issuetracker_pat_'
504 535 PATTERN_KEY = RC_PREFIX + SHORT_PATTERN_KEY
505 536
506 537 def test_issuetracker_index(self, autologin_user):
507 538 response = self.app.get(url('admin_settings_issuetracker'))
508 539 assert response.status_code == 200
509 540
510 541 def test_add_issuetracker_pattern(
511 542 self, request, autologin_user, csrf_token):
512 543 pattern = 'issuetracker_pat'
513 544 another_pattern = pattern+'1'
514 545 post_url = url('admin_settings_issuetracker_save')
515 546 post_data = {
516 547 'new_pattern_pattern_0': pattern,
517 548 'new_pattern_url_0': 'url',
518 549 'new_pattern_prefix_0': 'prefix',
519 550 'new_pattern_description_0': 'description',
520 551 'new_pattern_pattern_1': another_pattern,
521 552 'new_pattern_url_1': 'url1',
522 553 'new_pattern_prefix_1': 'prefix1',
523 554 'new_pattern_description_1': 'description1',
524 555 'csrf_token': csrf_token
525 556 }
526 557 self.app.post(post_url, post_data, status=302)
527 558 settings = SettingsModel().get_all_settings()
528 559 self.uid = md5(pattern)
529 560 assert settings[self.PATTERN_KEY+self.uid] == pattern
530 561 self.another_uid = md5(another_pattern)
531 562 assert settings[self.PATTERN_KEY+self.another_uid] == another_pattern
532 563
533 564 @request.addfinalizer
534 565 def cleanup():
535 566 defaults = SettingsModel().get_all_settings()
536 567
537 568 entries = [name for name in defaults if (
538 569 (self.uid in name) or (self.another_uid) in name)]
539 570 start = len(self.RC_PREFIX)
540 571 for del_key in entries:
541 572 # TODO: anderson: get_by_name needs name without prefix
542 573 entry = SettingsModel().get_setting_by_name(del_key[start:])
543 574 Session().delete(entry)
544 575
545 576 Session().commit()
546 577
547 578 def test_edit_issuetracker_pattern(
548 579 self, autologin_user, backend, csrf_token, request):
549 580 old_pattern = 'issuetracker_pat'
550 581 old_uid = md5(old_pattern)
551 582 pattern = 'issuetracker_pat_new'
552 583 self.new_uid = md5(pattern)
553 584
554 585 SettingsModel().create_or_update_setting(
555 586 self.SHORT_PATTERN_KEY+old_uid, old_pattern, 'unicode')
556 587
557 588 post_url = url('admin_settings_issuetracker_save')
558 589 post_data = {
559 590 'new_pattern_pattern_0': pattern,
560 591 'new_pattern_url_0': 'url',
561 592 'new_pattern_prefix_0': 'prefix',
562 593 'new_pattern_description_0': 'description',
563 594 'uid': old_uid,
564 595 'csrf_token': csrf_token
565 596 }
566 597 self.app.post(post_url, post_data, status=302)
567 598 settings = SettingsModel().get_all_settings()
568 599 assert settings[self.PATTERN_KEY+self.new_uid] == pattern
569 600 assert self.PATTERN_KEY+old_uid not in settings
570 601
571 602 @request.addfinalizer
572 603 def cleanup():
573 604 IssueTrackerSettingsModel().delete_entries(self.new_uid)
574 605
575 606 def test_replace_issuetracker_pattern_description(
576 607 self, autologin_user, csrf_token, request, settings_util):
577 608 prefix = 'issuetracker'
578 609 pattern = 'issuetracker_pat'
579 610 self.uid = md5(pattern)
580 611 pattern_key = '_'.join([prefix, 'pat', self.uid])
581 612 rc_pattern_key = '_'.join(['rhodecode', pattern_key])
582 613 desc_key = '_'.join([prefix, 'desc', self.uid])
583 614 rc_desc_key = '_'.join(['rhodecode', desc_key])
584 615 new_description = 'new_description'
585 616
586 617 settings_util.create_rhodecode_setting(
587 618 pattern_key, pattern, 'unicode', cleanup=False)
588 619 settings_util.create_rhodecode_setting(
589 620 desc_key, 'old description', 'unicode', cleanup=False)
590 621
591 622 post_url = url('admin_settings_issuetracker_save')
592 623 post_data = {
593 624 'new_pattern_pattern_0': pattern,
594 625 'new_pattern_url_0': 'url',
595 626 'new_pattern_prefix_0': 'prefix',
596 627 'new_pattern_description_0': new_description,
597 628 'uid': self.uid,
598 629 'csrf_token': csrf_token
599 630 }
600 631 self.app.post(post_url, post_data, status=302)
601 632 settings = SettingsModel().get_all_settings()
602 633 assert settings[rc_pattern_key] == pattern
603 634 assert settings[rc_desc_key] == new_description
604 635
605 636 @request.addfinalizer
606 637 def cleanup():
607 638 IssueTrackerSettingsModel().delete_entries(self.uid)
608 639
609 640 def test_delete_issuetracker_pattern(
610 641 self, autologin_user, backend, csrf_token, settings_util):
611 642 pattern = 'issuetracker_pat'
612 643 uid = md5(pattern)
613 644 settings_util.create_rhodecode_setting(
614 645 self.SHORT_PATTERN_KEY+uid, pattern, 'unicode', cleanup=False)
615 646
616 647 post_url = url('admin_issuetracker_delete')
617 648 post_data = {
618 649 '_method': 'delete',
619 650 'uid': uid,
620 651 'csrf_token': csrf_token
621 652 }
622 653 self.app.post(post_url, post_data, status=302)
623 654 settings = SettingsModel().get_all_settings()
624 655 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