##// END OF EJS Templates
svn: Add test to check the config file generation.
Martin Bornhold -
r564:808cf264 default
parent child Browse files
Show More
@@ -0,0 +1,138 b''
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2016-2016 RhodeCode GmbH
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
21
22 import mock
23 import re
24 import shutil
25 import tempfile
26
27 from pyramid import testing
28
29 from rhodecode.svn_support import keys
30 from rhodecode.svn_support.utils import generate_mod_dav_svn_config
31
32
33 class TestModDavSvnConfig(object):
34 @classmethod
35 def setup_class(cls):
36 # Make mako renderer available in tests.
37 config = testing.setUp()
38 config.include('pyramid_mako')
39
40 # Temporary directory holding the generated config files.
41 cls.tempdir = tempfile.mkdtemp(suffix='pytest-mod-dav-svn')
42
43 # Regex pattern to match a location block in the generated config.
44 cls.location_regex = (
45 '<Location {location}>\s+'
46 'DAV svn\s+'
47 'SVNParentPath {svn_parent_path}\s+'
48 'SVNListParentPath {svn_list_parent_path}\s+'
49 'Allow from all\s+'
50 'Order allow,deny\s+'
51 '</Location>')
52
53 @classmethod
54 def teardown_class(cls):
55 testing.tearDown()
56 shutil.rmtree(cls.tempdir, ignore_errors=True)
57
58 @classmethod
59 def get_settings(cls):
60 config_file_path = tempfile.mkstemp(
61 suffix='mod-dav-svn.conf', dir=cls.tempdir)[1]
62 return {
63 keys.config_file_path: config_file_path,
64 keys.location_root: '/location/root/',
65 keys.parent_path_root: '/parent/path/root/',
66 keys.list_parent_path: True,
67 }
68
69 @classmethod
70 def get_repo_groups(cls, count=1):
71 repo_groups = []
72 for num in range(0, count):
73 repo_group_mock = mock.MagicMock()
74 repo_group_mock.full_path = '/path/to/RepoGroup{}'.format(num)
75 repo_groups.append(repo_group_mock)
76 return repo_groups
77
78 @mock.patch('rhodecode.svn_support.utils.RepoGroup')
79 def test_generate_mod_dav_svn_config(self, RepoGroupMock):
80 num_groups = 3
81 RepoGroupMock.get_all_repo_groups.return_value = self.get_repo_groups(
82 count=num_groups)
83
84 # Execute the method under test.
85 settings = self.get_settings()
86 generate_mod_dav_svn_config(settings)
87
88 # Read generated file.
89 with open(settings[keys.config_file_path], 'r') as file_:
90 content = file_.read()
91
92 # Assert that one location block exists for each repository group.
93 repo_group_pattern = self.location_regex.format(
94 location='/location/root/path/to/RepoGroup\d+',
95 svn_parent_path='/parent/path/root/path/to/RepoGroup\d+',
96 svn_list_parent_path='On')
97 assert len(re.findall(repo_group_pattern, content)) == num_groups
98
99 # Assert that the root location block exists.
100 root_pattern = self.location_regex.format(
101 location='/location/root/',
102 svn_parent_path='/parent/path/root/',
103 svn_list_parent_path='On')
104 assert len(re.findall(root_pattern, content)) == 1
105
106 @mock.patch('rhodecode.svn_support.utils.RepoGroup')
107 def test_list_parent_path_on(self, RepoGroupMock):
108 RepoGroupMock.get_all_repo_groups.return_value = self.get_repo_groups()
109
110 # Execute the method under test.
111 settings = self.get_settings()
112 settings[keys.list_parent_path] = True
113 generate_mod_dav_svn_config(settings)
114
115 # Read generated file.
116 with open(settings[keys.config_file_path], 'r') as file_:
117 content = file_.read()
118
119 # Make assertions.
120 assert not re.search('SVNListParentPath\s+Off', content)
121 assert re.search('SVNListParentPath\s+On', content)
122
123 @mock.patch('rhodecode.svn_support.utils.RepoGroup')
124 def test_list_parent_path_off(self, RepoGroupMock):
125 RepoGroupMock.get_all_repo_groups.return_value = self.get_repo_groups()
126
127 # Execute the method under test.
128 settings = self.get_settings()
129 settings[keys.list_parent_path] = False
130 generate_mod_dav_svn_config(settings)
131
132 # Read generated file.
133 with open(settings[keys.config_file_path], 'r') as file_:
134 content = file_.read()
135
136 # Make assertions.
137 assert re.search('SVNListParentPath\s+Off', content)
138 assert not re.search('SVNListParentPath\s+On', content)
General Comments 0
You need to be logged in to leave comments. Login now