test_mod_dav_svn_config.py
97 lines
| 3.7 KiB
| text/x-python
|
PythonLexer
Martin Bornhold
|
r564 | # -*- 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 mock | ||||
Martin Bornhold
|
r1021 | import pytest | ||
Martin Bornhold
|
r564 | import re | ||
from pyramid import testing | ||||
Martin Bornhold
|
r1021 | from rhodecode.svn_support import utils | ||
Martin Bornhold
|
r564 | |||
class TestModDavSvnConfig(object): | ||||
Martin Bornhold
|
r862 | |||
Martin Bornhold
|
r564 | @classmethod | ||
def setup_class(cls): | ||||
# Make mako renderer available in tests. | ||||
config = testing.setUp() | ||||
config.include('pyramid_mako') | ||||
Martin Bornhold
|
r862 | cls.location_root = u'/location/root/çµäö' | ||
cls.parent_path_root = u'/parent/path/çµäö' | ||||
Martin Bornhold
|
r1021 | cls.realm = u'Dummy Realm (äöüçµ)' | ||
Martin Bornhold
|
r564 | |||
@classmethod | ||||
Martin Bornhold
|
r1021 | def get_repo_group_mocks(cls, count=1): | ||
Martin Bornhold
|
r564 | repo_groups = [] | ||
for num in range(0, count): | ||||
Martin Bornhold
|
r862 | full_path = u'/path/to/RepöGröúp-°µ {}'.format(num) | ||
Martin Bornhold
|
r564 | repo_group_mock = mock.MagicMock() | ||
Martin Bornhold
|
r572 | repo_group_mock.full_path = full_path | ||
repo_group_mock.full_path_splitted = full_path.split('/') | ||||
Martin Bornhold
|
r564 | repo_groups.append(repo_group_mock) | ||
return repo_groups | ||||
Martin Bornhold
|
r572 | def assert_root_location_directive(self, config): | ||
Martin Bornhold
|
r862 | pattern = u'<Location "{location}">'.format( | ||
location=self.location_root) | ||||
Martin Bornhold
|
r572 | assert len(re.findall(pattern, config)) == 1 | ||
def assert_group_location_directive(self, config, group_path): | ||||
Martin Bornhold
|
r862 | pattern = u'<Location "{location}{group_path}">'.format( | ||
Martin Bornhold
|
r572 | location=self.location_root, group_path=group_path) | ||
assert len(re.findall(pattern, config)) == 1 | ||||
Martin Bornhold
|
r1021 | 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 | ||||
) | ||||
Martin Bornhold
|
r572 | # Assert that one location directive exists for each repository group. | ||
Martin Bornhold
|
r1021 | for group in repo_groups: | ||
self.assert_group_location_directive( | ||||
generated_config, group.full_path) | ||||
Martin Bornhold
|
r564 | |||
Martin Bornhold
|
r572 | # Assert that the root location directive exists. | ||
Martin Bornhold
|
r1021 | self.assert_root_location_directive(generated_config) | ||
Martin Bornhold
|
r564 | |||
Martin Bornhold
|
r1021 | @pytest.mark.parametrize('list_parent_path', [True, False]) | ||
def test_list_parent_path(self, list_parent_path): | ||||
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 | ||||
) | ||||
Martin Bornhold
|
r564 | |||
Martin Bornhold
|
r1021 | # Assert that correct configuration directive is present. | ||
if list_parent_path: | ||||
assert not re.search('SVNListParentPath\s+Off', generated_config) | ||||
assert re.search('SVNListParentPath\s+On', generated_config) | ||||
else: | ||||
assert re.search('SVNListParentPath\s+Off', generated_config) | ||||
assert not re.search('SVNListParentPath\s+On', generated_config) | ||||