##// END OF EJS Templates
svn: Adapt tests to recent changes in implementation.
Martin Bornhold -
r572:a3054906 default
parent child Browse files
Show More
@@ -26,8 +26,7 b' import tempfile'
26
26
27 from pyramid import testing
27 from pyramid import testing
28
28
29 from rhodecode.svn_support import config_keys
29 from rhodecode.svn_support import config_keys, utils
30 from rhodecode.svn_support.utils import generate_mod_dav_svn_config
31
30
32
31
33 class TestModDavSvnConfig(object):
32 class TestModDavSvnConfig(object):
@@ -40,15 +39,8 b' class TestModDavSvnConfig(object):'
40 # Temporary directory holding the generated config files.
39 # Temporary directory holding the generated config files.
41 cls.tempdir = tempfile.mkdtemp(suffix='pytest-mod-dav-svn')
40 cls.tempdir = tempfile.mkdtemp(suffix='pytest-mod-dav-svn')
42
41
43 # Regex pattern to match a location block in the generated config.
42 cls.location_root = '/location/root'
44 cls.location_regex = (
43 cls.parent_path_root = '/parent/path/root'
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
44
53 @classmethod
45 @classmethod
54 def teardown_class(cls):
46 def teardown_class(cls):
@@ -61,8 +53,8 b' class TestModDavSvnConfig(object):'
61 suffix='mod-dav-svn.conf', dir=cls.tempdir)[1]
53 suffix='mod-dav-svn.conf', dir=cls.tempdir)[1]
62 return {
54 return {
63 config_keys.config_file_path: config_file_path,
55 config_keys.config_file_path: config_file_path,
64 config_keys.location_root: '/location/root/',
56 config_keys.location_root: cls.location_root,
65 config_keys.parent_path_root: '/parent/path/root/',
57 config_keys.parent_path_root: cls.parent_path_root,
66 config_keys.list_parent_path: True,
58 config_keys.list_parent_path: True,
67 }
59 }
68
60
@@ -70,11 +62,22 b' class TestModDavSvnConfig(object):'
70 def get_repo_groups(cls, count=1):
62 def get_repo_groups(cls, count=1):
71 repo_groups = []
63 repo_groups = []
72 for num in range(0, count):
64 for num in range(0, count):
65 full_path = '/path/to/RepoGroup{}'.format(num)
73 repo_group_mock = mock.MagicMock()
66 repo_group_mock = mock.MagicMock()
74 repo_group_mock.full_path = '/path/to/RepoGroup{}'.format(num)
67 repo_group_mock.full_path = full_path
68 repo_group_mock.full_path_splitted = full_path.split('/')
75 repo_groups.append(repo_group_mock)
69 repo_groups.append(repo_group_mock)
76 return repo_groups
70 return repo_groups
77
71
72 def assert_root_location_directive(self, config):
73 pattern = '<Location {location}>'.format(location=self.location_root)
74 assert len(re.findall(pattern, config)) == 1
75
76 def assert_group_location_directive(self, config, group_path):
77 pattern = '<Location {location}{group_path}>'.format(
78 location=self.location_root, group_path=group_path)
79 assert len(re.findall(pattern, config)) == 1
80
78 @mock.patch('rhodecode.svn_support.utils.RepoGroup')
81 @mock.patch('rhodecode.svn_support.utils.RepoGroup')
79 def test_generate_mod_dav_svn_config(self, RepoGroupMock):
82 def test_generate_mod_dav_svn_config(self, RepoGroupMock):
80 num_groups = 3
83 num_groups = 3
@@ -83,25 +86,18 b' class TestModDavSvnConfig(object):'
83
86
84 # Execute the method under test.
87 # Execute the method under test.
85 settings = self.get_settings()
88 settings = self.get_settings()
86 generate_mod_dav_svn_config(settings)
89 utils.generate_mod_dav_svn_config(settings)
87
90
88 # Read generated file.
91 # Read generated file.
89 with open(settings[config_keys.config_file_path], 'r') as file_:
92 with open(settings[config_keys.config_file_path], 'r') as file_:
90 content = file_.read()
93 content = file_.read()
91
94
92 # Assert that one location block exists for each repository group.
95 # Assert that one location directive exists for each repository group.
93 repo_group_pattern = self.location_regex.format(
96 for group in self.get_repo_groups(count=num_groups):
94 location='/location/root/path/to/RepoGroup\d+',
97 self.assert_group_location_directive(content, group.full_path)
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
98
99 # Assert that the root location block exists.
99 # Assert that the root location directive exists.
100 root_pattern = self.location_regex.format(
100 self.assert_root_location_directive(content)
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
101
106 @mock.patch('rhodecode.svn_support.utils.RepoGroup')
102 @mock.patch('rhodecode.svn_support.utils.RepoGroup')
107 def test_list_parent_path_on(self, RepoGroupMock):
103 def test_list_parent_path_on(self, RepoGroupMock):
@@ -110,7 +106,7 b' class TestModDavSvnConfig(object):'
110 # Execute the method under test.
106 # Execute the method under test.
111 settings = self.get_settings()
107 settings = self.get_settings()
112 settings[config_keys.list_parent_path] = True
108 settings[config_keys.list_parent_path] = True
113 generate_mod_dav_svn_config(settings)
109 utils.generate_mod_dav_svn_config(settings)
114
110
115 # Read generated file.
111 # Read generated file.
116 with open(settings[config_keys.config_file_path], 'r') as file_:
112 with open(settings[config_keys.config_file_path], 'r') as file_:
@@ -127,7 +123,7 b' class TestModDavSvnConfig(object):'
127 # Execute the method under test.
123 # Execute the method under test.
128 settings = self.get_settings()
124 settings = self.get_settings()
129 settings[config_keys.list_parent_path] = False
125 settings[config_keys.list_parent_path] = False
130 generate_mod_dav_svn_config(settings)
126 utils.generate_mod_dav_svn_config(settings)
131
127
132 # Read generated file.
128 # Read generated file.
133 with open(settings[config_keys.config_file_path], 'r') as file_:
129 with open(settings[config_keys.config_file_path], 'r') as file_:
@@ -136,3 +132,15 b' class TestModDavSvnConfig(object):'
136 # Make assertions.
132 # Make assertions.
137 assert re.search('SVNListParentPath\s+Off', content)
133 assert re.search('SVNListParentPath\s+Off', content)
138 assert not re.search('SVNListParentPath\s+On', content)
134 assert not re.search('SVNListParentPath\s+On', content)
135
136 @mock.patch('rhodecode.svn_support.utils.log')
137 def test_write_does_not_raise_on_error(self, LogMock):
138 """
139 Writing the configuration to file should never raise exceptions.
140 If e.g. path points to a place without write permissions.
141 """
142 utils._write_mod_dav_svn_config(
143 'content', '/dev/null/not/existing/path')
144
145 # Assert that we log the exception.
146 assert LogMock.exception.called
General Comments 0
You need to be logged in to leave comments. Login now