diff --git a/rhodecode/tests/functional/test_admin_settings.py b/rhodecode/tests/functional/test_admin_settings.py --- a/rhodecode/tests/functional/test_admin_settings.py +++ b/rhodecode/tests/functional/test_admin_settings.py @@ -1,69 +1,91 @@ # -*- coding: utf-8 -*- from rhodecode.lib.auth import get_crypt_password, check_password -from rhodecode.model.db import User, RhodeCodeSetting, Repository +from rhodecode.model.db import User, RhodeCodeSetting, Repository, RhodeCodeUi from rhodecode.tests import * +from rhodecode.tests.fixture import Fixture from rhodecode.lib import helpers as h from rhodecode.model.user import UserModel from rhodecode.model.scm import ScmModel from rhodecode.model.meta import Session +fixture = Fixture() + class TestAdminSettingsController(TestController): - def test_index(self): + def test_index_main(self): + self.log_user() response = self.app.get(url('admin_settings')) - # Test response... - def test_index_as_xml(self): - response = self.app.get(url('formatted_admin_settings', format='xml')) + 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')) - def test_create(self): - response = self.app.post(url('admin_settings')) + def test_index_visual(self): + self.log_user() + response = self.app.get(url('admin_settings_visual')) - def test_new(self): - response = self.app.get(url('admin_new_setting')) + def test_index_email(self): + self.log_user() + response = self.app.get(url('admin_settings_email')) - def test_new_as_xml(self): - response = self.app.get(url('formatted_admin_new_setting', format='xml')) + def test_index_hooks(self): + self.log_user() + response = self.app.get(url('admin_settings_hooks')) - def test_update(self): - response = self.app.put(url('admin_setting', setting_id=1)) + 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')) - def test_update_browser_fakeout(self): - response = self.app.post(url('admin_setting', setting_id=1), params=dict(_method='put')) + response = response.follow() + response.mustcontain('test_hooks_1') + response.mustcontain('cd /tmp') - def test_delete(self): - response = self.app.delete(url('admin_setting', setting_id=1)) + 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')) - def test_delete_browser_fakeout(self): - response = self.app.post(url('admin_setting', setting_id=1), params=dict(_method='delete')) + response = response.follow() + response.mustcontain('test_hooks_2') + response.mustcontain('cd /tmp2') - def test_show(self): - response = self.app.get(url('admin_setting', setting_id=1)) - - def test_show_as_xml(self): - response = self.app.get(url('formatted_admin_setting', setting_id=1, format='xml')) + 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']) - def test_edit(self): - response = self.app.get(url('admin_edit_setting', setting_id=1)) + def test_index_search(self): + self.log_user() + response = self.app.get(url('admin_settings_search')) - def test_edit_as_xml(self): - response = self.app.get(url('formatted_admin_edit_setting', - setting_id=1, format='xml')) + def test_index_system(self): + self.log_user() + response = self.app.get(url('admin_settings_system')) def test_ga_code_active(self): self.log_user() old_title = 'RhodeCode' old_realm = 'RhodeCode authentication' new_ga_code = 'ga-test-123456789' - response = self.app.post(url('admin_setting', setting_id='global'), - params=dict( - _method='put', - rhodecode_title=old_title, - rhodecode_realm=old_realm, - rhodecode_ga_code=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='', + )) self.checkSessionFlash(response, 'Updated application settings') @@ -78,13 +100,13 @@ class TestAdminSettingsController(TestCo old_title = 'RhodeCode' old_realm = 'RhodeCode authentication' new_ga_code = '' - response = self.app.post(url('admin_setting', setting_id='global'), - params=dict( - _method='put', - rhodecode_title=old_title, - rhodecode_realm=old_realm, - rhodecode_ga_code=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='', + )) self.checkSessionFlash(response, 'Updated application settings') self.assertEqual(RhodeCodeSetting @@ -93,6 +115,46 @@ class TestAdminSettingsController(TestCo response = response.follow() response.mustcontain(no=["_gaq.push(['_setAccount', '%s']);" % new_ga_code]) + 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']) + def test_title_change(self): self.log_user() old_title = 'RhodeCode' @@ -100,13 +162,13 @@ class TestAdminSettingsController(TestCo old_realm = 'RhodeCode authentication' for new_title in ['Changed', 'Żółwik', old_title]: - response = self.app.post(url('admin_setting', setting_id='global'), - params=dict( - _method='put', - rhodecode_title=new_title, - rhodecode_realm=old_realm, - rhodecode_ga_code='' - )) + 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='', + )) self.checkSessionFlash(response, 'Updated application settings') self.assertEqual(RhodeCodeSetting @@ -114,152 +176,4 @@ class TestAdminSettingsController(TestCo new_title.decode('utf-8')) response = response.follow() - response.mustcontain("""

%s

""" % new_title) - - def test_my_account(self): - self.log_user() - response = self.app.get(url('admin_settings_my_account')) - - response.mustcontain('value="test_admin') - - @parameterized.expand([('firstname', 'new_username'), - ('lastname', 'new_username'), - ('admin', True), - ('admin', False), - ('ldap_dn', 'test'), - ('ldap_dn', None), - ('active', False), - ('active', True), - ('email', 'some@email.com'), - ]) - def test_my_account_update(self, name, expected): - uname = 'testme' - usr = UserModel().create_or_update(username=uname, password='qweqwe', - email='testme@rhodecod.org') - Session().commit() - params = usr.get_api_data() - user_id = usr.user_id - self.log_user(username=uname, password='qweqwe') - params.update({name: expected}) - params.update({'password_confirmation': ''}) - params.update({'new_password': ''}) - - try: - response = self.app.put(url('admin_settings_my_account_update', - id=user_id), params) - - self.checkSessionFlash(response, - 'Your account was updated successfully') - - updated_user = User.get_by_username(uname) - updated_params = updated_user.get_api_data() - updated_params.update({'password_confirmation': ''}) - updated_params.update({'new_password': ''}) - - params['last_login'] = updated_params['last_login'] - if name == 'email': - params['emails'] = [expected] - if name == 'ldap_dn': - #cannot update this via form - params['ldap_dn'] = None - if name == 'active': - #my account cannot deactivate account - params['active'] = True - if name == 'admin': - #my account cannot make you an admin ! - params['admin'] = False - - self.assertEqual(params, updated_params) - - finally: - UserModel().delete('testme') - - def test_my_account_update_err_email_exists(self): - self.log_user() - - new_email = 'test_regular@mail.com' # already exisitn email - response = self.app.put(url('admin_settings_my_account_update'), - params=dict( - username='test_admin', - new_password='test12', - password_confirmation='test122', - firstname='NewName', - lastname='NewLastname', - email=new_email,) - ) - - response.mustcontain('This e-mail address is already taken') - - def test_my_account_update_err(self): - self.log_user('test_regular2', 'test12') - - new_email = 'newmail.pl' - response = self.app.post(url('admin_settings_my_account_update'), - params=dict( - _method='put', - username='test_admin', - new_password='test12', - password_confirmation='test122', - firstname='NewName', - lastname='NewLastname', - email=new_email,) - ) - - response.mustcontain('An email address must contain a single @') - from rhodecode.model import validators - msg = validators.ValidUsername(edit=False, - old_data={})._messages['username_exists'] - msg = h.html_escape(msg % {'username': 'test_admin'}) - response.mustcontain(u"%s" % msg) - - def test_set_repo_fork_has_no_self_id(self): - self.log_user() - repo = Repository.get_by_repo_name(HG_REPO) - response = self.app.get(url('edit_repo', repo_name=HG_REPO)) - opt = """""" % repo.repo_id - response.mustcontain(no=[opt]) - - def test_set_fork_of_repo(self): - self.log_user() - repo = Repository.get_by_repo_name(HG_REPO) - repo2 = Repository.get_by_repo_name(GIT_REPO) - response = self.app.put(url('repo_as_fork', repo_name=HG_REPO), - params=dict( - id_fork_of=repo2.repo_id - )) - repo = Repository.get_by_repo_name(HG_REPO) - repo2 = Repository.get_by_repo_name(GIT_REPO) - self.checkSessionFlash(response, - 'Marked repo %s as fork of %s' % (repo.repo_name, repo2.repo_name)) - - assert repo.fork == repo2 - response = response.follow() - # check if given repo is selected - - opt = """""" % ( - repo2.repo_id, repo2.repo_name) - response.mustcontain(opt) - - # clean session flash - #response = self.app.get(url('edit_repo', repo_name=HG_REPO)) - - ## mark it as None - response = self.app.put(url('repo_as_fork', repo_name=HG_REPO), - params=dict( - id_fork_of=None - )) - repo = Repository.get_by_repo_name(HG_REPO) - repo2 = Repository.get_by_repo_name(GIT_REPO) - self.checkSessionFlash(response, - 'Marked repo %s as fork of %s' % (repo.repo_name, "Nothing")) - assert repo.fork is None - - def test_set_fork_of_same_repo(self): - self.log_user() - repo = Repository.get_by_repo_name(HG_REPO) - response = self.app.put(url('repo_as_fork', repo_name=HG_REPO), - params=dict( - id_fork_of=repo.repo_id - )) - self.checkSessionFlash(response, - 'An error occurred during this operation') + response.mustcontain("""
- %s
""" % new_title)