Show More
@@ -19,15 +19,13 b'' | |||
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | |
|
22 | import codecs | |
|
23 | 22 | import mock |
|
23 | import pytest | |
|
24 | 24 | import re |
|
25 | import shutil | |
|
26 | import tempfile | |
|
27 | 25 | |
|
28 | 26 | from pyramid import testing |
|
29 | 27 | |
|
30 |
from rhodecode.svn_support import |
|
|
28 | from rhodecode.svn_support import utils | |
|
31 | 29 | |
|
32 | 30 | |
|
33 | 31 | class TestModDavSvnConfig(object): |
@@ -38,30 +36,12 b' class TestModDavSvnConfig(object):' | |||
|
38 | 36 | config = testing.setUp() |
|
39 | 37 | config.include('pyramid_mako') |
|
40 | 38 | |
|
41 | # Temporary directory holding the generated config files. | |
|
42 | cls.tempdir = tempfile.mkdtemp(suffix='pytest-mod-dav-svn') | |
|
43 | ||
|
44 | 39 | cls.location_root = u'/location/root/çµäö' |
|
45 | 40 | cls.parent_path_root = u'/parent/path/çµäö' |
|
46 |
cls. |
|
|
41 | cls.realm = u'Dummy Realm (äöüçµ)' | |
|
47 | 42 | |
|
48 | 43 | @classmethod |
|
49 | def teardown_class(cls): | |
|
50 | testing.tearDown() | |
|
51 | shutil.rmtree(cls.tempdir, ignore_errors=True) | |
|
52 | ||
|
53 | @classmethod | |
|
54 | def get_settings(cls): | |
|
55 | config_file_path = tempfile.mkstemp( | |
|
56 | suffix='mod-dav-svn.conf', dir=cls.tempdir)[1] | |
|
57 | return { | |
|
58 | config_keys.config_file_path: config_file_path, | |
|
59 | config_keys.location_root: cls.location_root, | |
|
60 | config_keys.list_parent_path: True, | |
|
61 | } | |
|
62 | ||
|
63 | @classmethod | |
|
64 | def get_repo_groups(cls, count=1): | |
|
44 | def get_repo_group_mocks(cls, count=1): | |
|
65 | 45 | repo_groups = [] |
|
66 | 46 | for num in range(0, count): |
|
67 | 47 | full_path = u'/path/to/RepöGröúp-°µ {}'.format(num) |
@@ -81,71 +61,37 b' class TestModDavSvnConfig(object):' | |||
|
81 | 61 | location=self.location_root, group_path=group_path) |
|
82 | 62 | assert len(re.findall(pattern, config)) == 1 |
|
83 | 63 | |
|
84 | @mock.patch('rhodecode.svn_support.utils.get_rhodecode_realm') | |
|
85 | @mock.patch('rhodecode.svn_support.utils.RepoGroup') | |
|
86 | def test_generate_mod_dav_svn_config(self, RepoGroupMock, GetRealmMock): | |
|
87 | # Setup mock objects. | |
|
88 | GetRealmMock.return_value = self._dummy_realm | |
|
89 | num_groups = 3 | |
|
90 | RepoGroupMock.get_all_repo_groups.return_value = self.get_repo_groups( | |
|
91 | count=num_groups) | |
|
92 | ||
|
93 | # Execute the method under test. | |
|
94 | settings = self.get_settings() | |
|
95 | utils.generate_mod_dav_svn_config( | |
|
96 | settings=settings, parent_path_root=self.parent_path_root) | |
|
97 | ||
|
98 | # Read generated file. | |
|
99 | path = settings[config_keys.config_file_path] | |
|
100 | with codecs.open(path, 'r', encoding='utf-8') as f: | |
|
101 | content = f.read() | |
|
102 | ||
|
64 | def test_render_mod_dav_svn_config(self): | |
|
65 | repo_groups = self.get_repo_group_mocks(count=10) | |
|
66 | generated_config = utils._render_mod_dav_svn_config( | |
|
67 | parent_path_root=self.parent_path_root, | |
|
68 | list_parent_path=True, | |
|
69 | location_root=self.location_root, | |
|
70 | repo_groups=repo_groups, | |
|
71 | realm=self.realm | |
|
72 | ) | |
|
103 | 73 | # Assert that one location directive exists for each repository group. |
|
104 |
for group in |
|
|
105 |
self.assert_group_location_directive( |
|
|
74 | for group in repo_groups: | |
|
75 | self.assert_group_location_directive( | |
|
76 | generated_config, group.full_path) | |
|
106 | 77 | |
|
107 | 78 | # Assert that the root location directive exists. |
|
108 |
self.assert_root_location_directive( |
|
|
109 | ||
|
110 | @mock.patch('rhodecode.svn_support.utils.get_rhodecode_realm') | |
|
111 | @mock.patch('rhodecode.svn_support.utils.RepoGroup') | |
|
112 | def test_list_parent_path_on(self, RepoGroupMock, GetRealmMock): | |
|
113 | # Setup mock objects. | |
|
114 | GetRealmMock.return_value = self._dummy_realm | |
|
115 | RepoGroupMock.get_all_repo_groups.return_value = self.get_repo_groups() | |
|
116 | ||
|
117 | # Execute the method under test. | |
|
118 | settings = self.get_settings() | |
|
119 | settings[config_keys.list_parent_path] = True | |
|
120 | utils.generate_mod_dav_svn_config( | |
|
121 | settings=settings, parent_path_root=self.parent_path_root) | |
|
122 | ||
|
123 | # Read generated file. | |
|
124 | path = settings[config_keys.config_file_path] | |
|
125 | with codecs.open(path, 'r', encoding='utf-8') as f: | |
|
126 | content = f.read() | |
|
79 | self.assert_root_location_directive(generated_config) | |
|
127 | 80 | |
|
128 | # Make assertions. | |
|
129 | assert not re.search('SVNListParentPath\s+Off', content) | |
|
130 | assert re.search('SVNListParentPath\s+On', content) | |
|
131 | ||
|
132 | @mock.patch('rhodecode.svn_support.utils.get_rhodecode_realm') | |
|
133 | @mock.patch('rhodecode.svn_support.utils.RepoGroup') | |
|
134 | def test_list_parent_path_off(self, RepoGroupMock, GetRealmMock): | |
|
135 | # Setup mock objects. | |
|
136 | GetRealmMock.return_value = self._dummy_realm | |
|
137 | RepoGroupMock.get_all_repo_groups.return_value = self.get_repo_groups() | |
|
81 | @pytest.mark.parametrize('list_parent_path', [True, False]) | |
|
82 | def test_list_parent_path(self, list_parent_path): | |
|
83 | generated_config = utils._render_mod_dav_svn_config( | |
|
84 | parent_path_root=self.parent_path_root, | |
|
85 | list_parent_path=list_parent_path, | |
|
86 | location_root=self.location_root, | |
|
87 | repo_groups=self.get_repo_group_mocks(count=10), | |
|
88 | realm=self.realm | |
|
89 | ) | |
|
138 | 90 | |
|
139 | # Execute the method under test. | |
|
140 | settings = self.get_settings() | |
|
141 | settings[config_keys.list_parent_path] = False | |
|
142 | utils.generate_mod_dav_svn_config( | |
|
143 | settings=settings, parent_path_root=self.parent_path_root) | |
|
144 | ||
|
145 | # Read generated file. | |
|
146 | with open(settings[config_keys.config_file_path], 'r') as file_: | |
|
147 | content = file_.read() | |
|
148 | ||
|
149 | # Make assertions. | |
|
150 | assert re.search('SVNListParentPath\s+Off', content) | |
|
151 | assert not re.search('SVNListParentPath\s+On', content) | |
|
91 | # Assert that correct configuration directive is present. | |
|
92 | if list_parent_path: | |
|
93 | assert not re.search('SVNListParentPath\s+Off', generated_config) | |
|
94 | assert re.search('SVNListParentPath\s+On', generated_config) | |
|
95 | else: | |
|
96 | assert re.search('SVNListParentPath\s+Off', generated_config) | |
|
97 | assert not re.search('SVNListParentPath\s+On', generated_config) |
@@ -46,7 +46,8 b' def generate_mod_dav_svn_config(registry' | |||
|
46 | 46 | parent_path_root=get_rhodecode_base_path(), |
|
47 | 47 | list_parent_path=settings[config_keys.list_parent_path], |
|
48 | 48 | location_root=settings[config_keys.location_root], |
|
49 |
repo_groups=RepoGroup.get_all_repo_groups() |
|
|
49 | repo_groups=RepoGroup.get_all_repo_groups(), | |
|
50 | realm=get_rhodecode_realm()) | |
|
50 | 51 | _write_mod_dav_svn_config(config, settings[config_keys.config_file_path]) |
|
51 | 52 | |
|
52 | 53 | # Trigger an event on mod dav svn configuration change. |
@@ -54,7 +55,7 b' def generate_mod_dav_svn_config(registry' | |||
|
54 | 55 | |
|
55 | 56 | |
|
56 | 57 | def _render_mod_dav_svn_config( |
|
57 | parent_path_root, list_parent_path, location_root, repo_groups): | |
|
58 | parent_path_root, list_parent_path, location_root, repo_groups, realm): | |
|
58 | 59 | """ |
|
59 | 60 | Render mod_dav_svn configuration to string. |
|
60 | 61 | """ |
@@ -70,7 +71,7 b' def _render_mod_dav_svn_config(' | |||
|
70 | 71 | 'parent_path_root': parent_path_root, |
|
71 | 72 | 'repo_group_paths': repo_group_paths, |
|
72 | 73 | 'svn_list_parent_path': list_parent_path, |
|
73 |
'rhodecode_realm': |
|
|
74 | 'rhodecode_realm': realm, | |
|
74 | 75 | } |
|
75 | 76 | |
|
76 | 77 | # Render the configuration template to string. |
General Comments 0
You need to be logged in to leave comments.
Login now