##// END OF EJS Templates
tests: re-use config_stub for svn tests
marcink -
r2312:ff33d555 default
parent child Browse files
Show More
@@ -1,126 +1,121 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2017 RhodeCode GmbH
3 # Copyright (C) 2016-2017 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
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
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
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/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
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 import re
21 import re
22 import os
22 import os
23 import mock
23 import mock
24 import pytest
24 import pytest
25
25
26 from pyramid import testing
27
28 from rhodecode.apps.svn_support import utils
26 from rhodecode.apps.svn_support import utils
29
27
30
28
29 @pytest.mark.usefixtures('config_stub')
31 class TestModDavSvnConfig(object):
30 class TestModDavSvnConfig(object):
32
31
33 @classmethod
32 @classmethod
34 def setup_class(cls):
33 def setup_class(cls):
35 # Make mako renderer available in tests.
36 config = testing.setUp()
37 config.include('pyramid_mako')
38
39 cls.location_root = u'/location/root/ç¡Àâ'
34 cls.location_root = u'/location/root/ç¡Àâ'
40 cls.parent_path_root = u'/parent/path/ç¡Àâ'
35 cls.parent_path_root = u'/parent/path/ç¡Àâ'
41 cls.realm = u'Dummy Realm (Àâüç¡)'
36 cls.realm = u'Dummy Realm (Àâüç¡)'
42
37
43 @classmethod
38 @classmethod
44 def get_repo_group_mocks(cls, count=1):
39 def get_repo_group_mocks(cls, count=1):
45 repo_groups = []
40 repo_groups = []
46 for num in range(0, count):
41 for num in range(0, count):
47 full_path = u'/path/to/RepâGrâúp-°¡ {}'.format(num)
42 full_path = u'/path/to/RepâGrâúp-°¡ {}'.format(num)
48 repo_group_mock = mock.MagicMock()
43 repo_group_mock = mock.MagicMock()
49 repo_group_mock.full_path = full_path
44 repo_group_mock.full_path = full_path
50 repo_group_mock.full_path_splitted = full_path.split('/')
45 repo_group_mock.full_path_splitted = full_path.split('/')
51 repo_groups.append(repo_group_mock)
46 repo_groups.append(repo_group_mock)
52 return repo_groups
47 return repo_groups
53
48
54 def assert_root_location_directive(self, config):
49 def assert_root_location_directive(self, config):
55 pattern = u'<Location "{location}">'.format(
50 pattern = u'<Location "{location}">'.format(
56 location=self.location_root)
51 location=self.location_root)
57 assert len(re.findall(pattern, config)) == 1
52 assert len(re.findall(pattern, config)) == 1
58
53
59 def assert_group_location_directive(self, config, group_path):
54 def assert_group_location_directive(self, config, group_path):
60 pattern = u'<Location "{location}{group_path}">'.format(
55 pattern = u'<Location "{location}{group_path}">'.format(
61 location=self.location_root, group_path=group_path)
56 location=self.location_root, group_path=group_path)
62 assert len(re.findall(pattern, config)) == 1
57 assert len(re.findall(pattern, config)) == 1
63
58
64 def test_render_mod_dav_svn_config(self):
59 def test_render_mod_dav_svn_config(self):
65 repo_groups = self.get_repo_group_mocks(count=10)
60 repo_groups = self.get_repo_group_mocks(count=10)
66 generated_config = utils._render_mod_dav_svn_config(
61 generated_config = utils._render_mod_dav_svn_config(
67 parent_path_root=self.parent_path_root,
62 parent_path_root=self.parent_path_root,
68 list_parent_path=True,
63 list_parent_path=True,
69 location_root=self.location_root,
64 location_root=self.location_root,
70 repo_groups=repo_groups,
65 repo_groups=repo_groups,
71 realm=self.realm,
66 realm=self.realm,
72 use_ssl=True,
67 use_ssl=True,
73 template=''
68 template=''
74 )
69 )
75 # Assert that one location directive exists for each repository group.
70 # Assert that one location directive exists for each repository group.
76 for group in repo_groups:
71 for group in repo_groups:
77 self.assert_group_location_directive(
72 self.assert_group_location_directive(
78 generated_config, group.full_path)
73 generated_config, group.full_path)
79
74
80 # Assert that the root location directive exists.
75 # Assert that the root location directive exists.
81 self.assert_root_location_directive(generated_config)
76 self.assert_root_location_directive(generated_config)
82
77
83 def test_render_mod_dav_svn_config_with_alternative_template(self, tmpdir):
78 def test_render_mod_dav_svn_config_with_alternative_template(self, tmpdir):
84 repo_groups = self.get_repo_group_mocks(count=10)
79 repo_groups = self.get_repo_group_mocks(count=10)
85 test_file_path = os.path.join(str(tmpdir), 'example.mako')
80 test_file_path = os.path.join(str(tmpdir), 'example.mako')
86 with open(test_file_path, 'wb') as f:
81 with open(test_file_path, 'wb') as f:
87 f.write('TEST_EXAMPLE\n')
82 f.write('TEST_EXAMPLE\n')
88
83
89 generated_config = utils._render_mod_dav_svn_config(
84 generated_config = utils._render_mod_dav_svn_config(
90 parent_path_root=self.parent_path_root,
85 parent_path_root=self.parent_path_root,
91 list_parent_path=True,
86 list_parent_path=True,
92 location_root=self.location_root,
87 location_root=self.location_root,
93 repo_groups=repo_groups,
88 repo_groups=repo_groups,
94 realm=self.realm,
89 realm=self.realm,
95 use_ssl=True,
90 use_ssl=True,
96 template=test_file_path
91 template=test_file_path
97 )
92 )
98 assert 'TEST_EXAMPLE' in generated_config
93 assert 'TEST_EXAMPLE' in generated_config
99
94
100 @pytest.mark.parametrize('list_parent_path', [True, False])
95 @pytest.mark.parametrize('list_parent_path', [True, False])
101 @pytest.mark.parametrize('use_ssl', [True, False])
96 @pytest.mark.parametrize('use_ssl', [True, False])
102 def test_list_parent_path(self, list_parent_path, use_ssl):
97 def test_list_parent_path(self, list_parent_path, use_ssl):
103 generated_config = utils._render_mod_dav_svn_config(
98 generated_config = utils._render_mod_dav_svn_config(
104 parent_path_root=self.parent_path_root,
99 parent_path_root=self.parent_path_root,
105 list_parent_path=list_parent_path,
100 list_parent_path=list_parent_path,
106 location_root=self.location_root,
101 location_root=self.location_root,
107 repo_groups=self.get_repo_group_mocks(count=10),
102 repo_groups=self.get_repo_group_mocks(count=10),
108 realm=self.realm,
103 realm=self.realm,
109 use_ssl=use_ssl,
104 use_ssl=use_ssl,
110 template=''
105 template=''
111 )
106 )
112
107
113 # Assert that correct configuration directive is present.
108 # Assert that correct configuration directive is present.
114 if list_parent_path:
109 if list_parent_path:
115 assert not re.search('SVNListParentPath\s+Off', generated_config)
110 assert not re.search('SVNListParentPath\s+Off', generated_config)
116 assert re.search('SVNListParentPath\s+On', generated_config)
111 assert re.search('SVNListParentPath\s+On', generated_config)
117 else:
112 else:
118 assert re.search('SVNListParentPath\s+Off', generated_config)
113 assert re.search('SVNListParentPath\s+Off', generated_config)
119 assert not re.search('SVNListParentPath\s+On', generated_config)
114 assert not re.search('SVNListParentPath\s+On', generated_config)
120
115
121 if use_ssl:
116 if use_ssl:
122 assert 'RequestHeader edit Destination ^https: http: early' \
117 assert 'RequestHeader edit Destination ^https: http: early' \
123 in generated_config
118 in generated_config
124 else:
119 else:
125 assert '#RequestHeader edit Destination ^https: http: early' \
120 assert '#RequestHeader edit Destination ^https: http: early' \
126 in generated_config
121 in generated_config
General Comments 0
You need to be logged in to leave comments. Login now