diff --git a/rhodecode/svn_support/tests/test_mod_dav_svn_config.py b/rhodecode/svn_support/tests/test_mod_dav_svn_config.py --- a/rhodecode/svn_support/tests/test_mod_dav_svn_config.py +++ b/rhodecode/svn_support/tests/test_mod_dav_svn_config.py @@ -26,8 +26,7 @@ import tempfile from pyramid import testing -from rhodecode.svn_support import config_keys -from rhodecode.svn_support.utils import generate_mod_dav_svn_config +from rhodecode.svn_support import config_keys, utils class TestModDavSvnConfig(object): @@ -40,15 +39,8 @@ class TestModDavSvnConfig(object): # Temporary directory holding the generated config files. cls.tempdir = tempfile.mkdtemp(suffix='pytest-mod-dav-svn') - # Regex pattern to match a location block in the generated config. - cls.location_regex = ( - '\s+' - 'DAV svn\s+' - 'SVNParentPath {svn_parent_path}\s+' - 'SVNListParentPath {svn_list_parent_path}\s+' - 'Allow from all\s+' - 'Order allow,deny\s+' - '') + cls.location_root = '/location/root' + cls.parent_path_root = '/parent/path/root' @classmethod def teardown_class(cls): @@ -61,8 +53,8 @@ class TestModDavSvnConfig(object): suffix='mod-dav-svn.conf', dir=cls.tempdir)[1] return { config_keys.config_file_path: config_file_path, - config_keys.location_root: '/location/root/', - config_keys.parent_path_root: '/parent/path/root/', + config_keys.location_root: cls.location_root, + config_keys.parent_path_root: cls.parent_path_root, config_keys.list_parent_path: True, } @@ -70,11 +62,22 @@ class TestModDavSvnConfig(object): def get_repo_groups(cls, count=1): repo_groups = [] for num in range(0, count): + full_path = '/path/to/RepoGroup{}'.format(num) repo_group_mock = mock.MagicMock() - repo_group_mock.full_path = '/path/to/RepoGroup{}'.format(num) + 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): + pattern = ''.format(location=self.location_root) + assert len(re.findall(pattern, config)) == 1 + + def assert_group_location_directive(self, config, group_path): + pattern = ''.format( + location=self.location_root, group_path=group_path) + assert len(re.findall(pattern, config)) == 1 + @mock.patch('rhodecode.svn_support.utils.RepoGroup') def test_generate_mod_dav_svn_config(self, RepoGroupMock): num_groups = 3 @@ -83,25 +86,18 @@ class TestModDavSvnConfig(object): # Execute the method under test. settings = self.get_settings() - generate_mod_dav_svn_config(settings) + utils.generate_mod_dav_svn_config(settings) # Read generated file. with open(settings[config_keys.config_file_path], 'r') as file_: content = file_.read() - # Assert that one location block exists for each repository group. - repo_group_pattern = self.location_regex.format( - location='/location/root/path/to/RepoGroup\d+', - svn_parent_path='/parent/path/root/path/to/RepoGroup\d+', - svn_list_parent_path='On') - assert len(re.findall(repo_group_pattern, content)) == num_groups + # 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) - # Assert that the root location block exists. - root_pattern = self.location_regex.format( - location='/location/root/', - svn_parent_path='/parent/path/root/', - svn_list_parent_path='On') - assert len(re.findall(root_pattern, content)) == 1 + # Assert that the root location directive exists. + self.assert_root_location_directive(content) @mock.patch('rhodecode.svn_support.utils.RepoGroup') def test_list_parent_path_on(self, RepoGroupMock): @@ -110,7 +106,7 @@ class TestModDavSvnConfig(object): # Execute the method under test. settings = self.get_settings() settings[config_keys.list_parent_path] = True - generate_mod_dav_svn_config(settings) + utils.generate_mod_dav_svn_config(settings) # Read generated file. with open(settings[config_keys.config_file_path], 'r') as file_: @@ -127,7 +123,7 @@ class TestModDavSvnConfig(object): # Execute the method under test. settings = self.get_settings() settings[config_keys.list_parent_path] = False - generate_mod_dav_svn_config(settings) + utils.generate_mod_dav_svn_config(settings) # Read generated file. with open(settings[config_keys.config_file_path], 'r') as file_: @@ -136,3 +132,15 @@ class TestModDavSvnConfig(object): # Make assertions. assert re.search('SVNListParentPath\s+Off', content) assert not re.search('SVNListParentPath\s+On', content) + + @mock.patch('rhodecode.svn_support.utils.log') + def test_write_does_not_raise_on_error(self, LogMock): + """ + Writing the configuration to file should never raise exceptions. + If e.g. path points to a place without write permissions. + """ + utils._write_mod_dav_svn_config( + 'content', '/dev/null/not/existing/path') + + # Assert that we log the exception. + assert LogMock.exception.called