##// END OF EJS Templates
tests(fix): fixed git tests for new head branches
tests(fix): fixed git tests for new head branches

File last commit:

r5093:525812a8 default
r5218:e92a0575 default
Show More
test_mod_dav_svn_config.py
119 lines | 4.7 KiB | text/x-python | PythonLexer
/ rhodecode / apps / svn_support / tests / test_mod_dav_svn_config.py
copyrights: updated for 2023
r5088 # Copyright (C) 2016-2023 RhodeCode GmbH
svn-support: move into apps module.
r1531 #
# 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/
svn: allow specifying alternative template file for mod_dav config.
r2161 import re
import os
svn-support: move into apps module.
r1531 import mock
import pytest
from rhodecode.apps.svn_support import utils
tests: re-use config_stub for svn tests
r2312 @pytest.mark.usefixtures('config_stub')
svn-support: move into apps module.
r1531 class TestModDavSvnConfig(object):
@classmethod
def setup_class(cls):
apps: modernize for python3
r5093 cls.location_root = '/location/root/çµäö'
cls.parent_path_root = '/parent/path/çµäö'
cls.realm = 'Dummy Realm (äöüçµ)'
svn-support: move into apps module.
r1531
@classmethod
def get_repo_group_mocks(cls, count=1):
repo_groups = []
for num in range(0, count):
tests: fixed all tests for python3 BIG changes
r5087 full_path = f'/path/to/RepöGröúp-°µ {num}'
svn-support: move into apps module.
r1531 repo_group_mock = mock.MagicMock()
repo_group_mock.full_path = full_path
repo_group_mock.full_path_splitted = full_path.split('/')
repo_groups.append(repo_group_mock)
return repo_groups
def assert_root_location_directive(self, config):
apps: modernize for python3
r5093 pattern = '<Location "{location}">'.format(
svn-support: move into apps module.
r1531 location=self.location_root)
assert len(re.findall(pattern, config)) == 1
def assert_group_location_directive(self, config, group_path):
apps: modernize for python3
r5093 pattern = '<Location "{location}{group_path}">'.format(
svn-support: move into apps module.
r1531 location=self.location_root, group_path=group_path)
assert len(re.findall(pattern, config)) == 1
def test_render_mod_dav_svn_config(self):
repo_groups = self.get_repo_group_mocks(count=10)
generated_config = utils._render_mod_dav_svn_config(
parent_path_root=self.parent_path_root,
list_parent_path=True,
location_root=self.location_root,
repo_groups=repo_groups,
realm=self.realm,
svn: allow specifying alternative template file for mod_dav config.
r2161 use_ssl=True,
template=''
svn-support: move into apps module.
r1531 )
# Assert that one location directive exists for each repository group.
for group in repo_groups:
self.assert_group_location_directive(
generated_config, group.full_path)
# Assert that the root location directive exists.
self.assert_root_location_directive(generated_config)
svn: allow specifying alternative template file for mod_dav config.
r2161 def test_render_mod_dav_svn_config_with_alternative_template(self, tmpdir):
repo_groups = self.get_repo_group_mocks(count=10)
test_file_path = os.path.join(str(tmpdir), 'example.mako')
apps: modernize for python3
r5093 with open(test_file_path, 'w') as f:
svn: allow specifying alternative template file for mod_dav config.
r2161 f.write('TEST_EXAMPLE\n')
generated_config = utils._render_mod_dav_svn_config(
parent_path_root=self.parent_path_root,
list_parent_path=True,
location_root=self.location_root,
repo_groups=repo_groups,
realm=self.realm,
use_ssl=True,
template=test_file_path
)
assert 'TEST_EXAMPLE' in generated_config
svn-support: move into apps module.
r1531 @pytest.mark.parametrize('list_parent_path', [True, False])
@pytest.mark.parametrize('use_ssl', [True, False])
def test_list_parent_path(self, list_parent_path, use_ssl):
generated_config = utils._render_mod_dav_svn_config(
parent_path_root=self.parent_path_root,
list_parent_path=list_parent_path,
location_root=self.location_root,
repo_groups=self.get_repo_group_mocks(count=10),
realm=self.realm,
svn: allow specifying alternative template file for mod_dav config.
r2161 use_ssl=use_ssl,
template=''
svn-support: move into apps module.
r1531 )
# Assert that correct configuration directive is present.
if list_parent_path:
tests: fixed all tests for python3 BIG changes
r5087 assert not re.search(r'SVNListParentPath\s+Off', generated_config)
assert re.search(r'SVNListParentPath\s+On', generated_config)
svn-support: move into apps module.
r1531 else:
tests: fixed all tests for python3 BIG changes
r5087 assert re.search(r'SVNListParentPath\s+Off', generated_config)
assert not re.search(r'SVNListParentPath\s+On', generated_config)
svn-support: move into apps module.
r1531
if use_ssl:
assert 'RequestHeader edit Destination ^https: http: early' \
in generated_config
else:
assert '#RequestHeader edit Destination ^https: http: early' \
in generated_config