##// END OF EJS Templates
docs: added infor about flash message suppressing.
docs: added infor about flash message suppressing.

File last commit:

r868:2073cad3 merge default
r988:f7d4acaa default
Show More
test_mod_dav_svn_config.py
151 lines | 5.7 KiB | text/x-python | PythonLexer
/ rhodecode / svn_support / tests / test_mod_dav_svn_config.py
Martin Bornhold
svn: Add test to check the config file generation.
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/
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 import codecs
Martin Bornhold
svn: Add test to check the config file generation.
r564 import mock
import re
import shutil
import tempfile
from pyramid import testing
Martin Bornhold
svn: Adapt tests to recent changes in implementation.
r572 from rhodecode.svn_support import config_keys, utils
Martin Bornhold
svn: Add test to check the config file generation.
r564
class TestModDavSvnConfig(object):
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862
Martin Bornhold
svn: Add test to check the config file generation.
r564 @classmethod
def setup_class(cls):
# Make mako renderer available in tests.
config = testing.setUp()
config.include('pyramid_mako')
# Temporary directory holding the generated config files.
cls.tempdir = tempfile.mkdtemp(suffix='pytest-mod-dav-svn')
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 cls.location_root = u'/location/root/çµäö'
cls.parent_path_root = u'/parent/path/çµäö'
cls._dummy_realm = u'Dummy Realm (äöüçµ)'
Martin Bornhold
svn: Add test to check the config file generation.
r564
@classmethod
def teardown_class(cls):
testing.tearDown()
shutil.rmtree(cls.tempdir, ignore_errors=True)
@classmethod
def get_settings(cls):
config_file_path = tempfile.mkstemp(
suffix='mod-dav-svn.conf', dir=cls.tempdir)[1]
return {
Martin Bornhold
svn: Rename keys.py to config_keys.py
r567 config_keys.config_file_path: config_file_path,
Martin Bornhold
svn: Adapt tests to recent changes in implementation.
r572 config_keys.location_root: cls.location_root,
Martin Bornhold
svn: Rename keys.py to config_keys.py
r567 config_keys.list_parent_path: True,
Martin Bornhold
svn: Add test to check the config file generation.
r564 }
@classmethod
def get_repo_groups(cls, count=1):
repo_groups = []
for num in range(0, count):
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 full_path = u'/path/to/RepöGröúp-°µ {}'.format(num)
Martin Bornhold
svn: Add test to check the config file generation.
r564 repo_group_mock = mock.MagicMock()
Martin Bornhold
svn: Adapt tests to recent changes in implementation.
r572 repo_group_mock.full_path = full_path
repo_group_mock.full_path_splitted = full_path.split('/')
Martin Bornhold
svn: Add test to check the config file generation.
r564 repo_groups.append(repo_group_mock)
return repo_groups
Martin Bornhold
svn: Adapt tests to recent changes in implementation.
r572 def assert_root_location_directive(self, config):
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 pattern = u'<Location "{location}">'.format(
location=self.location_root)
Martin Bornhold
svn: Adapt tests to recent changes in implementation.
r572 assert len(re.findall(pattern, config)) == 1
def assert_group_location_directive(self, config, group_path):
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 pattern = u'<Location "{location}{group_path}">'.format(
Martin Bornhold
svn: Adapt tests to recent changes in implementation.
r572 location=self.location_root, group_path=group_path)
assert len(re.findall(pattern, config)) == 1
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 @mock.patch('rhodecode.svn_support.utils.get_rhodecode_realm')
Martin Bornhold
svn: Add test to check the config file generation.
r564 @mock.patch('rhodecode.svn_support.utils.RepoGroup')
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 def test_generate_mod_dav_svn_config(self, RepoGroupMock, GetRealmMock):
# Setup mock objects.
GetRealmMock.return_value = self._dummy_realm
Martin Bornhold
svn: Add test to check the config file generation.
r564 num_groups = 3
RepoGroupMock.get_all_repo_groups.return_value = self.get_repo_groups(
count=num_groups)
# Execute the method under test.
settings = self.get_settings()
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 utils.generate_mod_dav_svn_config(
settings=settings, parent_path_root=self.parent_path_root)
Martin Bornhold
svn: Add test to check the config file generation.
r564
# Read generated file.
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 path = settings[config_keys.config_file_path]
with codecs.open(path, 'r', encoding='utf-8') as f:
content = f.read()
Martin Bornhold
svn: Add test to check the config file generation.
r564
Martin Bornhold
svn: Adapt tests to recent changes in implementation.
r572 # Assert that one location directive exists for each repository group.
for group in self.get_repo_groups(count=num_groups):
self.assert_group_location_directive(content, group.full_path)
Martin Bornhold
svn: Add test to check the config file generation.
r564
Martin Bornhold
svn: Adapt tests to recent changes in implementation.
r572 # Assert that the root location directive exists.
self.assert_root_location_directive(content)
Martin Bornhold
svn: Add test to check the config file generation.
r564
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 @mock.patch('rhodecode.svn_support.utils.get_rhodecode_realm')
Martin Bornhold
svn: Add test to check the config file generation.
r564 @mock.patch('rhodecode.svn_support.utils.RepoGroup')
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 def test_list_parent_path_on(self, RepoGroupMock, GetRealmMock):
# Setup mock objects.
GetRealmMock.return_value = self._dummy_realm
Martin Bornhold
svn: Add test to check the config file generation.
r564 RepoGroupMock.get_all_repo_groups.return_value = self.get_repo_groups()
# Execute the method under test.
settings = self.get_settings()
Martin Bornhold
svn: Rename keys.py to config_keys.py
r567 settings[config_keys.list_parent_path] = True
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 utils.generate_mod_dav_svn_config(
settings=settings, parent_path_root=self.parent_path_root)
Martin Bornhold
svn: Add test to check the config file generation.
r564
# Read generated file.
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 path = settings[config_keys.config_file_path]
with codecs.open(path, 'r', encoding='utf-8') as f:
content = f.read()
Martin Bornhold
svn: Add test to check the config file generation.
r564
# Make assertions.
assert not re.search('SVNListParentPath\s+Off', content)
assert re.search('SVNListParentPath\s+On', content)
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 @mock.patch('rhodecode.svn_support.utils.get_rhodecode_realm')
Martin Bornhold
svn: Add test to check the config file generation.
r564 @mock.patch('rhodecode.svn_support.utils.RepoGroup')
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 def test_list_parent_path_off(self, RepoGroupMock, GetRealmMock):
# Setup mock objects.
GetRealmMock.return_value = self._dummy_realm
Martin Bornhold
svn: Add test to check the config file generation.
r564 RepoGroupMock.get_all_repo_groups.return_value = self.get_repo_groups()
# Execute the method under test.
settings = self.get_settings()
Martin Bornhold
svn: Rename keys.py to config_keys.py
r567 settings[config_keys.list_parent_path] = False
Martin Bornhold
tests: Adapt sv_support tests to recent changes....
r862 utils.generate_mod_dav_svn_config(
settings=settings, parent_path_root=self.parent_path_root)
Martin Bornhold
svn: Add test to check the config file generation.
r564
# Read generated file.
Martin Bornhold
svn: Rename keys.py to config_keys.py
r567 with open(settings[config_keys.config_file_path], 'r') as file_:
Martin Bornhold
svn: Add test to check the config file generation.
r564 content = file_.read()
# Make assertions.
assert re.search('SVNListParentPath\s+Off', content)
assert not re.search('SVNListParentPath\s+On', content)