##// END OF EJS Templates
tests: Fix a test that was broken due to changes around the rebase-merge option.
Martin Bornhold -
r421:381afb6c default
parent child Browse files
Show More
@@ -1,1037 +1,1038 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2016 RhodeCode GmbH
3 # Copyright (C) 2010-2016 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 mock
21 import mock
22 import pytest
22 import pytest
23
23
24 from rhodecode.lib.utils2 import str2bool
24 from rhodecode.lib.utils2 import str2bool
25 from rhodecode.model.meta import Session
25 from rhodecode.model.meta import Session
26 from rhodecode.model.settings import VcsSettingsModel, UiSetting
26 from rhodecode.model.settings import VcsSettingsModel, UiSetting
27
27
28
28
29 HOOKS_FORM_DATA = {
29 HOOKS_FORM_DATA = {
30 'hooks_changegroup_repo_size': True,
30 'hooks_changegroup_repo_size': True,
31 'hooks_changegroup_push_logger': True,
31 'hooks_changegroup_push_logger': True,
32 'hooks_outgoing_pull_logger': True
32 'hooks_outgoing_pull_logger': True
33 }
33 }
34
34
35 SVN_FORM_DATA = {
35 SVN_FORM_DATA = {
36 'new_svn_branch': 'test-branch',
36 'new_svn_branch': 'test-branch',
37 'new_svn_tag': 'test-tag'
37 'new_svn_tag': 'test-tag'
38 }
38 }
39
39
40 GENERAL_FORM_DATA = {
40 GENERAL_FORM_DATA = {
41 'rhodecode_pr_merge_enabled': True,
41 'rhodecode_pr_merge_enabled': True,
42 'rhodecode_use_outdated_comments': True
42 'rhodecode_use_outdated_comments': True,
43 'rhodecode_hg_use_rebase_for_merging': True,
43 }
44 }
44
45
45
46
46 class TestInheritGlobalSettingsProperty(object):
47 class TestInheritGlobalSettingsProperty(object):
47 def test_get_raises_exception_when_repository_not_specified(self):
48 def test_get_raises_exception_when_repository_not_specified(self):
48 model = VcsSettingsModel()
49 model = VcsSettingsModel()
49 with pytest.raises(Exception) as exc_info:
50 with pytest.raises(Exception) as exc_info:
50 model.inherit_global_settings
51 model.inherit_global_settings
51 assert exc_info.value.message == 'Repository is not specified'
52 assert exc_info.value.message == 'Repository is not specified'
52
53
53 def test_true_is_returned_when_value_is_not_found(self, repo_stub):
54 def test_true_is_returned_when_value_is_not_found(self, repo_stub):
54 model = VcsSettingsModel(repo=repo_stub.repo_name)
55 model = VcsSettingsModel(repo=repo_stub.repo_name)
55 assert model.inherit_global_settings is True
56 assert model.inherit_global_settings is True
56
57
57 def test_value_is_returned(self, repo_stub, settings_util):
58 def test_value_is_returned(self, repo_stub, settings_util):
58 model = VcsSettingsModel(repo=repo_stub.repo_name)
59 model = VcsSettingsModel(repo=repo_stub.repo_name)
59 settings_util.create_repo_rhodecode_setting(
60 settings_util.create_repo_rhodecode_setting(
60 repo_stub, VcsSettingsModel.INHERIT_SETTINGS, False, 'bool')
61 repo_stub, VcsSettingsModel.INHERIT_SETTINGS, False, 'bool')
61 assert model.inherit_global_settings is False
62 assert model.inherit_global_settings is False
62
63
63 def test_value_is_set(self, repo_stub):
64 def test_value_is_set(self, repo_stub):
64 model = VcsSettingsModel(repo=repo_stub.repo_name)
65 model = VcsSettingsModel(repo=repo_stub.repo_name)
65 model.inherit_global_settings = False
66 model.inherit_global_settings = False
66 setting = model.repo_settings.get_setting_by_name(
67 setting = model.repo_settings.get_setting_by_name(
67 VcsSettingsModel.INHERIT_SETTINGS)
68 VcsSettingsModel.INHERIT_SETTINGS)
68 try:
69 try:
69 assert setting.app_settings_type == 'bool'
70 assert setting.app_settings_type == 'bool'
70 assert setting.app_settings_value is False
71 assert setting.app_settings_value is False
71 finally:
72 finally:
72 Session().delete(setting)
73 Session().delete(setting)
73 Session().commit()
74 Session().commit()
74
75
75 def test_set_raises_exception_when_repository_not_specified(self):
76 def test_set_raises_exception_when_repository_not_specified(self):
76 model = VcsSettingsModel()
77 model = VcsSettingsModel()
77 with pytest.raises(Exception) as exc_info:
78 with pytest.raises(Exception) as exc_info:
78 model.inherit_global_settings = False
79 model.inherit_global_settings = False
79 assert exc_info.value.message == 'Repository is not specified'
80 assert exc_info.value.message == 'Repository is not specified'
80
81
81
82
82 class TestVcsSettingsModel(object):
83 class TestVcsSettingsModel(object):
83 def test_global_svn_branch_patterns(self):
84 def test_global_svn_branch_patterns(self):
84 model = VcsSettingsModel()
85 model = VcsSettingsModel()
85 expected_result = {'test': 'test'}
86 expected_result = {'test': 'test'}
86 with mock.patch.object(model, 'global_settings') as settings_mock:
87 with mock.patch.object(model, 'global_settings') as settings_mock:
87 get_settings = settings_mock.get_ui_by_section
88 get_settings = settings_mock.get_ui_by_section
88 get_settings.return_value = expected_result
89 get_settings.return_value = expected_result
89 settings_mock.return_value = expected_result
90 settings_mock.return_value = expected_result
90 result = model.get_global_svn_branch_patterns()
91 result = model.get_global_svn_branch_patterns()
91
92
92 get_settings.assert_called_once_with(model.SVN_BRANCH_SECTION)
93 get_settings.assert_called_once_with(model.SVN_BRANCH_SECTION)
93 assert expected_result == result
94 assert expected_result == result
94
95
95 def test_repo_svn_branch_patterns(self):
96 def test_repo_svn_branch_patterns(self):
96 model = VcsSettingsModel()
97 model = VcsSettingsModel()
97 expected_result = {'test': 'test'}
98 expected_result = {'test': 'test'}
98 with mock.patch.object(model, 'repo_settings') as settings_mock:
99 with mock.patch.object(model, 'repo_settings') as settings_mock:
99 get_settings = settings_mock.get_ui_by_section
100 get_settings = settings_mock.get_ui_by_section
100 get_settings.return_value = expected_result
101 get_settings.return_value = expected_result
101 settings_mock.return_value = expected_result
102 settings_mock.return_value = expected_result
102 result = model.get_repo_svn_branch_patterns()
103 result = model.get_repo_svn_branch_patterns()
103
104
104 get_settings.assert_called_once_with(model.SVN_BRANCH_SECTION)
105 get_settings.assert_called_once_with(model.SVN_BRANCH_SECTION)
105 assert expected_result == result
106 assert expected_result == result
106
107
107 def test_repo_svn_branch_patterns_raises_exception_when_repo_is_not_set(
108 def test_repo_svn_branch_patterns_raises_exception_when_repo_is_not_set(
108 self):
109 self):
109 model = VcsSettingsModel()
110 model = VcsSettingsModel()
110 with pytest.raises(Exception) as exc_info:
111 with pytest.raises(Exception) as exc_info:
111 model.get_repo_svn_branch_patterns()
112 model.get_repo_svn_branch_patterns()
112 assert exc_info.value.message == 'Repository is not specified'
113 assert exc_info.value.message == 'Repository is not specified'
113
114
114 def test_global_svn_tag_patterns(self):
115 def test_global_svn_tag_patterns(self):
115 model = VcsSettingsModel()
116 model = VcsSettingsModel()
116 expected_result = {'test': 'test'}
117 expected_result = {'test': 'test'}
117 with mock.patch.object(model, 'global_settings') as settings_mock:
118 with mock.patch.object(model, 'global_settings') as settings_mock:
118 get_settings = settings_mock.get_ui_by_section
119 get_settings = settings_mock.get_ui_by_section
119 get_settings.return_value = expected_result
120 get_settings.return_value = expected_result
120 settings_mock.return_value = expected_result
121 settings_mock.return_value = expected_result
121 result = model.get_global_svn_tag_patterns()
122 result = model.get_global_svn_tag_patterns()
122
123
123 get_settings.assert_called_once_with(model.SVN_TAG_SECTION)
124 get_settings.assert_called_once_with(model.SVN_TAG_SECTION)
124 assert expected_result == result
125 assert expected_result == result
125
126
126 def test_repo_svn_tag_patterns(self):
127 def test_repo_svn_tag_patterns(self):
127 model = VcsSettingsModel()
128 model = VcsSettingsModel()
128 expected_result = {'test': 'test'}
129 expected_result = {'test': 'test'}
129 with mock.patch.object(model, 'repo_settings') as settings_mock:
130 with mock.patch.object(model, 'repo_settings') as settings_mock:
130 get_settings = settings_mock.get_ui_by_section
131 get_settings = settings_mock.get_ui_by_section
131 get_settings.return_value = expected_result
132 get_settings.return_value = expected_result
132 settings_mock.return_value = expected_result
133 settings_mock.return_value = expected_result
133 result = model.get_repo_svn_tag_patterns()
134 result = model.get_repo_svn_tag_patterns()
134
135
135 get_settings.assert_called_once_with(model.SVN_TAG_SECTION)
136 get_settings.assert_called_once_with(model.SVN_TAG_SECTION)
136 assert expected_result == result
137 assert expected_result == result
137
138
138 def test_repo_svn_tag_patterns_raises_exception_when_repo_is_not_set(self):
139 def test_repo_svn_tag_patterns_raises_exception_when_repo_is_not_set(self):
139 model = VcsSettingsModel()
140 model = VcsSettingsModel()
140 with pytest.raises(Exception) as exc_info:
141 with pytest.raises(Exception) as exc_info:
141 model.get_repo_svn_tag_patterns()
142 model.get_repo_svn_tag_patterns()
142 assert exc_info.value.message == 'Repository is not specified'
143 assert exc_info.value.message == 'Repository is not specified'
143
144
144 def test_get_global_settings(self):
145 def test_get_global_settings(self):
145 expected_result = {'test': 'test'}
146 expected_result = {'test': 'test'}
146 model = VcsSettingsModel()
147 model = VcsSettingsModel()
147 with mock.patch.object(model, '_collect_all_settings') as collect_mock:
148 with mock.patch.object(model, '_collect_all_settings') as collect_mock:
148 collect_mock.return_value = expected_result
149 collect_mock.return_value = expected_result
149 result = model.get_global_settings()
150 result = model.get_global_settings()
150
151
151 collect_mock.assert_called_once_with(global_=True)
152 collect_mock.assert_called_once_with(global_=True)
152 assert result == expected_result
153 assert result == expected_result
153
154
154 def test_get_repo_settings(self, repo_stub):
155 def test_get_repo_settings(self, repo_stub):
155 model = VcsSettingsModel(repo=repo_stub.repo_name)
156 model = VcsSettingsModel(repo=repo_stub.repo_name)
156 expected_result = {'test': 'test'}
157 expected_result = {'test': 'test'}
157 with mock.patch.object(model, '_collect_all_settings') as collect_mock:
158 with mock.patch.object(model, '_collect_all_settings') as collect_mock:
158 collect_mock.return_value = expected_result
159 collect_mock.return_value = expected_result
159 result = model.get_repo_settings()
160 result = model.get_repo_settings()
160
161
161 collect_mock.assert_called_once_with(global_=False)
162 collect_mock.assert_called_once_with(global_=False)
162 assert result == expected_result
163 assert result == expected_result
163
164
164 @pytest.mark.parametrize('settings, global_', [
165 @pytest.mark.parametrize('settings, global_', [
165 ('global_settings', True),
166 ('global_settings', True),
166 ('repo_settings', False)
167 ('repo_settings', False)
167 ])
168 ])
168 def test_collect_all_settings(self, settings, global_):
169 def test_collect_all_settings(self, settings, global_):
169 model = VcsSettingsModel()
170 model = VcsSettingsModel()
170 result_mock = self._mock_result()
171 result_mock = self._mock_result()
171
172
172 settings_patch = mock.patch.object(model, settings)
173 settings_patch = mock.patch.object(model, settings)
173 with settings_patch as settings_mock:
174 with settings_patch as settings_mock:
174 settings_mock.get_ui_by_section_and_key.return_value = result_mock
175 settings_mock.get_ui_by_section_and_key.return_value = result_mock
175 settings_mock.get_setting_by_name.return_value = result_mock
176 settings_mock.get_setting_by_name.return_value = result_mock
176 result = model._collect_all_settings(global_=global_)
177 result = model._collect_all_settings(global_=global_)
177
178
178 ui_settings = model.HG_SETTINGS + model.HOOKS_SETTINGS
179 ui_settings = model.HG_SETTINGS + model.HOOKS_SETTINGS
179 self._assert_get_settings_calls(
180 self._assert_get_settings_calls(
180 settings_mock, ui_settings, model.GENERAL_SETTINGS)
181 settings_mock, ui_settings, model.GENERAL_SETTINGS)
181 self._assert_collect_all_settings_result(
182 self._assert_collect_all_settings_result(
182 ui_settings, model.GENERAL_SETTINGS, result)
183 ui_settings, model.GENERAL_SETTINGS, result)
183
184
184 @pytest.mark.parametrize('settings, global_', [
185 @pytest.mark.parametrize('settings, global_', [
185 ('global_settings', True),
186 ('global_settings', True),
186 ('repo_settings', False)
187 ('repo_settings', False)
187 ])
188 ])
188 def test_collect_all_settings_without_empty_value(self, settings, global_):
189 def test_collect_all_settings_without_empty_value(self, settings, global_):
189 model = VcsSettingsModel()
190 model = VcsSettingsModel()
190
191
191 settings_patch = mock.patch.object(model, settings)
192 settings_patch = mock.patch.object(model, settings)
192 with settings_patch as settings_mock:
193 with settings_patch as settings_mock:
193 settings_mock.get_ui_by_section_and_key.return_value = None
194 settings_mock.get_ui_by_section_and_key.return_value = None
194 settings_mock.get_setting_by_name.return_value = None
195 settings_mock.get_setting_by_name.return_value = None
195 result = model._collect_all_settings(global_=global_)
196 result = model._collect_all_settings(global_=global_)
196
197
197 assert result == {}
198 assert result == {}
198
199
199 def _mock_result(self):
200 def _mock_result(self):
200 result_mock = mock.Mock()
201 result_mock = mock.Mock()
201 result_mock.ui_value = 'ui_value'
202 result_mock.ui_value = 'ui_value'
202 result_mock.ui_active = True
203 result_mock.ui_active = True
203 result_mock.app_settings_value = 'setting_value'
204 result_mock.app_settings_value = 'setting_value'
204 return result_mock
205 return result_mock
205
206
206 def _assert_get_settings_calls(
207 def _assert_get_settings_calls(
207 self, settings_mock, ui_settings, general_settings):
208 self, settings_mock, ui_settings, general_settings):
208 assert (
209 assert (
209 settings_mock.get_ui_by_section_and_key.call_count ==
210 settings_mock.get_ui_by_section_and_key.call_count ==
210 len(ui_settings))
211 len(ui_settings))
211 assert (
212 assert (
212 settings_mock.get_setting_by_name.call_count ==
213 settings_mock.get_setting_by_name.call_count ==
213 len(general_settings))
214 len(general_settings))
214
215
215 for section, key in ui_settings:
216 for section, key in ui_settings:
216 expected_call = mock.call(section, key)
217 expected_call = mock.call(section, key)
217 assert (
218 assert (
218 expected_call in
219 expected_call in
219 settings_mock.get_ui_by_section_and_key.call_args_list)
220 settings_mock.get_ui_by_section_and_key.call_args_list)
220
221
221 for name in general_settings:
222 for name in general_settings:
222 expected_call = mock.call(name)
223 expected_call = mock.call(name)
223 assert (
224 assert (
224 expected_call in
225 expected_call in
225 settings_mock.get_setting_by_name.call_args_list)
226 settings_mock.get_setting_by_name.call_args_list)
226
227
227 def _assert_collect_all_settings_result(
228 def _assert_collect_all_settings_result(
228 self, ui_settings, general_settings, result):
229 self, ui_settings, general_settings, result):
229 expected_result = {}
230 expected_result = {}
230 for section, key in ui_settings:
231 for section, key in ui_settings:
231 key = '{}_{}'.format(section, key.replace('.', '_'))
232 key = '{}_{}'.format(section, key.replace('.', '_'))
232 value = True if section in ('extensions', 'hooks') else 'ui_value'
233 value = True if section in ('extensions', 'hooks') else 'ui_value'
233 expected_result[key] = value
234 expected_result[key] = value
234
235
235 for name in general_settings:
236 for name in general_settings:
236 key = 'rhodecode_' + name
237 key = 'rhodecode_' + name
237 expected_result[key] = 'setting_value'
238 expected_result[key] = 'setting_value'
238
239
239 assert expected_result == result
240 assert expected_result == result
240
241
241
242
242 class TestCreateOrUpdateRepoHookSettings(object):
243 class TestCreateOrUpdateRepoHookSettings(object):
243 def test_create_when_no_repo_object_found(self, repo_stub):
244 def test_create_when_no_repo_object_found(self, repo_stub):
244 model = VcsSettingsModel(repo=repo_stub.repo_name)
245 model = VcsSettingsModel(repo=repo_stub.repo_name)
245
246
246 self._create_settings(model, HOOKS_FORM_DATA)
247 self._create_settings(model, HOOKS_FORM_DATA)
247
248
248 cleanup = []
249 cleanup = []
249 try:
250 try:
250 for section, key in model.HOOKS_SETTINGS:
251 for section, key in model.HOOKS_SETTINGS:
251 ui = model.repo_settings.get_ui_by_section_and_key(
252 ui = model.repo_settings.get_ui_by_section_and_key(
252 section, key)
253 section, key)
253 assert ui.ui_active is True
254 assert ui.ui_active is True
254 cleanup.append(ui)
255 cleanup.append(ui)
255 finally:
256 finally:
256 for ui in cleanup:
257 for ui in cleanup:
257 Session().delete(ui)
258 Session().delete(ui)
258 Session().commit()
259 Session().commit()
259
260
260 def test_create_raises_exception_when_data_incomplete(self, repo_stub):
261 def test_create_raises_exception_when_data_incomplete(self, repo_stub):
261 model = VcsSettingsModel(repo=repo_stub.repo_name)
262 model = VcsSettingsModel(repo=repo_stub.repo_name)
262
263
263 deleted_key = 'hooks_changegroup_repo_size'
264 deleted_key = 'hooks_changegroup_repo_size'
264 data = HOOKS_FORM_DATA.copy()
265 data = HOOKS_FORM_DATA.copy()
265 data.pop(deleted_key)
266 data.pop(deleted_key)
266
267
267 with pytest.raises(ValueError) as exc_info:
268 with pytest.raises(ValueError) as exc_info:
268 model.create_or_update_repo_hook_settings(data)
269 model.create_or_update_repo_hook_settings(data)
269 assert (
270 assert (
270 exc_info.value.message ==
271 exc_info.value.message ==
271 'The given data does not contain {} key'.format(deleted_key))
272 'The given data does not contain {} key'.format(deleted_key))
272
273
273 def test_update_when_repo_object_found(self, repo_stub, settings_util):
274 def test_update_when_repo_object_found(self, repo_stub, settings_util):
274 model = VcsSettingsModel(repo=repo_stub.repo_name)
275 model = VcsSettingsModel(repo=repo_stub.repo_name)
275 for section, key in model.HOOKS_SETTINGS:
276 for section, key in model.HOOKS_SETTINGS:
276 settings_util.create_repo_rhodecode_ui(
277 settings_util.create_repo_rhodecode_ui(
277 repo_stub, section, None, key=key, active=False)
278 repo_stub, section, None, key=key, active=False)
278 model.create_or_update_repo_hook_settings(HOOKS_FORM_DATA)
279 model.create_or_update_repo_hook_settings(HOOKS_FORM_DATA)
279 for section, key in model.HOOKS_SETTINGS:
280 for section, key in model.HOOKS_SETTINGS:
280 ui = model.repo_settings.get_ui_by_section_and_key(section, key)
281 ui = model.repo_settings.get_ui_by_section_and_key(section, key)
281 assert ui.ui_active is True
282 assert ui.ui_active is True
282
283
283 def _create_settings(self, model, data):
284 def _create_settings(self, model, data):
284 global_patch = mock.patch.object(model, 'global_settings')
285 global_patch = mock.patch.object(model, 'global_settings')
285 global_setting = mock.Mock()
286 global_setting = mock.Mock()
286 global_setting.ui_value = 'Test value'
287 global_setting.ui_value = 'Test value'
287 with global_patch as global_mock:
288 with global_patch as global_mock:
288 global_mock.get_ui_by_section_and_key.return_value = global_setting
289 global_mock.get_ui_by_section_and_key.return_value = global_setting
289 model.create_or_update_repo_hook_settings(HOOKS_FORM_DATA)
290 model.create_or_update_repo_hook_settings(HOOKS_FORM_DATA)
290
291
291
292
292 class TestUpdateGlobalHookSettings(object):
293 class TestUpdateGlobalHookSettings(object):
293 def test_update_raises_exception_when_data_incomplete(self):
294 def test_update_raises_exception_when_data_incomplete(self):
294 model = VcsSettingsModel()
295 model = VcsSettingsModel()
295
296
296 deleted_key = 'hooks_changegroup_repo_size'
297 deleted_key = 'hooks_changegroup_repo_size'
297 data = HOOKS_FORM_DATA.copy()
298 data = HOOKS_FORM_DATA.copy()
298 data.pop(deleted_key)
299 data.pop(deleted_key)
299
300
300 with pytest.raises(ValueError) as exc_info:
301 with pytest.raises(ValueError) as exc_info:
301 model.update_global_hook_settings(data)
302 model.update_global_hook_settings(data)
302 assert (
303 assert (
303 exc_info.value.message ==
304 exc_info.value.message ==
304 'The given data does not contain {} key'.format(deleted_key))
305 'The given data does not contain {} key'.format(deleted_key))
305
306
306 def test_update_global_hook_settings(self, settings_util):
307 def test_update_global_hook_settings(self, settings_util):
307 model = VcsSettingsModel()
308 model = VcsSettingsModel()
308 setting_mock = mock.MagicMock()
309 setting_mock = mock.MagicMock()
309 setting_mock.ui_active = False
310 setting_mock.ui_active = False
310 get_settings_patcher = mock.patch.object(
311 get_settings_patcher = mock.patch.object(
311 model.global_settings, 'get_ui_by_section_and_key',
312 model.global_settings, 'get_ui_by_section_and_key',
312 return_value=setting_mock)
313 return_value=setting_mock)
313 session_patcher = mock.patch('rhodecode.model.settings.Session')
314 session_patcher = mock.patch('rhodecode.model.settings.Session')
314 with get_settings_patcher as get_settings_mock, session_patcher:
315 with get_settings_patcher as get_settings_mock, session_patcher:
315 model.update_global_hook_settings(HOOKS_FORM_DATA)
316 model.update_global_hook_settings(HOOKS_FORM_DATA)
316 assert setting_mock.ui_active is True
317 assert setting_mock.ui_active is True
317 assert get_settings_mock.call_count == 3
318 assert get_settings_mock.call_count == 3
318
319
319
320
320 class TestCreateOrUpdateRepoGeneralSettings(object):
321 class TestCreateOrUpdateRepoGeneralSettings(object):
321 def test_calls_create_or_update_general_settings(self, repo_stub):
322 def test_calls_create_or_update_general_settings(self, repo_stub):
322 model = VcsSettingsModel(repo=repo_stub.repo_name)
323 model = VcsSettingsModel(repo=repo_stub.repo_name)
323 create_patch = mock.patch.object(
324 create_patch = mock.patch.object(
324 model, '_create_or_update_general_settings')
325 model, '_create_or_update_general_settings')
325 with create_patch as create_mock:
326 with create_patch as create_mock:
326 model.create_or_update_repo_pr_settings(GENERAL_FORM_DATA)
327 model.create_or_update_repo_pr_settings(GENERAL_FORM_DATA)
327 create_mock.assert_called_once_with(
328 create_mock.assert_called_once_with(
328 model.repo_settings, GENERAL_FORM_DATA)
329 model.repo_settings, GENERAL_FORM_DATA)
329
330
330 def test_raises_exception_when_repository_is_not_specified(self):
331 def test_raises_exception_when_repository_is_not_specified(self):
331 model = VcsSettingsModel()
332 model = VcsSettingsModel()
332 with pytest.raises(Exception) as exc_info:
333 with pytest.raises(Exception) as exc_info:
333 model.create_or_update_repo_pr_settings(GENERAL_FORM_DATA)
334 model.create_or_update_repo_pr_settings(GENERAL_FORM_DATA)
334 assert exc_info.value.message == 'Repository is not specified'
335 assert exc_info.value.message == 'Repository is not specified'
335
336
336
337
337 class TestCreateOrUpdatGlobalGeneralSettings(object):
338 class TestCreateOrUpdatGlobalGeneralSettings(object):
338 def test_calls_create_or_update_general_settings(self):
339 def test_calls_create_or_update_general_settings(self):
339 model = VcsSettingsModel()
340 model = VcsSettingsModel()
340 create_patch = mock.patch.object(
341 create_patch = mock.patch.object(
341 model, '_create_or_update_general_settings')
342 model, '_create_or_update_general_settings')
342 with create_patch as create_mock:
343 with create_patch as create_mock:
343 model.create_or_update_global_pr_settings(GENERAL_FORM_DATA)
344 model.create_or_update_global_pr_settings(GENERAL_FORM_DATA)
344 create_mock.assert_called_once_with(
345 create_mock.assert_called_once_with(
345 model.global_settings, GENERAL_FORM_DATA)
346 model.global_settings, GENERAL_FORM_DATA)
346
347
347
348
348 class TestCreateOrUpdateGeneralSettings(object):
349 class TestCreateOrUpdateGeneralSettings(object):
349 def test_create_when_no_repo_settings_found(self, repo_stub):
350 def test_create_when_no_repo_settings_found(self, repo_stub):
350 model = VcsSettingsModel(repo=repo_stub.repo_name)
351 model = VcsSettingsModel(repo=repo_stub.repo_name)
351 model._create_or_update_general_settings(
352 model._create_or_update_general_settings(
352 model.repo_settings, GENERAL_FORM_DATA)
353 model.repo_settings, GENERAL_FORM_DATA)
353
354
354 cleanup = []
355 cleanup = []
355 try:
356 try:
356 for name in model.GENERAL_SETTINGS:
357 for name in model.GENERAL_SETTINGS:
357 setting = model.repo_settings.get_setting_by_name(name)
358 setting = model.repo_settings.get_setting_by_name(name)
358 assert setting.app_settings_value is True
359 assert setting.app_settings_value is True
359 cleanup.append(setting)
360 cleanup.append(setting)
360 finally:
361 finally:
361 for setting in cleanup:
362 for setting in cleanup:
362 Session().delete(setting)
363 Session().delete(setting)
363 Session().commit()
364 Session().commit()
364
365
365 def test_create_raises_exception_when_data_incomplete(self, repo_stub):
366 def test_create_raises_exception_when_data_incomplete(self, repo_stub):
366 model = VcsSettingsModel(repo=repo_stub.repo_name)
367 model = VcsSettingsModel(repo=repo_stub.repo_name)
367
368
368 deleted_key = 'rhodecode_pr_merge_enabled'
369 deleted_key = 'rhodecode_pr_merge_enabled'
369 data = GENERAL_FORM_DATA.copy()
370 data = GENERAL_FORM_DATA.copy()
370 data.pop(deleted_key)
371 data.pop(deleted_key)
371
372
372 with pytest.raises(ValueError) as exc_info:
373 with pytest.raises(ValueError) as exc_info:
373 model._create_or_update_general_settings(model.repo_settings, data)
374 model._create_or_update_general_settings(model.repo_settings, data)
374 assert (
375 assert (
375 exc_info.value.message ==
376 exc_info.value.message ==
376 'The given data does not contain {} key'.format(deleted_key))
377 'The given data does not contain {} key'.format(deleted_key))
377
378
378 def test_update_when_repo_setting_found(self, repo_stub, settings_util):
379 def test_update_when_repo_setting_found(self, repo_stub, settings_util):
379 model = VcsSettingsModel(repo=repo_stub.repo_name)
380 model = VcsSettingsModel(repo=repo_stub.repo_name)
380 for name in model.GENERAL_SETTINGS:
381 for name in model.GENERAL_SETTINGS:
381 settings_util.create_repo_rhodecode_setting(
382 settings_util.create_repo_rhodecode_setting(
382 repo_stub, name, False, 'bool')
383 repo_stub, name, False, 'bool')
383
384
384 model._create_or_update_general_settings(
385 model._create_or_update_general_settings(
385 model.repo_settings, GENERAL_FORM_DATA)
386 model.repo_settings, GENERAL_FORM_DATA)
386
387
387 for name in model.GENERAL_SETTINGS:
388 for name in model.GENERAL_SETTINGS:
388 setting = model.repo_settings.get_setting_by_name(name)
389 setting = model.repo_settings.get_setting_by_name(name)
389 assert setting.app_settings_value is True
390 assert setting.app_settings_value is True
390
391
391
392
392 class TestCreateRepoSvnSettings(object):
393 class TestCreateRepoSvnSettings(object):
393 def test_calls_create_svn_settings(self, repo_stub):
394 def test_calls_create_svn_settings(self, repo_stub):
394 model = VcsSettingsModel(repo=repo_stub.repo_name)
395 model = VcsSettingsModel(repo=repo_stub.repo_name)
395 with mock.patch.object(model, '_create_svn_settings') as create_mock:
396 with mock.patch.object(model, '_create_svn_settings') as create_mock:
396 model.create_repo_svn_settings(SVN_FORM_DATA)
397 model.create_repo_svn_settings(SVN_FORM_DATA)
397 create_mock.assert_called_once_with(model.repo_settings, SVN_FORM_DATA)
398 create_mock.assert_called_once_with(model.repo_settings, SVN_FORM_DATA)
398
399
399 def test_raises_exception_when_repository_is_not_specified(self):
400 def test_raises_exception_when_repository_is_not_specified(self):
400 model = VcsSettingsModel()
401 model = VcsSettingsModel()
401 with pytest.raises(Exception) as exc_info:
402 with pytest.raises(Exception) as exc_info:
402 model.create_repo_svn_settings(SVN_FORM_DATA)
403 model.create_repo_svn_settings(SVN_FORM_DATA)
403 assert exc_info.value.message == 'Repository is not specified'
404 assert exc_info.value.message == 'Repository is not specified'
404
405
405
406
406 class TestCreateGlobalSvnSettings(object):
407 class TestCreateGlobalSvnSettings(object):
407 def test_calls_create_svn_settings(self):
408 def test_calls_create_svn_settings(self):
408 model = VcsSettingsModel()
409 model = VcsSettingsModel()
409 with mock.patch.object(model, '_create_svn_settings') as create_mock:
410 with mock.patch.object(model, '_create_svn_settings') as create_mock:
410 model.create_global_svn_settings(SVN_FORM_DATA)
411 model.create_global_svn_settings(SVN_FORM_DATA)
411 create_mock.assert_called_once_with(
412 create_mock.assert_called_once_with(
412 model.global_settings, SVN_FORM_DATA)
413 model.global_settings, SVN_FORM_DATA)
413
414
414
415
415 class TestCreateSvnSettings(object):
416 class TestCreateSvnSettings(object):
416 def test_create(self, repo_stub):
417 def test_create(self, repo_stub):
417 model = VcsSettingsModel(repo=repo_stub.repo_name)
418 model = VcsSettingsModel(repo=repo_stub.repo_name)
418 model._create_svn_settings(model.repo_settings, SVN_FORM_DATA)
419 model._create_svn_settings(model.repo_settings, SVN_FORM_DATA)
419 Session().commit()
420 Session().commit()
420
421
421 branch_ui = model.repo_settings.get_ui_by_section(
422 branch_ui = model.repo_settings.get_ui_by_section(
422 model.SVN_BRANCH_SECTION)
423 model.SVN_BRANCH_SECTION)
423 tag_ui = model.repo_settings.get_ui_by_section(
424 tag_ui = model.repo_settings.get_ui_by_section(
424 model.SVN_TAG_SECTION)
425 model.SVN_TAG_SECTION)
425
426
426 try:
427 try:
427 assert len(branch_ui) == 1
428 assert len(branch_ui) == 1
428 assert len(tag_ui) == 1
429 assert len(tag_ui) == 1
429 finally:
430 finally:
430 Session().delete(branch_ui[0])
431 Session().delete(branch_ui[0])
431 Session().delete(tag_ui[0])
432 Session().delete(tag_ui[0])
432 Session().commit()
433 Session().commit()
433
434
434 def test_create_tag(self, repo_stub):
435 def test_create_tag(self, repo_stub):
435 model = VcsSettingsModel(repo=repo_stub.repo_name)
436 model = VcsSettingsModel(repo=repo_stub.repo_name)
436 data = SVN_FORM_DATA.copy()
437 data = SVN_FORM_DATA.copy()
437 data.pop('new_svn_branch')
438 data.pop('new_svn_branch')
438 model._create_svn_settings(model.repo_settings, data)
439 model._create_svn_settings(model.repo_settings, data)
439 Session().commit()
440 Session().commit()
440
441
441 branch_ui = model.repo_settings.get_ui_by_section(
442 branch_ui = model.repo_settings.get_ui_by_section(
442 model.SVN_BRANCH_SECTION)
443 model.SVN_BRANCH_SECTION)
443 tag_ui = model.repo_settings.get_ui_by_section(
444 tag_ui = model.repo_settings.get_ui_by_section(
444 model.SVN_TAG_SECTION)
445 model.SVN_TAG_SECTION)
445
446
446 try:
447 try:
447 assert len(branch_ui) == 0
448 assert len(branch_ui) == 0
448 assert len(tag_ui) == 1
449 assert len(tag_ui) == 1
449 finally:
450 finally:
450 Session().delete(tag_ui[0])
451 Session().delete(tag_ui[0])
451 Session().commit()
452 Session().commit()
452
453
453 def test_create_nothing_when_no_svn_settings_specified(self, repo_stub):
454 def test_create_nothing_when_no_svn_settings_specified(self, repo_stub):
454 model = VcsSettingsModel(repo=repo_stub.repo_name)
455 model = VcsSettingsModel(repo=repo_stub.repo_name)
455 model._create_svn_settings(model.repo_settings, {})
456 model._create_svn_settings(model.repo_settings, {})
456 Session().commit()
457 Session().commit()
457
458
458 branch_ui = model.repo_settings.get_ui_by_section(
459 branch_ui = model.repo_settings.get_ui_by_section(
459 model.SVN_BRANCH_SECTION)
460 model.SVN_BRANCH_SECTION)
460 tag_ui = model.repo_settings.get_ui_by_section(
461 tag_ui = model.repo_settings.get_ui_by_section(
461 model.SVN_TAG_SECTION)
462 model.SVN_TAG_SECTION)
462
463
463 assert len(branch_ui) == 0
464 assert len(branch_ui) == 0
464 assert len(tag_ui) == 0
465 assert len(tag_ui) == 0
465
466
466 def test_create_nothing_when_empty_settings_specified(self, repo_stub):
467 def test_create_nothing_when_empty_settings_specified(self, repo_stub):
467 model = VcsSettingsModel(repo=repo_stub.repo_name)
468 model = VcsSettingsModel(repo=repo_stub.repo_name)
468 data = {
469 data = {
469 'new_svn_branch': '',
470 'new_svn_branch': '',
470 'new_svn_tag': ''
471 'new_svn_tag': ''
471 }
472 }
472 model._create_svn_settings(model.repo_settings, data)
473 model._create_svn_settings(model.repo_settings, data)
473 Session().commit()
474 Session().commit()
474
475
475 branch_ui = model.repo_settings.get_ui_by_section(
476 branch_ui = model.repo_settings.get_ui_by_section(
476 model.SVN_BRANCH_SECTION)
477 model.SVN_BRANCH_SECTION)
477 tag_ui = model.repo_settings.get_ui_by_section(
478 tag_ui = model.repo_settings.get_ui_by_section(
478 model.SVN_TAG_SECTION)
479 model.SVN_TAG_SECTION)
479
480
480 assert len(branch_ui) == 0
481 assert len(branch_ui) == 0
481 assert len(tag_ui) == 0
482 assert len(tag_ui) == 0
482
483
483
484
484 class TestCreateOrUpdateUi(object):
485 class TestCreateOrUpdateUi(object):
485 def test_create(self, repo_stub):
486 def test_create(self, repo_stub):
486 model = VcsSettingsModel(repo=repo_stub.repo_name)
487 model = VcsSettingsModel(repo=repo_stub.repo_name)
487 model._create_or_update_ui(
488 model._create_or_update_ui(
488 model.repo_settings, 'test-section', 'test-key', active=False,
489 model.repo_settings, 'test-section', 'test-key', active=False,
489 value='False')
490 value='False')
490 Session().commit()
491 Session().commit()
491
492
492 created_ui = model.repo_settings.get_ui_by_section_and_key(
493 created_ui = model.repo_settings.get_ui_by_section_and_key(
493 'test-section', 'test-key')
494 'test-section', 'test-key')
494
495
495 try:
496 try:
496 assert created_ui.ui_active is False
497 assert created_ui.ui_active is False
497 assert str2bool(created_ui.ui_value) is False
498 assert str2bool(created_ui.ui_value) is False
498 finally:
499 finally:
499 Session().delete(created_ui)
500 Session().delete(created_ui)
500 Session().commit()
501 Session().commit()
501
502
502 def test_update(self, repo_stub, settings_util):
503 def test_update(self, repo_stub, settings_util):
503 model = VcsSettingsModel(repo=repo_stub.repo_name)
504 model = VcsSettingsModel(repo=repo_stub.repo_name)
504
505
505 largefiles, phases = model.HG_SETTINGS
506 largefiles, phases = model.HG_SETTINGS
506 section = 'test-section'
507 section = 'test-section'
507 key = 'test-key'
508 key = 'test-key'
508 settings_util.create_repo_rhodecode_ui(
509 settings_util.create_repo_rhodecode_ui(
509 repo_stub, section, 'True', key=key, active=True)
510 repo_stub, section, 'True', key=key, active=True)
510
511
511 model._create_or_update_ui(
512 model._create_or_update_ui(
512 model.repo_settings, section, key, active=False, value='False')
513 model.repo_settings, section, key, active=False, value='False')
513 Session().commit()
514 Session().commit()
514
515
515 created_ui = model.repo_settings.get_ui_by_section_and_key(
516 created_ui = model.repo_settings.get_ui_by_section_and_key(
516 section, key)
517 section, key)
517 assert created_ui.ui_active is False
518 assert created_ui.ui_active is False
518 assert str2bool(created_ui.ui_value) is False
519 assert str2bool(created_ui.ui_value) is False
519
520
520
521
521 class TestCreateOrUpdateRepoHgSettings(object):
522 class TestCreateOrUpdateRepoHgSettings(object):
522 FORM_DATA = {
523 FORM_DATA = {
523 'extensions_largefiles': False,
524 'extensions_largefiles': False,
524 'phases_publish': False
525 'phases_publish': False
525 }
526 }
526
527
527 def test_creates_repo_hg_settings_when_data_is_correct(self, repo_stub):
528 def test_creates_repo_hg_settings_when_data_is_correct(self, repo_stub):
528 model = VcsSettingsModel(repo=repo_stub.repo_name)
529 model = VcsSettingsModel(repo=repo_stub.repo_name)
529 with mock.patch.object(model, '_create_or_update_ui') as create_mock:
530 with mock.patch.object(model, '_create_or_update_ui') as create_mock:
530 model.create_or_update_repo_hg_settings(self.FORM_DATA)
531 model.create_or_update_repo_hg_settings(self.FORM_DATA)
531 expected_calls = [
532 expected_calls = [
532 mock.call(model.repo_settings, 'extensions', 'largefiles',
533 mock.call(model.repo_settings, 'extensions', 'largefiles',
533 active=False, value=''),
534 active=False, value=''),
534 mock.call(model.repo_settings, 'phases', 'publish', value='False'),
535 mock.call(model.repo_settings, 'phases', 'publish', value='False'),
535 ]
536 ]
536 assert expected_calls == create_mock.call_args_list
537 assert expected_calls == create_mock.call_args_list
537
538
538 @pytest.mark.parametrize('field_to_remove', FORM_DATA.keys())
539 @pytest.mark.parametrize('field_to_remove', FORM_DATA.keys())
539 def test_key_is_not_found(self, repo_stub, field_to_remove):
540 def test_key_is_not_found(self, repo_stub, field_to_remove):
540 model = VcsSettingsModel(repo=repo_stub.repo_name)
541 model = VcsSettingsModel(repo=repo_stub.repo_name)
541 data = self.FORM_DATA.copy()
542 data = self.FORM_DATA.copy()
542 data.pop(field_to_remove)
543 data.pop(field_to_remove)
543 with pytest.raises(ValueError) as exc_info:
544 with pytest.raises(ValueError) as exc_info:
544 model.create_or_update_repo_hg_settings(data)
545 model.create_or_update_repo_hg_settings(data)
545 expected_message = 'The given data does not contain {} key'.format(
546 expected_message = 'The given data does not contain {} key'.format(
546 field_to_remove)
547 field_to_remove)
547 assert exc_info.value.message == expected_message
548 assert exc_info.value.message == expected_message
548
549
549 def test_create_raises_exception_when_repository_not_specified(self):
550 def test_create_raises_exception_when_repository_not_specified(self):
550 model = VcsSettingsModel()
551 model = VcsSettingsModel()
551 with pytest.raises(Exception) as exc_info:
552 with pytest.raises(Exception) as exc_info:
552 model.create_or_update_repo_hg_settings(self.FORM_DATA)
553 model.create_or_update_repo_hg_settings(self.FORM_DATA)
553 assert exc_info.value.message == 'Repository is not specified'
554 assert exc_info.value.message == 'Repository is not specified'
554
555
555
556
556 class TestUpdateGlobalSslSetting(object):
557 class TestUpdateGlobalSslSetting(object):
557 def test_updates_global_hg_settings(self):
558 def test_updates_global_hg_settings(self):
558 model = VcsSettingsModel()
559 model = VcsSettingsModel()
559 with mock.patch.object(model, '_create_or_update_ui') as create_mock:
560 with mock.patch.object(model, '_create_or_update_ui') as create_mock:
560 model.update_global_ssl_setting('False')
561 model.update_global_ssl_setting('False')
561 create_mock.assert_called_once_with(
562 create_mock.assert_called_once_with(
562 model.global_settings, 'web', 'push_ssl', value='False')
563 model.global_settings, 'web', 'push_ssl', value='False')
563
564
564
565
565 class TestUpdateGlobalPathSetting(object):
566 class TestUpdateGlobalPathSetting(object):
566 def test_updates_global_path_settings(self):
567 def test_updates_global_path_settings(self):
567 model = VcsSettingsModel()
568 model = VcsSettingsModel()
568 with mock.patch.object(model, '_create_or_update_ui') as create_mock:
569 with mock.patch.object(model, '_create_or_update_ui') as create_mock:
569 model.update_global_path_setting('False')
570 model.update_global_path_setting('False')
570 create_mock.assert_called_once_with(
571 create_mock.assert_called_once_with(
571 model.global_settings, 'paths', '/', value='False')
572 model.global_settings, 'paths', '/', value='False')
572
573
573
574
574 class TestCreateOrUpdateGlobalHgSettings(object):
575 class TestCreateOrUpdateGlobalHgSettings(object):
575 FORM_DATA = {
576 FORM_DATA = {
576 'extensions_largefiles': False,
577 'extensions_largefiles': False,
577 'phases_publish': False,
578 'phases_publish': False,
578 'extensions_hgsubversion': False
579 'extensions_hgsubversion': False
579 }
580 }
580
581
581 def test_creates_repo_hg_settings_when_data_is_correct(self):
582 def test_creates_repo_hg_settings_when_data_is_correct(self):
582 model = VcsSettingsModel()
583 model = VcsSettingsModel()
583 with mock.patch.object(model, '_create_or_update_ui') as create_mock:
584 with mock.patch.object(model, '_create_or_update_ui') as create_mock:
584 model.create_or_update_global_hg_settings(self.FORM_DATA)
585 model.create_or_update_global_hg_settings(self.FORM_DATA)
585 expected_calls = [
586 expected_calls = [
586 mock.call(model.global_settings, 'extensions', 'largefiles',
587 mock.call(model.global_settings, 'extensions', 'largefiles',
587 active=False, value=''),
588 active=False, value=''),
588 mock.call(model.global_settings, 'phases', 'publish',
589 mock.call(model.global_settings, 'phases', 'publish',
589 value='False'),
590 value='False'),
590 mock.call(model.global_settings, 'extensions', 'hgsubversion',
591 mock.call(model.global_settings, 'extensions', 'hgsubversion',
591 active=False)
592 active=False)
592 ]
593 ]
593 assert expected_calls == create_mock.call_args_list
594 assert expected_calls == create_mock.call_args_list
594
595
595 @pytest.mark.parametrize('field_to_remove', FORM_DATA.keys())
596 @pytest.mark.parametrize('field_to_remove', FORM_DATA.keys())
596 def test_key_is_not_found(self, repo_stub, field_to_remove):
597 def test_key_is_not_found(self, repo_stub, field_to_remove):
597 model = VcsSettingsModel(repo=repo_stub.repo_name)
598 model = VcsSettingsModel(repo=repo_stub.repo_name)
598 data = self.FORM_DATA.copy()
599 data = self.FORM_DATA.copy()
599 data.pop(field_to_remove)
600 data.pop(field_to_remove)
600 with pytest.raises(Exception) as exc_info:
601 with pytest.raises(Exception) as exc_info:
601 model.create_or_update_global_hg_settings(data)
602 model.create_or_update_global_hg_settings(data)
602 expected_message = 'The given data does not contain {} key'.format(
603 expected_message = 'The given data does not contain {} key'.format(
603 field_to_remove)
604 field_to_remove)
604 assert exc_info.value.message == expected_message
605 assert exc_info.value.message == expected_message
605
606
606
607
607 class TestDeleteRepoSvnPattern(object):
608 class TestDeleteRepoSvnPattern(object):
608 def test_success_when_repo_is_set(self, backend_svn):
609 def test_success_when_repo_is_set(self, backend_svn):
609 repo_name = backend_svn.repo_name
610 repo_name = backend_svn.repo_name
610 model = VcsSettingsModel(repo=repo_name)
611 model = VcsSettingsModel(repo=repo_name)
611 delete_ui_patch = mock.patch.object(model.repo_settings, 'delete_ui')
612 delete_ui_patch = mock.patch.object(model.repo_settings, 'delete_ui')
612 with delete_ui_patch as delete_ui_mock:
613 with delete_ui_patch as delete_ui_mock:
613 model.delete_repo_svn_pattern(123)
614 model.delete_repo_svn_pattern(123)
614 delete_ui_mock.assert_called_once_with(123)
615 delete_ui_mock.assert_called_once_with(123)
615
616
616 def test_raises_exception_when_repository_is_not_specified(self):
617 def test_raises_exception_when_repository_is_not_specified(self):
617 model = VcsSettingsModel()
618 model = VcsSettingsModel()
618 with pytest.raises(Exception) as exc_info:
619 with pytest.raises(Exception) as exc_info:
619 model.delete_repo_svn_pattern(123)
620 model.delete_repo_svn_pattern(123)
620 assert exc_info.value.message == 'Repository is not specified'
621 assert exc_info.value.message == 'Repository is not specified'
621
622
622
623
623 class TestDeleteGlobalSvnPattern(object):
624 class TestDeleteGlobalSvnPattern(object):
624 def test_delete_global_svn_pattern_calls_delete_ui(self):
625 def test_delete_global_svn_pattern_calls_delete_ui(self):
625 model = VcsSettingsModel()
626 model = VcsSettingsModel()
626 delete_ui_patch = mock.patch.object(model.global_settings, 'delete_ui')
627 delete_ui_patch = mock.patch.object(model.global_settings, 'delete_ui')
627 with delete_ui_patch as delete_ui_mock:
628 with delete_ui_patch as delete_ui_mock:
628 model.delete_global_svn_pattern(123)
629 model.delete_global_svn_pattern(123)
629 delete_ui_mock.assert_called_once_with(123)
630 delete_ui_mock.assert_called_once_with(123)
630
631
631
632
632 class TestFilterUiSettings(object):
633 class TestFilterUiSettings(object):
633 def test_settings_are_filtered(self):
634 def test_settings_are_filtered(self):
634 model = VcsSettingsModel()
635 model = VcsSettingsModel()
635 repo_settings = [
636 repo_settings = [
636 UiSetting('extensions', 'largefiles', '', True),
637 UiSetting('extensions', 'largefiles', '', True),
637 UiSetting('phases', 'publish', 'True', True),
638 UiSetting('phases', 'publish', 'True', True),
638 UiSetting('hooks', 'changegroup.repo_size', 'hook', True),
639 UiSetting('hooks', 'changegroup.repo_size', 'hook', True),
639 UiSetting('hooks', 'changegroup.push_logger', 'hook', True),
640 UiSetting('hooks', 'changegroup.push_logger', 'hook', True),
640 UiSetting('hooks', 'outgoing.pull_logger', 'hook', True),
641 UiSetting('hooks', 'outgoing.pull_logger', 'hook', True),
641 UiSetting(
642 UiSetting(
642 'vcs_svn_branch', '84223c972204fa545ca1b22dac7bef5b68d7442d',
643 'vcs_svn_branch', '84223c972204fa545ca1b22dac7bef5b68d7442d',
643 'test_branch', True),
644 'test_branch', True),
644 UiSetting(
645 UiSetting(
645 'vcs_svn_tag', '84229c972204fa545ca1b22dac7bef5b68d7442d',
646 'vcs_svn_tag', '84229c972204fa545ca1b22dac7bef5b68d7442d',
646 'test_tag', True),
647 'test_tag', True),
647 ]
648 ]
648 non_repo_settings = [
649 non_repo_settings = [
649 UiSetting('test', 'outgoing.pull_logger', 'hook', True),
650 UiSetting('test', 'outgoing.pull_logger', 'hook', True),
650 UiSetting('hooks', 'test2', 'hook', True),
651 UiSetting('hooks', 'test2', 'hook', True),
651 UiSetting(
652 UiSetting(
652 'vcs_svn_repo', '84229c972204fa545ca1b22dac7bef5b68d7442d',
653 'vcs_svn_repo', '84229c972204fa545ca1b22dac7bef5b68d7442d',
653 'test_tag', True),
654 'test_tag', True),
654 ]
655 ]
655 settings = repo_settings + non_repo_settings
656 settings = repo_settings + non_repo_settings
656 filtered_settings = model._filter_ui_settings(settings)
657 filtered_settings = model._filter_ui_settings(settings)
657 assert sorted(filtered_settings) == sorted(repo_settings)
658 assert sorted(filtered_settings) == sorted(repo_settings)
658
659
659
660
660 class TestFilterGeneralSettings(object):
661 class TestFilterGeneralSettings(object):
661 def test_settings_are_filtered(self):
662 def test_settings_are_filtered(self):
662 model = VcsSettingsModel()
663 model = VcsSettingsModel()
663 settings = {
664 settings = {
664 'rhodecode_abcde': 'value1',
665 'rhodecode_abcde': 'value1',
665 'rhodecode_vwxyz': 'value2',
666 'rhodecode_vwxyz': 'value2',
666 }
667 }
667 general_settings = {
668 general_settings = {
668 'rhodecode_{}'.format(key): 'value'
669 'rhodecode_{}'.format(key): 'value'
669 for key in VcsSettingsModel.GENERAL_SETTINGS
670 for key in VcsSettingsModel.GENERAL_SETTINGS
670 }
671 }
671 settings.update(general_settings)
672 settings.update(general_settings)
672
673
673 filtered_settings = model._filter_general_settings(general_settings)
674 filtered_settings = model._filter_general_settings(general_settings)
674 assert sorted(filtered_settings) == sorted(general_settings)
675 assert sorted(filtered_settings) == sorted(general_settings)
675
676
676
677
677 class TestGetRepoUiSettings(object):
678 class TestGetRepoUiSettings(object):
678 def test_global_uis_are_returned_when_no_repo_uis_found(
679 def test_global_uis_are_returned_when_no_repo_uis_found(
679 self, repo_stub):
680 self, repo_stub):
680 model = VcsSettingsModel(repo=repo_stub.repo_name)
681 model = VcsSettingsModel(repo=repo_stub.repo_name)
681 result = model.get_repo_ui_settings()
682 result = model.get_repo_ui_settings()
682 svn_sections = (
683 svn_sections = (
683 VcsSettingsModel.SVN_TAG_SECTION,
684 VcsSettingsModel.SVN_TAG_SECTION,
684 VcsSettingsModel.SVN_BRANCH_SECTION)
685 VcsSettingsModel.SVN_BRANCH_SECTION)
685 expected_result = [
686 expected_result = [
686 s for s in model.global_settings.get_ui()
687 s for s in model.global_settings.get_ui()
687 if s.section not in svn_sections]
688 if s.section not in svn_sections]
688 assert sorted(result) == sorted(expected_result)
689 assert sorted(result) == sorted(expected_result)
689
690
690 def test_repo_uis_are_overriding_global_uis(
691 def test_repo_uis_are_overriding_global_uis(
691 self, repo_stub, settings_util):
692 self, repo_stub, settings_util):
692 for section, key in VcsSettingsModel.HOOKS_SETTINGS:
693 for section, key in VcsSettingsModel.HOOKS_SETTINGS:
693 settings_util.create_repo_rhodecode_ui(
694 settings_util.create_repo_rhodecode_ui(
694 repo_stub, section, 'repo', key=key, active=False)
695 repo_stub, section, 'repo', key=key, active=False)
695 model = VcsSettingsModel(repo=repo_stub.repo_name)
696 model = VcsSettingsModel(repo=repo_stub.repo_name)
696 result = model.get_repo_ui_settings()
697 result = model.get_repo_ui_settings()
697 for setting in result:
698 for setting in result:
698 locator = (setting.section, setting.key)
699 locator = (setting.section, setting.key)
699 if locator in VcsSettingsModel.HOOKS_SETTINGS:
700 if locator in VcsSettingsModel.HOOKS_SETTINGS:
700 assert setting.value == 'repo'
701 assert setting.value == 'repo'
701
702
702 assert setting.active is False
703 assert setting.active is False
703
704
704 def test_global_svn_patterns_are_not_in_list(
705 def test_global_svn_patterns_are_not_in_list(
705 self, repo_stub, settings_util):
706 self, repo_stub, settings_util):
706 svn_sections = (
707 svn_sections = (
707 VcsSettingsModel.SVN_TAG_SECTION,
708 VcsSettingsModel.SVN_TAG_SECTION,
708 VcsSettingsModel.SVN_BRANCH_SECTION)
709 VcsSettingsModel.SVN_BRANCH_SECTION)
709 for section in svn_sections:
710 for section in svn_sections:
710 settings_util.create_rhodecode_ui(
711 settings_util.create_rhodecode_ui(
711 section, 'repo', key='deadbeef' + section, active=False)
712 section, 'repo', key='deadbeef' + section, active=False)
712 model = VcsSettingsModel(repo=repo_stub.repo_name)
713 model = VcsSettingsModel(repo=repo_stub.repo_name)
713 result = model.get_repo_ui_settings()
714 result = model.get_repo_ui_settings()
714 for setting in result:
715 for setting in result:
715 assert setting.section not in svn_sections
716 assert setting.section not in svn_sections
716
717
717 def test_repo_uis_filtered_by_section_are_returned(
718 def test_repo_uis_filtered_by_section_are_returned(
718 self, repo_stub, settings_util):
719 self, repo_stub, settings_util):
719 for section, key in VcsSettingsModel.HOOKS_SETTINGS:
720 for section, key in VcsSettingsModel.HOOKS_SETTINGS:
720 settings_util.create_repo_rhodecode_ui(
721 settings_util.create_repo_rhodecode_ui(
721 repo_stub, section, 'repo', key=key, active=False)
722 repo_stub, section, 'repo', key=key, active=False)
722 model = VcsSettingsModel(repo=repo_stub.repo_name)
723 model = VcsSettingsModel(repo=repo_stub.repo_name)
723 section, key = VcsSettingsModel.HOOKS_SETTINGS[0]
724 section, key = VcsSettingsModel.HOOKS_SETTINGS[0]
724 result = model.get_repo_ui_settings(section=section)
725 result = model.get_repo_ui_settings(section=section)
725 for setting in result:
726 for setting in result:
726 assert setting.section == section
727 assert setting.section == section
727
728
728 def test_repo_uis_filtered_by_key_are_returned(
729 def test_repo_uis_filtered_by_key_are_returned(
729 self, repo_stub, settings_util):
730 self, repo_stub, settings_util):
730 for section, key in VcsSettingsModel.HOOKS_SETTINGS:
731 for section, key in VcsSettingsModel.HOOKS_SETTINGS:
731 settings_util.create_repo_rhodecode_ui(
732 settings_util.create_repo_rhodecode_ui(
732 repo_stub, section, 'repo', key=key, active=False)
733 repo_stub, section, 'repo', key=key, active=False)
733 model = VcsSettingsModel(repo=repo_stub.repo_name)
734 model = VcsSettingsModel(repo=repo_stub.repo_name)
734 section, key = VcsSettingsModel.HOOKS_SETTINGS[0]
735 section, key = VcsSettingsModel.HOOKS_SETTINGS[0]
735 result = model.get_repo_ui_settings(key=key)
736 result = model.get_repo_ui_settings(key=key)
736 for setting in result:
737 for setting in result:
737 assert setting.key == key
738 assert setting.key == key
738
739
739 def test_raises_exception_when_repository_is_not_specified(self):
740 def test_raises_exception_when_repository_is_not_specified(self):
740 model = VcsSettingsModel()
741 model = VcsSettingsModel()
741 with pytest.raises(Exception) as exc_info:
742 with pytest.raises(Exception) as exc_info:
742 model.get_repo_ui_settings()
743 model.get_repo_ui_settings()
743 assert exc_info.value.message == 'Repository is not specified'
744 assert exc_info.value.message == 'Repository is not specified'
744
745
745
746
746 class TestGetRepoGeneralSettings(object):
747 class TestGetRepoGeneralSettings(object):
747 def test_global_settings_are_returned_when_no_repo_settings_found(
748 def test_global_settings_are_returned_when_no_repo_settings_found(
748 self, repo_stub):
749 self, repo_stub):
749 model = VcsSettingsModel(repo=repo_stub.repo_name)
750 model = VcsSettingsModel(repo=repo_stub.repo_name)
750 result = model.get_repo_general_settings()
751 result = model.get_repo_general_settings()
751 expected_result = model.global_settings.get_all_settings()
752 expected_result = model.global_settings.get_all_settings()
752 assert sorted(result) == sorted(expected_result)
753 assert sorted(result) == sorted(expected_result)
753
754
754 def test_repo_uis_are_overriding_global_uis(
755 def test_repo_uis_are_overriding_global_uis(
755 self, repo_stub, settings_util):
756 self, repo_stub, settings_util):
756 for key in VcsSettingsModel.GENERAL_SETTINGS:
757 for key in VcsSettingsModel.GENERAL_SETTINGS:
757 settings_util.create_repo_rhodecode_setting(
758 settings_util.create_repo_rhodecode_setting(
758 repo_stub, key, 'abcde', type_='unicode')
759 repo_stub, key, 'abcde', type_='unicode')
759 model = VcsSettingsModel(repo=repo_stub.repo_name)
760 model = VcsSettingsModel(repo=repo_stub.repo_name)
760 result = model.get_repo_ui_settings()
761 result = model.get_repo_ui_settings()
761 for key in result:
762 for key in result:
762 if key in VcsSettingsModel.GENERAL_SETTINGS:
763 if key in VcsSettingsModel.GENERAL_SETTINGS:
763 assert result[key] == 'abcde'
764 assert result[key] == 'abcde'
764
765
765 def test_raises_exception_when_repository_is_not_specified(self):
766 def test_raises_exception_when_repository_is_not_specified(self):
766 model = VcsSettingsModel()
767 model = VcsSettingsModel()
767 with pytest.raises(Exception) as exc_info:
768 with pytest.raises(Exception) as exc_info:
768 model.get_repo_general_settings()
769 model.get_repo_general_settings()
769 assert exc_info.value.message == 'Repository is not specified'
770 assert exc_info.value.message == 'Repository is not specified'
770
771
771
772
772 class TestGetGlobalGeneralSettings(object):
773 class TestGetGlobalGeneralSettings(object):
773 def test_global_settings_are_returned(self, repo_stub):
774 def test_global_settings_are_returned(self, repo_stub):
774 model = VcsSettingsModel()
775 model = VcsSettingsModel()
775 result = model.get_global_general_settings()
776 result = model.get_global_general_settings()
776 expected_result = model.global_settings.get_all_settings()
777 expected_result = model.global_settings.get_all_settings()
777 assert sorted(result) == sorted(expected_result)
778 assert sorted(result) == sorted(expected_result)
778
779
779 def test_repo_uis_are_not_overriding_global_uis(
780 def test_repo_uis_are_not_overriding_global_uis(
780 self, repo_stub, settings_util):
781 self, repo_stub, settings_util):
781 for key in VcsSettingsModel.GENERAL_SETTINGS:
782 for key in VcsSettingsModel.GENERAL_SETTINGS:
782 settings_util.create_repo_rhodecode_setting(
783 settings_util.create_repo_rhodecode_setting(
783 repo_stub, key, 'abcde', type_='unicode')
784 repo_stub, key, 'abcde', type_='unicode')
784 model = VcsSettingsModel(repo=repo_stub.repo_name)
785 model = VcsSettingsModel(repo=repo_stub.repo_name)
785 result = model.get_global_general_settings()
786 result = model.get_global_general_settings()
786 expected_result = model.global_settings.get_all_settings()
787 expected_result = model.global_settings.get_all_settings()
787 assert sorted(result) == sorted(expected_result)
788 assert sorted(result) == sorted(expected_result)
788
789
789
790
790 class TestGetGlobalUiSettings(object):
791 class TestGetGlobalUiSettings(object):
791 def test_global_uis_are_returned(self, repo_stub):
792 def test_global_uis_are_returned(self, repo_stub):
792 model = VcsSettingsModel()
793 model = VcsSettingsModel()
793 result = model.get_global_ui_settings()
794 result = model.get_global_ui_settings()
794 expected_result = model.global_settings.get_ui()
795 expected_result = model.global_settings.get_ui()
795 assert sorted(result) == sorted(expected_result)
796 assert sorted(result) == sorted(expected_result)
796
797
797 def test_repo_uis_are_not_overriding_global_uis(
798 def test_repo_uis_are_not_overriding_global_uis(
798 self, repo_stub, settings_util):
799 self, repo_stub, settings_util):
799 for section, key in VcsSettingsModel.HOOKS_SETTINGS:
800 for section, key in VcsSettingsModel.HOOKS_SETTINGS:
800 settings_util.create_repo_rhodecode_ui(
801 settings_util.create_repo_rhodecode_ui(
801 repo_stub, section, 'repo', key=key, active=False)
802 repo_stub, section, 'repo', key=key, active=False)
802 model = VcsSettingsModel(repo=repo_stub.repo_name)
803 model = VcsSettingsModel(repo=repo_stub.repo_name)
803 result = model.get_global_ui_settings()
804 result = model.get_global_ui_settings()
804 expected_result = model.global_settings.get_ui()
805 expected_result = model.global_settings.get_ui()
805 assert sorted(result) == sorted(expected_result)
806 assert sorted(result) == sorted(expected_result)
806
807
807 def test_ui_settings_filtered_by_section(
808 def test_ui_settings_filtered_by_section(
808 self, repo_stub, settings_util):
809 self, repo_stub, settings_util):
809 model = VcsSettingsModel(repo=repo_stub.repo_name)
810 model = VcsSettingsModel(repo=repo_stub.repo_name)
810 section, key = VcsSettingsModel.HOOKS_SETTINGS[0]
811 section, key = VcsSettingsModel.HOOKS_SETTINGS[0]
811 result = model.get_global_ui_settings(section=section)
812 result = model.get_global_ui_settings(section=section)
812 expected_result = model.global_settings.get_ui(section=section)
813 expected_result = model.global_settings.get_ui(section=section)
813 assert sorted(result) == sorted(expected_result)
814 assert sorted(result) == sorted(expected_result)
814
815
815 def test_ui_settings_filtered_by_key(
816 def test_ui_settings_filtered_by_key(
816 self, repo_stub, settings_util):
817 self, repo_stub, settings_util):
817 model = VcsSettingsModel(repo=repo_stub.repo_name)
818 model = VcsSettingsModel(repo=repo_stub.repo_name)
818 section, key = VcsSettingsModel.HOOKS_SETTINGS[0]
819 section, key = VcsSettingsModel.HOOKS_SETTINGS[0]
819 result = model.get_global_ui_settings(key=key)
820 result = model.get_global_ui_settings(key=key)
820 expected_result = model.global_settings.get_ui(key=key)
821 expected_result = model.global_settings.get_ui(key=key)
821 assert sorted(result) == sorted(expected_result)
822 assert sorted(result) == sorted(expected_result)
822
823
823
824
824 class TestGetGeneralSettings(object):
825 class TestGetGeneralSettings(object):
825 def test_global_settings_are_returned_when_inherited_is_true(
826 def test_global_settings_are_returned_when_inherited_is_true(
826 self, repo_stub, settings_util):
827 self, repo_stub, settings_util):
827 model = VcsSettingsModel(repo=repo_stub.repo_name)
828 model = VcsSettingsModel(repo=repo_stub.repo_name)
828 model.inherit_global_settings = True
829 model.inherit_global_settings = True
829 for key in VcsSettingsModel.GENERAL_SETTINGS:
830 for key in VcsSettingsModel.GENERAL_SETTINGS:
830 settings_util.create_repo_rhodecode_setting(
831 settings_util.create_repo_rhodecode_setting(
831 repo_stub, key, 'abcde', type_='unicode')
832 repo_stub, key, 'abcde', type_='unicode')
832 result = model.get_general_settings()
833 result = model.get_general_settings()
833 expected_result = model.get_global_general_settings()
834 expected_result = model.get_global_general_settings()
834 assert sorted(result) == sorted(expected_result)
835 assert sorted(result) == sorted(expected_result)
835
836
836 def test_repo_settings_are_returned_when_inherited_is_false(
837 def test_repo_settings_are_returned_when_inherited_is_false(
837 self, repo_stub, settings_util):
838 self, repo_stub, settings_util):
838 model = VcsSettingsModel(repo=repo_stub.repo_name)
839 model = VcsSettingsModel(repo=repo_stub.repo_name)
839 model.inherit_global_settings = False
840 model.inherit_global_settings = False
840 for key in VcsSettingsModel.GENERAL_SETTINGS:
841 for key in VcsSettingsModel.GENERAL_SETTINGS:
841 settings_util.create_repo_rhodecode_setting(
842 settings_util.create_repo_rhodecode_setting(
842 repo_stub, key, 'abcde', type_='unicode')
843 repo_stub, key, 'abcde', type_='unicode')
843 result = model.get_general_settings()
844 result = model.get_general_settings()
844 expected_result = model.get_repo_general_settings()
845 expected_result = model.get_repo_general_settings()
845 assert sorted(result) == sorted(expected_result)
846 assert sorted(result) == sorted(expected_result)
846
847
847 def test_global_settings_are_returned_when_no_repository_specified(self):
848 def test_global_settings_are_returned_when_no_repository_specified(self):
848 model = VcsSettingsModel()
849 model = VcsSettingsModel()
849 result = model.get_general_settings()
850 result = model.get_general_settings()
850 expected_result = model.get_global_general_settings()
851 expected_result = model.get_global_general_settings()
851 assert sorted(result) == sorted(expected_result)
852 assert sorted(result) == sorted(expected_result)
852
853
853
854
854 class TestGetUiSettings(object):
855 class TestGetUiSettings(object):
855 def test_global_settings_are_returned_when_inherited_is_true(
856 def test_global_settings_are_returned_when_inherited_is_true(
856 self, repo_stub, settings_util):
857 self, repo_stub, settings_util):
857 model = VcsSettingsModel(repo=repo_stub.repo_name)
858 model = VcsSettingsModel(repo=repo_stub.repo_name)
858 model.inherit_global_settings = True
859 model.inherit_global_settings = True
859 for section, key in VcsSettingsModel.HOOKS_SETTINGS:
860 for section, key in VcsSettingsModel.HOOKS_SETTINGS:
860 settings_util.create_repo_rhodecode_ui(
861 settings_util.create_repo_rhodecode_ui(
861 repo_stub, section, 'repo', key=key, active=True)
862 repo_stub, section, 'repo', key=key, active=True)
862 result = model.get_ui_settings()
863 result = model.get_ui_settings()
863 expected_result = model.get_global_ui_settings()
864 expected_result = model.get_global_ui_settings()
864 assert sorted(result) == sorted(expected_result)
865 assert sorted(result) == sorted(expected_result)
865
866
866 def test_repo_settings_are_returned_when_inherited_is_false(
867 def test_repo_settings_are_returned_when_inherited_is_false(
867 self, repo_stub, settings_util):
868 self, repo_stub, settings_util):
868 model = VcsSettingsModel(repo=repo_stub.repo_name)
869 model = VcsSettingsModel(repo=repo_stub.repo_name)
869 model.inherit_global_settings = False
870 model.inherit_global_settings = False
870 for section, key in VcsSettingsModel.HOOKS_SETTINGS:
871 for section, key in VcsSettingsModel.HOOKS_SETTINGS:
871 settings_util.create_repo_rhodecode_ui(
872 settings_util.create_repo_rhodecode_ui(
872 repo_stub, section, 'repo', key=key, active=True)
873 repo_stub, section, 'repo', key=key, active=True)
873 result = model.get_ui_settings()
874 result = model.get_ui_settings()
874 expected_result = model.get_repo_ui_settings()
875 expected_result = model.get_repo_ui_settings()
875 assert sorted(result) == sorted(expected_result)
876 assert sorted(result) == sorted(expected_result)
876
877
877 def test_repo_settings_filtered_by_section_and_key(self, repo_stub):
878 def test_repo_settings_filtered_by_section_and_key(self, repo_stub):
878 model = VcsSettingsModel(repo=repo_stub.repo_name)
879 model = VcsSettingsModel(repo=repo_stub.repo_name)
879 model.inherit_global_settings = False
880 model.inherit_global_settings = False
880 args = ('section', 'key')
881 args = ('section', 'key')
881 with mock.patch.object(model, 'get_repo_ui_settings') as settings_mock:
882 with mock.patch.object(model, 'get_repo_ui_settings') as settings_mock:
882 model.get_ui_settings(*args)
883 model.get_ui_settings(*args)
883 settings_mock.assert_called_once_with(*args)
884 settings_mock.assert_called_once_with(*args)
884
885
885 def test_global_settings_filtered_by_section_and_key(self):
886 def test_global_settings_filtered_by_section_and_key(self):
886 model = VcsSettingsModel()
887 model = VcsSettingsModel()
887 args = ('section', 'key')
888 args = ('section', 'key')
888 with mock.patch.object(model, 'get_global_ui_settings') as (
889 with mock.patch.object(model, 'get_global_ui_settings') as (
889 settings_mock):
890 settings_mock):
890 model.get_ui_settings(*args)
891 model.get_ui_settings(*args)
891 settings_mock.assert_called_once_with(*args)
892 settings_mock.assert_called_once_with(*args)
892
893
893 def test_global_settings_are_returned_when_no_repository_specified(self):
894 def test_global_settings_are_returned_when_no_repository_specified(self):
894 model = VcsSettingsModel()
895 model = VcsSettingsModel()
895 result = model.get_ui_settings()
896 result = model.get_ui_settings()
896 expected_result = model.get_global_ui_settings()
897 expected_result = model.get_global_ui_settings()
897 assert sorted(result) == sorted(expected_result)
898 assert sorted(result) == sorted(expected_result)
898
899
899
900
900 class TestGetSvnPatterns(object):
901 class TestGetSvnPatterns(object):
901 def test_repo_settings_filtered_by_section_and_key(self, repo_stub):
902 def test_repo_settings_filtered_by_section_and_key(self, repo_stub):
902 model = VcsSettingsModel(repo=repo_stub.repo_name)
903 model = VcsSettingsModel(repo=repo_stub.repo_name)
903 args = ('section', )
904 args = ('section', )
904 with mock.patch.object(model, 'get_repo_ui_settings') as settings_mock:
905 with mock.patch.object(model, 'get_repo_ui_settings') as settings_mock:
905 model.get_svn_patterns(*args)
906 model.get_svn_patterns(*args)
906 settings_mock.assert_called_once_with(*args)
907 settings_mock.assert_called_once_with(*args)
907
908
908 def test_global_settings_filtered_by_section_and_key(self):
909 def test_global_settings_filtered_by_section_and_key(self):
909 model = VcsSettingsModel()
910 model = VcsSettingsModel()
910 args = ('section', )
911 args = ('section', )
911 with mock.patch.object(model, 'get_global_ui_settings') as (
912 with mock.patch.object(model, 'get_global_ui_settings') as (
912 settings_mock):
913 settings_mock):
913 model.get_svn_patterns(*args)
914 model.get_svn_patterns(*args)
914 settings_mock.assert_called_once_with(*args)
915 settings_mock.assert_called_once_with(*args)
915
916
916
917
917 class TestGetReposLocation(object):
918 class TestGetReposLocation(object):
918 def test_returns_repos_location(self, repo_stub):
919 def test_returns_repos_location(self, repo_stub):
919 model = VcsSettingsModel()
920 model = VcsSettingsModel()
920
921
921 result_mock = mock.Mock()
922 result_mock = mock.Mock()
922 result_mock.ui_value = '/tmp'
923 result_mock.ui_value = '/tmp'
923
924
924 with mock.patch.object(model, 'global_settings') as settings_mock:
925 with mock.patch.object(model, 'global_settings') as settings_mock:
925 settings_mock.get_ui_by_key.return_value = result_mock
926 settings_mock.get_ui_by_key.return_value = result_mock
926 result = model.get_repos_location()
927 result = model.get_repos_location()
927
928
928 settings_mock.get_ui_by_key.assert_called_once_with('/')
929 settings_mock.get_ui_by_key.assert_called_once_with('/')
929 assert result == '/tmp'
930 assert result == '/tmp'
930
931
931
932
932 class TestCreateOrUpdateRepoSettings(object):
933 class TestCreateOrUpdateRepoSettings(object):
933 FORM_DATA = {
934 FORM_DATA = {
934 'inherit_global_settings': False,
935 'inherit_global_settings': False,
935 'hooks_changegroup_repo_size': False,
936 'hooks_changegroup_repo_size': False,
936 'hooks_changegroup_push_logger': False,
937 'hooks_changegroup_push_logger': False,
937 'hooks_outgoing_pull_logger': False,
938 'hooks_outgoing_pull_logger': False,
938 'extensions_largefiles': False,
939 'extensions_largefiles': False,
939 'phases_publish': 'false',
940 'phases_publish': 'false',
940 'rhodecode_pr_merge_enabled': False,
941 'rhodecode_pr_merge_enabled': False,
941 'rhodecode_use_outdated_comments': False,
942 'rhodecode_use_outdated_comments': False,
942 'new_svn_branch': '',
943 'new_svn_branch': '',
943 'new_svn_tag': ''
944 'new_svn_tag': ''
944 }
945 }
945
946
946 def test_get_raises_exception_when_repository_not_specified(self):
947 def test_get_raises_exception_when_repository_not_specified(self):
947 model = VcsSettingsModel()
948 model = VcsSettingsModel()
948 with pytest.raises(Exception) as exc_info:
949 with pytest.raises(Exception) as exc_info:
949 model.create_or_update_repo_settings(data=self.FORM_DATA)
950 model.create_or_update_repo_settings(data=self.FORM_DATA)
950 assert exc_info.value.message == 'Repository is not specified'
951 assert exc_info.value.message == 'Repository is not specified'
951
952
952 def test_only_svn_settings_are_updated_when_type_is_svn(self, backend_svn):
953 def test_only_svn_settings_are_updated_when_type_is_svn(self, backend_svn):
953 repo = backend_svn.create_repo()
954 repo = backend_svn.create_repo()
954 model = VcsSettingsModel(repo=repo)
955 model = VcsSettingsModel(repo=repo)
955 with self._patch_model(model) as mocks:
956 with self._patch_model(model) as mocks:
956 model.create_or_update_repo_settings(
957 model.create_or_update_repo_settings(
957 data=self.FORM_DATA, inherit_global_settings=False)
958 data=self.FORM_DATA, inherit_global_settings=False)
958 mocks['create_repo_svn_settings'].assert_called_once_with(
959 mocks['create_repo_svn_settings'].assert_called_once_with(
959 self.FORM_DATA)
960 self.FORM_DATA)
960 non_called_methods = (
961 non_called_methods = (
961 'create_or_update_repo_hook_settings',
962 'create_or_update_repo_hook_settings',
962 'create_or_update_repo_pr_settings',
963 'create_or_update_repo_pr_settings',
963 'create_or_update_repo_hg_settings')
964 'create_or_update_repo_hg_settings')
964 for method in non_called_methods:
965 for method in non_called_methods:
965 assert mocks[method].call_count == 0
966 assert mocks[method].call_count == 0
966
967
967 def test_non_svn_settings_are_updated_when_type_is_hg(self, backend_hg):
968 def test_non_svn_settings_are_updated_when_type_is_hg(self, backend_hg):
968 repo = backend_hg.create_repo()
969 repo = backend_hg.create_repo()
969 model = VcsSettingsModel(repo=repo)
970 model = VcsSettingsModel(repo=repo)
970 with self._patch_model(model) as mocks:
971 with self._patch_model(model) as mocks:
971 model.create_or_update_repo_settings(
972 model.create_or_update_repo_settings(
972 data=self.FORM_DATA, inherit_global_settings=False)
973 data=self.FORM_DATA, inherit_global_settings=False)
973
974
974 assert mocks['create_repo_svn_settings'].call_count == 0
975 assert mocks['create_repo_svn_settings'].call_count == 0
975 called_methods = (
976 called_methods = (
976 'create_or_update_repo_hook_settings',
977 'create_or_update_repo_hook_settings',
977 'create_or_update_repo_pr_settings',
978 'create_or_update_repo_pr_settings',
978 'create_or_update_repo_hg_settings')
979 'create_or_update_repo_hg_settings')
979 for method in called_methods:
980 for method in called_methods:
980 mocks[method].assert_called_once_with(self.FORM_DATA)
981 mocks[method].assert_called_once_with(self.FORM_DATA)
981
982
982 def test_non_svn_and_hg_settings_are_updated_when_type_is_git(
983 def test_non_svn_and_hg_settings_are_updated_when_type_is_git(
983 self, backend_git):
984 self, backend_git):
984 repo = backend_git.create_repo()
985 repo = backend_git.create_repo()
985 model = VcsSettingsModel(repo=repo)
986 model = VcsSettingsModel(repo=repo)
986 with self._patch_model(model) as mocks:
987 with self._patch_model(model) as mocks:
987 model.create_or_update_repo_settings(
988 model.create_or_update_repo_settings(
988 data=self.FORM_DATA, inherit_global_settings=False)
989 data=self.FORM_DATA, inherit_global_settings=False)
989
990
990 assert mocks['create_repo_svn_settings'].call_count == 0
991 assert mocks['create_repo_svn_settings'].call_count == 0
991 called_methods = (
992 called_methods = (
992 'create_or_update_repo_hook_settings',
993 'create_or_update_repo_hook_settings',
993 'create_or_update_repo_pr_settings')
994 'create_or_update_repo_pr_settings')
994 non_called_methods = (
995 non_called_methods = (
995 'create_repo_svn_settings',
996 'create_repo_svn_settings',
996 'create_or_update_repo_hg_settings'
997 'create_or_update_repo_hg_settings'
997 )
998 )
998 for method in called_methods:
999 for method in called_methods:
999 mocks[method].assert_called_once_with(self.FORM_DATA)
1000 mocks[method].assert_called_once_with(self.FORM_DATA)
1000 for method in non_called_methods:
1001 for method in non_called_methods:
1001 assert mocks[method].call_count == 0
1002 assert mocks[method].call_count == 0
1002
1003
1003 def test_no_methods_are_called_when_settings_are_inherited(
1004 def test_no_methods_are_called_when_settings_are_inherited(
1004 self, backend):
1005 self, backend):
1005 repo = backend.create_repo()
1006 repo = backend.create_repo()
1006 model = VcsSettingsModel(repo=repo)
1007 model = VcsSettingsModel(repo=repo)
1007 with self._patch_model(model) as mocks:
1008 with self._patch_model(model) as mocks:
1008 model.create_or_update_repo_settings(
1009 model.create_or_update_repo_settings(
1009 data=self.FORM_DATA, inherit_global_settings=True)
1010 data=self.FORM_DATA, inherit_global_settings=True)
1010 for method_name in mocks:
1011 for method_name in mocks:
1011 assert mocks[method_name].call_count == 0
1012 assert mocks[method_name].call_count == 0
1012
1013
1013 def test_cache_is_marked_for_invalidation(self, repo_stub):
1014 def test_cache_is_marked_for_invalidation(self, repo_stub):
1014 model = VcsSettingsModel(repo=repo_stub)
1015 model = VcsSettingsModel(repo=repo_stub)
1015 invalidation_patcher = mock.patch(
1016 invalidation_patcher = mock.patch(
1016 'rhodecode.controllers.admin.repos.ScmModel.mark_for_invalidation')
1017 'rhodecode.controllers.admin.repos.ScmModel.mark_for_invalidation')
1017 with invalidation_patcher as invalidation_mock:
1018 with invalidation_patcher as invalidation_mock:
1018 model.create_or_update_repo_settings(
1019 model.create_or_update_repo_settings(
1019 data=self.FORM_DATA, inherit_global_settings=True)
1020 data=self.FORM_DATA, inherit_global_settings=True)
1020 invalidation_mock.assert_called_once_with(
1021 invalidation_mock.assert_called_once_with(
1021 repo_stub.repo_name, delete=True)
1022 repo_stub.repo_name, delete=True)
1022
1023
1023 def test_inherit_flag_is_saved(self, repo_stub):
1024 def test_inherit_flag_is_saved(self, repo_stub):
1024 model = VcsSettingsModel(repo=repo_stub)
1025 model = VcsSettingsModel(repo=repo_stub)
1025 model.inherit_global_settings = True
1026 model.inherit_global_settings = True
1026 with self._patch_model(model):
1027 with self._patch_model(model):
1027 model.create_or_update_repo_settings(
1028 model.create_or_update_repo_settings(
1028 data=self.FORM_DATA, inherit_global_settings=False)
1029 data=self.FORM_DATA, inherit_global_settings=False)
1029 assert model.inherit_global_settings is False
1030 assert model.inherit_global_settings is False
1030
1031
1031 def _patch_model(self, model):
1032 def _patch_model(self, model):
1032 return mock.patch.multiple(
1033 return mock.patch.multiple(
1033 model,
1034 model,
1034 create_repo_svn_settings=mock.DEFAULT,
1035 create_repo_svn_settings=mock.DEFAULT,
1035 create_or_update_repo_hook_settings=mock.DEFAULT,
1036 create_or_update_repo_hook_settings=mock.DEFAULT,
1036 create_or_update_repo_pr_settings=mock.DEFAULT,
1037 create_or_update_repo_pr_settings=mock.DEFAULT,
1037 create_or_update_repo_hg_settings=mock.DEFAULT)
1038 create_or_update_repo_hg_settings=mock.DEFAULT)
General Comments 0
You need to be logged in to leave comments. Login now