Files
@ e527cc2ce8dc
Branch filter:
Location: kallithea/kallithea/tests/functional/test_admin_settings.py
e527cc2ce8dc
9.1 KiB
text/x-python
cleanup: get rid of most "import *"
Apply script generated with the following hack:
(
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(.*)' may be undefined, or defined from star imports.*/sed -ri 's,\\\\<\2\\\\>([^=]|$),XXXX.\2\\\\1,g' \1/gp" | sort -u
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.* undefined name '(.*)'$/sed -ri 's,\\\\<\2\\\\>([^=]|$),XXXX.\2\\\\1,g' \1/gp" | sort -u
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(from .*)\.([^.]*) import \*' used.*/sed -ri 's,\\\\<XXXX\\\\.,\3.,g' \1/gp" | sort -u
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(from .*)\.([^.]*) import \*' used.*/sed -ri 's,\2\\\\.\3 .*,\2 import \3,g' \1/gp" | sort -u
) | grep -v kallithea/bin/kallithea_cli_ishell.py > fix2.sh
Apply script generated with the following hack:
(
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(.*)' may be undefined, or defined from star imports.*/sed -ri 's,\\\\<\2\\\\>([^=]|$),XXXX.\2\\\\1,g' \1/gp" | sort -u
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.* undefined name '(.*)'$/sed -ri 's,\\\\<\2\\\\>([^=]|$),XXXX.\2\\\\1,g' \1/gp" | sort -u
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(from .*)\.([^.]*) import \*' used.*/sed -ri 's,\\\\<XXXX\\\\.,\3.,g' \1/gp" | sort -u
hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(from .*)\.([^.]*) import \*' used.*/sed -ri 's,\2\\\\.\3 .*,\2 import \3,g' \1/gp" | sort -u
) | grep -v kallithea/bin/kallithea_cli_ishell.py > fix2.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | # -*- coding: utf-8 -*-
from kallithea.model.db import Setting, Ui
from kallithea.tests import base
from kallithea.tests.fixture import Fixture
fixture = Fixture()
class TestAdminSettingsController(base.TestController):
def test_index_main(self):
self.log_user()
response = self.app.get(base.url('admin_settings'))
def test_index_mapping(self):
self.log_user()
response = self.app.get(base.url('admin_settings_mapping'))
def test_index_global(self):
self.log_user()
response = self.app.get(base.url('admin_settings_global'))
def test_index_visual(self):
self.log_user()
response = self.app.get(base.url('admin_settings_visual'))
def test_index_email(self):
self.log_user()
response = self.app.get(base.url('admin_settings_email'))
def test_index_hooks(self):
self.log_user()
response = self.app.get(base.url('admin_settings_hooks'))
def test_create_custom_hook(self):
self.log_user()
response = self.app.post(base.url('admin_settings_hooks'),
params=dict(new_hook_ui_key='test_hooks_1',
new_hook_ui_value='cd %s' % base.TESTS_TMP_PATH,
_session_csrf_secret_token=self.session_csrf_secret_token()))
self.checkSessionFlash(response, 'Added new hook')
response = response.follow()
response.mustcontain('test_hooks_1')
response.mustcontain('cd %s' % base.TESTS_TMP_PATH)
def test_edit_custom_hook(self):
self.log_user()
response = self.app.post(base.url('admin_settings_hooks'),
params=dict(hook_ui_key='test_hooks_1',
hook_ui_value='old_value_of_hook_1',
hook_ui_value_new='new_value_of_hook_1',
_session_csrf_secret_token=self.session_csrf_secret_token()))
response = response.follow()
response.mustcontain('test_hooks_1')
response.mustcontain('new_value_of_hook_1')
def test_add_existing_custom_hook(self):
self.log_user()
response = self.app.post(base.url('admin_settings_hooks'),
params=dict(new_hook_ui_key='test_hooks_1',
new_hook_ui_value='attempted_new_value',
_session_csrf_secret_token=self.session_csrf_secret_token()))
self.checkSessionFlash(response, 'Hook already exists')
response = response.follow()
response.mustcontain('test_hooks_1')
response.mustcontain('new_value_of_hook_1')
def test_create_custom_hook_delete(self):
self.log_user()
response = self.app.post(base.url('admin_settings_hooks'),
params=dict(new_hook_ui_key='test_hooks_2',
new_hook_ui_value='cd %s2' % base.TESTS_TMP_PATH,
_session_csrf_secret_token=self.session_csrf_secret_token()))
self.checkSessionFlash(response, 'Added new hook')
response = response.follow()
response.mustcontain('test_hooks_2')
response.mustcontain('cd %s2' % base.TESTS_TMP_PATH)
hook_id = Ui.get_by_key('hooks', 'test_hooks_2').ui_id
## delete
self.app.post(base.url('admin_settings_hooks'),
params=dict(hook_id=hook_id, _session_csrf_secret_token=self.session_csrf_secret_token()))
response = self.app.get(base.url('admin_settings_hooks'))
response.mustcontain(no=['test_hooks_2'])
response.mustcontain(no=['cd %s2' % base.TESTS_TMP_PATH])
def test_add_existing_builtin_hook(self):
self.log_user()
response = self.app.post(base.url('admin_settings_hooks'),
params=dict(new_hook_ui_key='changegroup.update',
new_hook_ui_value='attempted_new_value',
_session_csrf_secret_token=self.session_csrf_secret_token()))
self.checkSessionFlash(response, 'Builtin hooks are read-only')
response = response.follow()
response.mustcontain('changegroup.update')
response.mustcontain('hg update >&2')
def test_index_search(self):
self.log_user()
response = self.app.get(base.url('admin_settings_search'))
def test_index_system(self):
self.log_user()
response = self.app.get(base.url('admin_settings_system'))
def test_ga_code_active(self):
self.log_user()
old_title = 'Kallithea'
old_realm = 'Kallithea authentication'
new_ga_code = 'ga-test-123456789'
response = self.app.post(base.url('admin_settings_global'),
params=dict(title=old_title,
realm=old_realm,
ga_code=new_ga_code,
captcha_private_key='',
captcha_public_key='',
_session_csrf_secret_token=self.session_csrf_secret_token(),
))
self.checkSessionFlash(response, 'Updated application settings')
assert Setting.get_app_settings()['ga_code'] == new_ga_code
response = response.follow()
response.mustcontain("""_gaq.push(['_setAccount', '%s']);""" % new_ga_code)
def test_ga_code_inactive(self):
self.log_user()
old_title = 'Kallithea'
old_realm = 'Kallithea authentication'
new_ga_code = ''
response = self.app.post(base.url('admin_settings_global'),
params=dict(title=old_title,
realm=old_realm,
ga_code=new_ga_code,
captcha_private_key='',
captcha_public_key='',
_session_csrf_secret_token=self.session_csrf_secret_token(),
))
self.checkSessionFlash(response, 'Updated application settings')
assert Setting.get_app_settings()['ga_code'] == new_ga_code
response = response.follow()
response.mustcontain(no=["_gaq.push(['_setAccount', '%s']);" % new_ga_code])
def test_captcha_activate(self):
self.log_user()
old_title = 'Kallithea'
old_realm = 'Kallithea authentication'
new_ga_code = ''
response = self.app.post(base.url('admin_settings_global'),
params=dict(title=old_title,
realm=old_realm,
ga_code=new_ga_code,
captcha_private_key='1234567890',
captcha_public_key='1234567890',
_session_csrf_secret_token=self.session_csrf_secret_token(),
))
self.checkSessionFlash(response, 'Updated application settings')
assert Setting.get_app_settings()['captcha_private_key'] == '1234567890'
response = self.app.get(base.url('register'))
response.mustcontain('captcha')
def test_captcha_deactivate(self):
self.log_user()
old_title = 'Kallithea'
old_realm = 'Kallithea authentication'
new_ga_code = ''
response = self.app.post(base.url('admin_settings_global'),
params=dict(title=old_title,
realm=old_realm,
ga_code=new_ga_code,
captcha_private_key='',
captcha_public_key='1234567890',
_session_csrf_secret_token=self.session_csrf_secret_token(),
))
self.checkSessionFlash(response, 'Updated application settings')
assert Setting.get_app_settings()['captcha_private_key'] == ''
response = self.app.get(base.url('register'))
response.mustcontain(no=['captcha'])
def test_title_change(self):
self.log_user()
old_title = 'Kallithea'
new_title = old_title + '_changed'
old_realm = 'Kallithea authentication'
for new_title in ['Changed', 'Żółwik', old_title]:
response = self.app.post(base.url('admin_settings_global'),
params=dict(title=new_title,
realm=old_realm,
ga_code='',
captcha_private_key='',
captcha_public_key='',
_session_csrf_secret_token=self.session_csrf_secret_token(),
))
self.checkSessionFlash(response, 'Updated application settings')
assert Setting.get_app_settings()['title'] == new_title.decode('utf-8')
response = response.follow()
response.mustcontain("""<span class="branding">%s</span>""" % new_title)
|