##// END OF EJS Templates
integrations: refactor/cleanup + features, fixes #4181...
integrations: refactor/cleanup + features, fixes #4181 * added scopes on integrations, scopes are: - repo only - repogroup children only - root repos only - global (any repo) * integrations schemas now have separate section for the settings (eg. slack) and options (eg. scope/enabled) * added descriptions to integration types * added icons to integration types * added 'create new' integration page * added scope of integration to integrations list * added breadcrumbs for each repo/repogroup/global integrations pages * added sorting to integrations list * added pagination to integrations list * added icons to integrations list * added type filter to integrations list * added message to integrations list if none we found * added extra permissions check on integrations views * db migration from 56 => 57 - adds child_repos_only field * added tests for integrations triggered on events * added tests for integrations schemas * added tests for integrations views for repo/repogroup/admin

File last commit:

r624:e0a65beb default
r731:7a6d3636 default
Show More
test_sanitize_settings.py
202 lines | 7.3 KiB | text/x-python | PythonLexer
/ rhodecode / tests / config / test_sanitize_settings.py
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 # -*- coding: utf-8 -*-
# Copyright (C) 2016-2016 RhodeCode GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import pytest
from rhodecode.config.middleware import (
Martin Bornhold
tests: Test sanitize helper function for integer settings.
r624 _sanitize_vcs_settings, _bool_setting, _string_setting, _list_setting,
_int_setting)
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593
class TestHelperFunctions(object):
@pytest.mark.parametrize('raw, expected', [
Martin Bornhold
tests: Add some test cases for unicode and list separation.
r606 ('true', True), (u'true', True),
('yes', True), (u'yes', True),
('on', True), (u'on', True),
('false', False), (u'false', False),
('no', False), (u'no', False),
('off', False), (u'off', False),
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 ('invalid-bool-value', False),
('invalid-∫øø@-√å@¨€', False),
Martin Bornhold
tests: Add some test cases for unicode and list separation.
r606 (u'invalid-∫øø@-√å@¨€', False),
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 ])
def test_bool_setting_helper(self, raw, expected):
key = 'dummy-key'
settings = {key: raw}
_bool_setting(settings, key, None)
assert settings[key] is expected
@pytest.mark.parametrize('raw, expected', [
('', ''),
('test-string', 'test-string'),
('CaSe-TeSt', 'case-test'),
('test-string-烩€', 'test-string-烩€'),
Martin Bornhold
tests: Add some test cases for unicode and list separation.
r606 (u'test-string-烩€', u'test-string-烩€'),
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 ])
def test_string_setting_helper(self, raw, expected):
key = 'dummy-key'
settings = {key: raw}
_string_setting(settings, key, None)
assert settings[key] == expected
@pytest.mark.parametrize('raw, expected', [
('', []),
('test', ['test']),
('CaSe-TeSt', ['CaSe-TeSt']),
Martin Bornhold
tests: Add some test cases for unicode and list separation.
r606 ('test-string-烩€', ['test-string-烩€']),
(u'test-string-烩€', [u'test-string-烩€']),
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 ('hg git svn', ['hg', 'git', 'svn']),
('hg,git,svn', ['hg', 'git', 'svn']),
('hg, git, svn', ['hg', 'git', 'svn']),
('hg\ngit\nsvn', ['hg', 'git', 'svn']),
Martin Bornhold
tests: Add some test cases for unicode and list separation.
r606 (' hg\n git\n svn ', ['hg', 'git', 'svn']),
(', hg , git , svn , ', ['', 'hg', 'git', 'svn', '']),
('cheese,free node,other', ['cheese', 'free node', 'other']),
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 ])
def test_list_setting_helper(self, raw, expected):
key = 'dummy-key'
settings = {key: raw}
_list_setting(settings, key, None)
assert settings[key] == expected
Martin Bornhold
tests: Test sanitize helper function for integer settings.
r624 @pytest.mark.parametrize('raw, expected', [
('0', 0),
('-0', 0),
('12345', 12345),
('-12345', -12345),
(u'-12345', -12345),
])
def test_int_setting_helper(self, raw, expected):
key = 'dummy-key'
settings = {key: raw}
_int_setting(settings, key, None)
assert settings[key] == expected
@pytest.mark.parametrize('raw', [
('0xff'),
(''),
('invalid-int'),
('invalid-⁄~†'),
(u'invalid-⁄~†'),
])
def test_int_setting_helper_invalid_input(self, raw):
key = 'dummy-key'
settings = {key: raw}
with pytest.raises(Exception):
_int_setting(settings, key, None)
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593
class TestSanitizeVcsSettings(object):
_bool_settings = [
('vcs.hooks.direct_calls', False),
('vcs.server.enable', True),
('vcs.start_server', False),
('startup.import_repos', False),
]
_string_settings = [
('vcs.svn.compatible_version', ''),
('git_rev_filter', '--all'),
('vcs.hooks.protocol', 'pyro4'),
('vcs.server', ''),
('vcs.server.log_level', 'debug'),
('vcs.server.protocol', 'pyro4'),
]
_list_settings = [
('vcs.backends', 'hg git'),
]
@pytest.mark.parametrize('key, default', _list_settings)
def test_list_setting_spacesep_list(self, key, default):
test_list = ['test', 'list', 'values', 'for', key]
input_value = ' '.join(test_list)
settings = {key: input_value}
_sanitize_vcs_settings(settings)
assert settings[key] == test_list
@pytest.mark.parametrize('key, default', _list_settings)
def test_list_setting_newlinesep_list(self, key, default):
test_list = ['test', 'list', 'values', 'for', key]
input_value = '\n'.join(test_list)
settings = {key: input_value}
_sanitize_vcs_settings(settings)
assert settings[key] == test_list
@pytest.mark.parametrize('key, default', _list_settings)
def test_list_setting_commasep_list(self, key, default):
test_list = ['test', 'list', 'values', 'for', key]
input_value = ','.join(test_list)
settings = {key: input_value}
_sanitize_vcs_settings(settings)
assert settings[key] == test_list
@pytest.mark.parametrize('key, default', _list_settings)
def test_list_setting_comma_and_space_sep_list(self, key, default):
test_list = ['test', 'list', 'values', 'for', key]
input_value = ', '.join(test_list)
settings = {key: input_value}
_sanitize_vcs_settings(settings)
assert settings[key] == test_list
@pytest.mark.parametrize('key, default', _string_settings)
def test_string_setting_string(self, key, default):
test_value = 'test-string-for-{}'.format(key)
settings = {key: test_value}
_sanitize_vcs_settings(settings)
assert settings[key] == test_value
@pytest.mark.parametrize('key, default', _string_settings)
def test_string_setting_default(self, key, default):
settings = {}
_sanitize_vcs_settings(settings)
assert settings[key] == default
@pytest.mark.parametrize('key, default', _string_settings)
def test_string_setting_lowercase(self, key, default):
test_value = 'Test-String-For-{}'.format(key)
settings = {key: test_value}
_sanitize_vcs_settings(settings)
assert settings[key] == test_value.lower()
@pytest.mark.parametrize('key, default', _bool_settings)
def test_bool_setting_true(self, key, default):
settings = {key: 'true'}
_sanitize_vcs_settings(settings)
assert settings[key] is True
@pytest.mark.parametrize('key, default', _bool_settings)
def test_bool_setting_false(self, key, default):
settings = {key: 'false'}
_sanitize_vcs_settings(settings)
assert settings[key] is False
@pytest.mark.parametrize('key, default', _bool_settings)
def test_bool_setting_invalid_string(self, key, default):
settings = {key: 'no-bool-val-string'}
_sanitize_vcs_settings(settings)
assert settings[key] is False
@pytest.mark.parametrize('key, default', _bool_settings)
def test_bool_setting_default(self, key, default):
settings = {}
_sanitize_vcs_settings(settings)
assert settings[key] is default