##// END OF EJS Templates
svn-support: Fix tests for subversion support....
Martin Bornhold -
r1021:d36782c6 default
parent child Browse files
Show More
@@ -19,15 +19,13 b''
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21
21
22 import codecs
23 import mock
22 import mock
23 import pytest
24 import re
24 import re
25 import shutil
26 import tempfile
27
25
28 from pyramid import testing
26 from pyramid import testing
29
27
30 from rhodecode.svn_support import config_keys, utils
28 from rhodecode.svn_support import utils
31
29
32
30
33 class TestModDavSvnConfig(object):
31 class TestModDavSvnConfig(object):
@@ -38,30 +36,12 b' class TestModDavSvnConfig(object):'
38 config = testing.setUp()
36 config = testing.setUp()
39 config.include('pyramid_mako')
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 cls.location_root = u'/location/root/çµäö'
39 cls.location_root = u'/location/root/çµäö'
45 cls.parent_path_root = u'/parent/path/çµäö'
40 cls.parent_path_root = u'/parent/path/çµäö'
46 cls._dummy_realm = u'Dummy Realm (äöüçµ)'
41 cls.realm = u'Dummy Realm (äöüçµ)'
47
42
48 @classmethod
43 @classmethod
49 def teardown_class(cls):
44 def get_repo_group_mocks(cls, count=1):
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):
65 repo_groups = []
45 repo_groups = []
66 for num in range(0, count):
46 for num in range(0, count):
67 full_path = u'/path/to/RepöGröúp-°µ {}'.format(num)
47 full_path = u'/path/to/RepöGröúp-°µ {}'.format(num)
@@ -81,71 +61,37 b' class TestModDavSvnConfig(object):'
81 location=self.location_root, group_path=group_path)
61 location=self.location_root, group_path=group_path)
82 assert len(re.findall(pattern, config)) == 1
62 assert len(re.findall(pattern, config)) == 1
83
63
84 @mock.patch('rhodecode.svn_support.utils.get_rhodecode_realm')
64 def test_render_mod_dav_svn_config(self):
85 @mock.patch('rhodecode.svn_support.utils.RepoGroup')
65 repo_groups = self.get_repo_group_mocks(count=10)
86 def test_generate_mod_dav_svn_config(self, RepoGroupMock, GetRealmMock):
66 generated_config = utils._render_mod_dav_svn_config(
87 # Setup mock objects.
67 parent_path_root=self.parent_path_root,
88 GetRealmMock.return_value = self._dummy_realm
68 list_parent_path=True,
89 num_groups = 3
69 location_root=self.location_root,
90 RepoGroupMock.get_all_repo_groups.return_value = self.get_repo_groups(
70 repo_groups=repo_groups,
91 count=num_groups)
71 realm=self.realm
92
72 )
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
103 # Assert that one location directive exists for each repository group.
73 # Assert that one location directive exists for each repository group.
104 for group in self.get_repo_groups(count=num_groups):
74 for group in repo_groups:
105 self.assert_group_location_directive(content, group.full_path)
75 self.assert_group_location_directive(
76 generated_config, group.full_path)
106
77
107 # Assert that the root location directive exists.
78 # Assert that the root location directive exists.
108 self.assert_root_location_directive(content)
79 self.assert_root_location_directive(generated_config)
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()
127
80
128 # Make assertions.
81 @pytest.mark.parametrize('list_parent_path', [True, False])
129 assert not re.search('SVNListParentPath\s+Off', content)
82 def test_list_parent_path(self, list_parent_path):
130 assert re.search('SVNListParentPath\s+On', content)
83 generated_config = utils._render_mod_dav_svn_config(
131
84 parent_path_root=self.parent_path_root,
132 @mock.patch('rhodecode.svn_support.utils.get_rhodecode_realm')
85 list_parent_path=list_parent_path,
133 @mock.patch('rhodecode.svn_support.utils.RepoGroup')
86 location_root=self.location_root,
134 def test_list_parent_path_off(self, RepoGroupMock, GetRealmMock):
87 repo_groups=self.get_repo_group_mocks(count=10),
135 # Setup mock objects.
88 realm=self.realm
136 GetRealmMock.return_value = self._dummy_realm
89 )
137 RepoGroupMock.get_all_repo_groups.return_value = self.get_repo_groups()
138
90
139 # Execute the method under test.
91 # Assert that correct configuration directive is present.
140 settings = self.get_settings()
92 if list_parent_path:
141 settings[config_keys.list_parent_path] = False
93 assert not re.search('SVNListParentPath\s+Off', generated_config)
142 utils.generate_mod_dav_svn_config(
94 assert re.search('SVNListParentPath\s+On', generated_config)
143 settings=settings, parent_path_root=self.parent_path_root)
95 else:
144
96 assert re.search('SVNListParentPath\s+Off', generated_config)
145 # Read generated file.
97 assert not re.search('SVNListParentPath\s+On', generated_config)
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)
@@ -46,7 +46,8 b' def generate_mod_dav_svn_config(registry'
46 parent_path_root=get_rhodecode_base_path(),
46 parent_path_root=get_rhodecode_base_path(),
47 list_parent_path=settings[config_keys.list_parent_path],
47 list_parent_path=settings[config_keys.list_parent_path],
48 location_root=settings[config_keys.location_root],
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 _write_mod_dav_svn_config(config, settings[config_keys.config_file_path])
51 _write_mod_dav_svn_config(config, settings[config_keys.config_file_path])
51
52
52 # Trigger an event on mod dav svn configuration change.
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 def _render_mod_dav_svn_config(
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 Render mod_dav_svn configuration to string.
60 Render mod_dav_svn configuration to string.
60 """
61 """
@@ -70,7 +71,7 b' def _render_mod_dav_svn_config('
70 'parent_path_root': parent_path_root,
71 'parent_path_root': parent_path_root,
71 'repo_group_paths': repo_group_paths,
72 'repo_group_paths': repo_group_paths,
72 'svn_list_parent_path': list_parent_path,
73 'svn_list_parent_path': list_parent_path,
73 'rhodecode_realm': get_rhodecode_realm(),
74 'rhodecode_realm': realm,
74 }
75 }
75
76
76 # Render the configuration template to string.
77 # Render the configuration template to string.
General Comments 0
You need to be logged in to leave comments. Login now