##// END OF EJS Templates
celery: don't allow subtasks within tasks
celery: don't allow subtasks within tasks

File last commit:

r4823:59ec40ea default
r4875:92d53da0 default
Show More
test_sanitize_settings.py
205 lines | 7.8 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 -*-
code: update copyrights to 2020
r4306 # Copyright (C) 2016-2020 RhodeCode GmbH
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 #
# 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
tests: fixed tests for new repo settings...
r1721 from rhodecode.tests import no_newline_id_generator
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 from rhodecode.config.middleware import sanitize_settings_and_apply_defaults
from rhodecode.config.settings_maker import SettingsMaker
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 ])
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 def test_bool_func_helper(self, raw, expected):
val = SettingsMaker._bool_func(raw)
assert val == expected
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593
@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 ])
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 def test_string_func_helper(self, raw, expected):
val = SettingsMaker._string_func(raw)
assert val == expected
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593
@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']),
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823
Martin Bornhold
tests: Add some test cases for unicode and list separation.
r606 (', hg , git , svn , ', ['', 'hg', 'git', 'svn', '']),
('cheese,free node,other', ['cheese', 'free node', 'other']),
tests: fixed tests for new repo settings...
r1721 ], ids=no_newline_id_generator)
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 def test_list_setting_helper(self, raw, expected):
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 val = SettingsMaker._list_func(raw)
assert val == expected
@pytest.mark.parametrize('raw, expected', [
('hg git svn', ['hg', 'git', 'svn']),
], ids=no_newline_id_generator)
def test_list_setting_spaces_helper(self, raw, expected):
val = SettingsMaker._list_func(raw, sep=' ')
assert val == expected
@pytest.mark.parametrize('raw, expected', [
('hg\ngit\nsvn', ['hg', 'git', 'svn']),
(' hg\n git\n svn ', ['hg', 'git', 'svn']),
], ids=no_newline_id_generator)
def test_list_setting_newlines_helper(self, raw, expected):
val = SettingsMaker._list_func(raw, sep='\n')
assert val == expected
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593
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):
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 val = SettingsMaker._int_func(raw)
assert val == expected
Martin Bornhold
tests: Test sanitize helper function for integer settings.
r624
@pytest.mark.parametrize('raw', [
('0xff'),
(''),
('invalid-int'),
('invalid-⁄~†'),
(u'invalid-⁄~†'),
])
def test_int_setting_helper_invalid_input(self, raw):
with pytest.raises(Exception):
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 SettingsMaker._int_func(raw)
Martin Bornhold
tests: Test sanitize helper function for integer settings.
r624
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593
class TestSanitizeVcsSettings(object):
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 _bool_funcs = [
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 ('vcs.hooks.direct_calls', False),
('vcs.server.enable', True),
('vcs.start_server', False),
('startup.import_repos', False),
]
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 _string_funcs = [
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 ('vcs.svn.compatible_version', ''),
Martin Bornhold
tests: Change default settings in tests to 'http'
r966 ('vcs.hooks.protocol', 'http'),
hooks: made the callback host configurable....
r2833 ('vcs.hooks.host', '127.0.0.1'),
Martin Bornhold
tests: Change default settings in tests to 'http'
r966 ('vcs.scm_app_implementation', 'http'),
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 ('vcs.server', ''),
Martin Bornhold
tests: Change default settings in tests to 'http'
r966 ('vcs.server.protocol', 'http'),
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 ]
_list_settings = [
('vcs.backends', 'hg git'),
]
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 # @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_settings_and_apply_defaults({'__file__': ''}, 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_settings_and_apply_defaults({'__file__': ''}, settings)
# assert settings[key] == test_list
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593
@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}
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 sanitize_settings_and_apply_defaults({'__file__': ''}, settings)
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 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}
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 sanitize_settings_and_apply_defaults({'__file__': ''}, settings)
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 assert settings[key] == test_list
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 @pytest.mark.parametrize('key, default', _string_funcs)
def test_string_func_string(self, key, default):
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 test_value = 'test-string-for-{}'.format(key)
settings = {key: test_value}
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 sanitize_settings_and_apply_defaults({'__file__': ''}, settings)
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 assert settings[key] == test_value
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 @pytest.mark.parametrize('key, default', _string_funcs)
def test_string_func_default(self, key, default):
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 settings = {}
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 sanitize_settings_and_apply_defaults({'__file__': ''}, settings)
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 assert settings[key] == default
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 # @pytest.mark.parametrize('key, default', _string_funcs)
# def test_string_func_lowercase(self, key, default):
# test_value = 'Test-String-For-{}'.format(key)
# settings = {key: test_value}
# sanitize_settings_and_apply_defaults({'__file__': ''}, settings)
# assert settings[key] == test_value.lower()
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 @pytest.mark.parametrize('key, default', _bool_funcs)
def test_bool_func_true(self, key, default):
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 settings = {key: 'true'}
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 sanitize_settings_and_apply_defaults({'__file__': ''}, settings)
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 assert settings[key] is True
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 @pytest.mark.parametrize('key, default', _bool_funcs)
def test_bool_func_false(self, key, default):
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 settings = {key: 'false'}
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 sanitize_settings_and_apply_defaults({'__file__': ''}, settings)
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 assert settings[key] is False
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 @pytest.mark.parametrize('key, default', _bool_funcs)
def test_bool_func_invalid_string(self, key, default):
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 settings = {key: 'no-bool-val-string'}
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 sanitize_settings_and_apply_defaults({'__file__': ''}, settings)
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 assert settings[key] is False
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 @pytest.mark.parametrize('key, default', _bool_funcs)
def test_bool_func_default(self, key, default):
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 settings = {}
config: major update for the code to make it be almost fully controllable via env for new docker based installer.
r4823 sanitize_settings_and_apply_defaults({'__file__': ''}, settings)
Martin Bornhold
tests: Add test to check the sanitize settings method in app init.
r593 assert settings[key] is default