test_admin_settings.py
179 lines
| 7.1 KiB
| text/x-python
|
PythonLexer
r1366 | # -*- coding: utf-8 -*- | |||
r754 | from rhodecode.lib.auth import get_crypt_password, check_password | |||
|
r4116 | from rhodecode.model.db import User, RhodeCodeSetting, Repository, RhodeCodeUi | ||
r547 | from rhodecode.tests import * | |||
|
r4116 | from rhodecode.tests.fixture import Fixture | ||
r2467 | from rhodecode.lib import helpers as h | |||
r2544 | from rhodecode.model.user import UserModel | |||
r2629 | from rhodecode.model.scm import ScmModel | |||
r3797 | from rhodecode.model.meta import Session | |||
r2467 | ||||
|
r4116 | fixture = Fixture() | ||
r547 | ||||
r691 | class TestAdminSettingsController(TestController): | |||
r547 | ||||
|
r4116 | def test_index_main(self): | ||
self.log_user() | ||||
r547 | response = self.app.get(url('admin_settings')) | |||
|
r4116 | def test_index_mapping(self): | ||
self.log_user() | ||||
response = self.app.get(url('admin_settings_mapping')) | ||||
def test_index_global(self): | ||||
self.log_user() | ||||
response = self.app.get(url('admin_settings_global')) | ||||
r547 | ||||
|
r4116 | def test_index_visual(self): | ||
self.log_user() | ||||
response = self.app.get(url('admin_settings_visual')) | ||||
r547 | ||||
|
r4116 | def test_index_email(self): | ||
self.log_user() | ||||
response = self.app.get(url('admin_settings_email')) | ||||
r547 | ||||
|
r4116 | def test_index_hooks(self): | ||
self.log_user() | ||||
response = self.app.get(url('admin_settings_hooks')) | ||||
r547 | ||||
|
r4116 | def test_create_custom_hook(self): | ||
self.log_user() | ||||
response = self.app.post(url('admin_settings_hooks'), | ||||
params=dict(new_hook_ui_key='test_hooks_1', | ||||
new_hook_ui_value='cd /tmp')) | ||||
r547 | ||||
|
r4116 | response = response.follow() | ||
response.mustcontain('test_hooks_1') | ||||
response.mustcontain('cd /tmp') | ||||
r547 | ||||
|
r4116 | def test_create_custom_hook_delete(self): | ||
self.log_user() | ||||
response = self.app.post(url('admin_settings_hooks'), | ||||
params=dict(new_hook_ui_key='test_hooks_2', | ||||
new_hook_ui_value='cd /tmp2')) | ||||
r547 | ||||
|
r4116 | response = response.follow() | ||
response.mustcontain('test_hooks_2') | ||||
response.mustcontain('cd /tmp2') | ||||
r547 | ||||
|
r4116 | hook_id = RhodeCodeUi.get_by_key('test_hooks_2').ui_id | ||
## delete | ||||
self.app.post(url('admin_settings_hooks'), | ||||
params=dict(hook_id=hook_id)) | ||||
response = self.app.get(url('admin_settings_hooks')) | ||||
response.mustcontain(no=['test_hooks_2']) | ||||
response.mustcontain(no=['cd /tmp2']) | ||||
r547 | ||||
|
r4116 | def test_index_search(self): | ||
self.log_user() | ||||
response = self.app.get(url('admin_settings_search')) | ||||
r547 | ||||
|
r4116 | def test_index_system(self): | ||
self.log_user() | ||||
response = self.app.get(url('admin_settings_system')) | ||||
r547 | ||||
r893 | def test_ga_code_active(self): | |||
self.log_user() | ||||
old_title = 'RhodeCode' | ||||
old_realm = 'RhodeCode authentication' | ||||
new_ga_code = 'ga-test-123456789' | ||||
|
r4116 | response = self.app.post(url('admin_settings_global'), | ||
params=dict(rhodecode_title=old_title, | ||||
rhodecode_realm=old_realm, | ||||
rhodecode_ga_code=new_ga_code, | ||||
rhodecode_captcha_private_key='', | ||||
rhodecode_captcha_public_key='', | ||||
)) | ||||
r893 | ||||
r1382 | self.checkSessionFlash(response, 'Updated application settings') | |||
r1633 | self.assertEqual(RhodeCodeSetting | |||
r1366 | .get_app_settings()['rhodecode_ga_code'], new_ga_code) | |||
r893 | ||||
response = response.follow() | ||||
r2544 | response.mustcontain("""_gaq.push(['_setAccount', '%s']);""" % new_ga_code) | |||
r893 | ||||
def test_ga_code_inactive(self): | ||||
self.log_user() | ||||
old_title = 'RhodeCode' | ||||
old_realm = 'RhodeCode authentication' | ||||
new_ga_code = '' | ||||
|
r4116 | response = self.app.post(url('admin_settings_global'), | ||
params=dict(rhodecode_title=old_title, | ||||
rhodecode_realm=old_realm, | ||||
rhodecode_ga_code=new_ga_code, | ||||
rhodecode_captcha_private_key='', | ||||
rhodecode_captcha_public_key='', | ||||
)) | ||||
r893 | ||||
r3640 | self.checkSessionFlash(response, 'Updated application settings') | |||
r1633 | self.assertEqual(RhodeCodeSetting | |||
r1366 | .get_app_settings()['rhodecode_ga_code'], new_ga_code) | |||
r893 | ||||
response = response.follow() | ||||
r3646 | response.mustcontain(no=["_gaq.push(['_setAccount', '%s']);" % new_ga_code]) | |||
r893 | ||||
|
r4116 | def test_captcha_activate(self): | ||
self.log_user() | ||||
old_title = 'RhodeCode' | ||||
old_realm = 'RhodeCode authentication' | ||||
new_ga_code = '' | ||||
response = self.app.post(url('admin_settings_global'), | ||||
params=dict(rhodecode_title=old_title, | ||||
rhodecode_realm=old_realm, | ||||
rhodecode_ga_code=new_ga_code, | ||||
rhodecode_captcha_private_key='1234567890', | ||||
rhodecode_captcha_public_key='1234567890', | ||||
)) | ||||
self.checkSessionFlash(response, 'Updated application settings') | ||||
self.assertEqual(RhodeCodeSetting | ||||
.get_app_settings()['rhodecode_captcha_private_key'], '1234567890') | ||||
response = self.app.get(url('register')) | ||||
response.mustcontain('captcha') | ||||
def test_captcha_deactivate(self): | ||||
self.log_user() | ||||
old_title = 'RhodeCode' | ||||
old_realm = 'RhodeCode authentication' | ||||
new_ga_code = '' | ||||
response = self.app.post(url('admin_settings_global'), | ||||
params=dict(rhodecode_title=old_title, | ||||
rhodecode_realm=old_realm, | ||||
rhodecode_ga_code=new_ga_code, | ||||
rhodecode_captcha_private_key='', | ||||
rhodecode_captcha_public_key='1234567890', | ||||
)) | ||||
self.checkSessionFlash(response, 'Updated application settings') | ||||
self.assertEqual(RhodeCodeSetting | ||||
.get_app_settings()['rhodecode_captcha_private_key'], '') | ||||
response = self.app.get(url('register')) | ||||
response.mustcontain(no=['captcha']) | ||||
r893 | def test_title_change(self): | |||
self.log_user() | ||||
old_title = 'RhodeCode' | ||||
new_title = old_title + '_changed' | ||||
old_realm = 'RhodeCode authentication' | ||||
r1366 | ||||
for new_title in ['Changed', 'Żółwik', old_title]: | ||||
|
r4116 | response = self.app.post(url('admin_settings_global'), | ||
params=dict(rhodecode_title=new_title, | ||||
rhodecode_realm=old_realm, | ||||
rhodecode_ga_code='', | ||||
rhodecode_captcha_private_key='', | ||||
rhodecode_captcha_public_key='', | ||||
)) | ||||
r893 | ||||
r1382 | self.checkSessionFlash(response, 'Updated application settings') | |||
r1633 | self.assertEqual(RhodeCodeSetting | |||
r1366 | .get_app_settings()['rhodecode_title'], | |||
new_title.decode('utf-8')) | ||||
r893 | ||||
r1366 | response = response.follow() | |||
|
r4116 | response.mustcontain("""<div class="branding">- %s</div>""" % new_title) | ||