Show More
@@ -1,308 +1,309 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 tempfile |
|
21 | import tempfile | |
22 |
|
22 | |||
23 | import mock |
|
23 | import mock | |
24 | import pytest |
|
24 | import pytest | |
25 |
|
25 | |||
26 | from rhodecode.lib.exceptions import AttachedForksError |
|
26 | from rhodecode.lib.exceptions import AttachedForksError | |
27 | from rhodecode.lib.utils import make_db_config |
|
27 | from rhodecode.lib.utils import make_db_config | |
28 | from rhodecode.model.db import Repository |
|
28 | from rhodecode.model.db import Repository | |
29 | from rhodecode.model.meta import Session |
|
29 | from rhodecode.model.meta import Session | |
30 | from rhodecode.model.repo import RepoModel |
|
30 | from rhodecode.model.repo import RepoModel | |
31 | from rhodecode.model.scm import ScmModel |
|
31 | from rhodecode.model.scm import ScmModel | |
32 | from rhodecode.lib.utils2 import safe_unicode |
|
32 | from rhodecode.lib.utils2 import safe_unicode | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | class TestRepoModel: |
|
35 | class TestRepoModel: | |
36 |
|
36 | |||
37 | def test_remove_repo(self, backend): |
|
37 | def test_remove_repo(self, backend): | |
38 | repo = backend.create_repo() |
|
38 | repo = backend.create_repo() | |
39 | Session().commit() |
|
39 | Session().commit() | |
40 | RepoModel().delete(repo=repo) |
|
40 | RepoModel().delete(repo=repo) | |
41 | Session().commit() |
|
41 | Session().commit() | |
42 |
|
42 | |||
43 | repos = ScmModel().repo_scan() |
|
43 | repos = ScmModel().repo_scan() | |
44 |
|
44 | |||
45 | assert Repository.get_by_repo_name(repo_name=backend.repo_name) is None |
|
45 | assert Repository.get_by_repo_name(repo_name=backend.repo_name) is None | |
46 | assert repo.repo_name not in repos |
|
46 | assert repo.repo_name not in repos | |
47 |
|
47 | |||
48 | def test_remove_repo_raises_exc_when_attached_forks(self, backend): |
|
48 | def test_remove_repo_raises_exc_when_attached_forks(self, backend): | |
49 | repo = backend.create_repo() |
|
49 | repo = backend.create_repo() | |
50 | Session().commit() |
|
50 | Session().commit() | |
51 | backend.create_fork() |
|
51 | backend.create_fork() | |
52 | Session().commit() |
|
52 | Session().commit() | |
53 |
|
53 | |||
54 | with pytest.raises(AttachedForksError): |
|
54 | with pytest.raises(AttachedForksError): | |
55 | RepoModel().delete(repo=repo) |
|
55 | RepoModel().delete(repo=repo) | |
56 |
|
56 | |||
57 | def test_remove_repo_delete_forks(self, backend): |
|
57 | def test_remove_repo_delete_forks(self, backend): | |
58 | repo = backend.create_repo() |
|
58 | repo = backend.create_repo() | |
59 | Session().commit() |
|
59 | Session().commit() | |
60 |
|
60 | |||
61 | fork = backend.create_fork() |
|
61 | fork = backend.create_fork() | |
62 | Session().commit() |
|
62 | Session().commit() | |
63 |
|
63 | |||
64 | fork_of_fork = backend.create_fork() |
|
64 | fork_of_fork = backend.create_fork() | |
65 | Session().commit() |
|
65 | Session().commit() | |
66 |
|
66 | |||
67 | RepoModel().delete(repo=repo, forks='delete') |
|
67 | RepoModel().delete(repo=repo, forks='delete') | |
68 | Session().commit() |
|
68 | Session().commit() | |
69 |
|
69 | |||
70 | assert Repository.get_by_repo_name(repo_name=repo.repo_name) is None |
|
70 | assert Repository.get_by_repo_name(repo_name=repo.repo_name) is None | |
71 | assert Repository.get_by_repo_name(repo_name=fork.repo_name) is None |
|
71 | assert Repository.get_by_repo_name(repo_name=fork.repo_name) is None | |
72 | assert ( |
|
72 | assert ( | |
73 | Repository.get_by_repo_name(repo_name=fork_of_fork.repo_name) |
|
73 | Repository.get_by_repo_name(repo_name=fork_of_fork.repo_name) | |
74 | is None) |
|
74 | is None) | |
75 |
|
75 | |||
76 | def test_remove_repo_detach_forks(self, backend): |
|
76 | def test_remove_repo_detach_forks(self, backend): | |
77 | repo = backend.create_repo() |
|
77 | repo = backend.create_repo() | |
78 | Session().commit() |
|
78 | Session().commit() | |
79 |
|
79 | |||
80 | fork = backend.create_fork() |
|
80 | fork = backend.create_fork() | |
81 | Session().commit() |
|
81 | Session().commit() | |
82 |
|
82 | |||
83 | fork_of_fork = backend.create_fork() |
|
83 | fork_of_fork = backend.create_fork() | |
84 | Session().commit() |
|
84 | Session().commit() | |
85 |
|
85 | |||
86 | RepoModel().delete(repo=repo, forks='detach') |
|
86 | RepoModel().delete(repo=repo, forks='detach') | |
87 | Session().commit() |
|
87 | Session().commit() | |
88 |
|
88 | |||
89 | assert Repository.get_by_repo_name(repo_name=repo.repo_name) is None |
|
89 | assert Repository.get_by_repo_name(repo_name=repo.repo_name) is None | |
90 | assert ( |
|
90 | assert ( | |
91 | Repository.get_by_repo_name(repo_name=fork.repo_name) is not None) |
|
91 | Repository.get_by_repo_name(repo_name=fork.repo_name) is not None) | |
92 | assert ( |
|
92 | assert ( | |
93 | Repository.get_by_repo_name(repo_name=fork_of_fork.repo_name) |
|
93 | Repository.get_by_repo_name(repo_name=fork_of_fork.repo_name) | |
94 | is not None) |
|
94 | is not None) | |
95 |
|
95 | |||
96 | @pytest.mark.parametrize("filename, expected", [ |
|
96 | @pytest.mark.parametrize("filename, expected", [ | |
97 | ("README", True), |
|
97 | ("README", True), | |
98 | ("README.rst", False), |
|
98 | ("README.rst", False), | |
99 | ]) |
|
99 | ]) | |
100 | def test_filenode_is_link(self, vcsbackend, filename, expected): |
|
100 | def test_filenode_is_link(self, vcsbackend, filename, expected): | |
101 | repo = vcsbackend.repo |
|
101 | repo = vcsbackend.repo | |
102 | assert repo.get_commit().is_link(filename) is expected |
|
102 | assert repo.get_commit().is_link(filename) is expected | |
103 |
|
103 | |||
104 | def test_get_commit(self, backend): |
|
104 | def test_get_commit(self, backend): | |
105 | backend.repo.get_commit() |
|
105 | backend.repo.get_commit() | |
106 |
|
106 | |||
107 | def test_get_changeset_is_deprecated(self, backend): |
|
107 | def test_get_changeset_is_deprecated(self, backend): | |
108 | repo = backend.repo |
|
108 | repo = backend.repo | |
109 | pytest.deprecated_call(repo.get_changeset) |
|
109 | pytest.deprecated_call(repo.get_changeset) | |
110 |
|
110 | |||
111 | def test_clone_url_encrypted_value(self, backend): |
|
111 | def test_clone_url_encrypted_value(self, backend): | |
112 | repo = backend.create_repo() |
|
112 | repo = backend.create_repo() | |
113 | Session().commit() |
|
113 | Session().commit() | |
114 |
|
114 | |||
115 | repo.clone_url = 'https://marcink:qweqwe@code.rhodecode.com' |
|
115 | repo.clone_url = 'https://marcink:qweqwe@code.rhodecode.com' | |
116 | Session().add(repo) |
|
116 | Session().add(repo) | |
117 | Session().commit() |
|
117 | Session().commit() | |
118 |
|
118 | |||
119 | assert repo.clone_url == 'https://marcink:qweqwe@code.rhodecode.com' |
|
119 | assert repo.clone_url == 'https://marcink:qweqwe@code.rhodecode.com' | |
120 |
|
120 | |||
121 | @pytest.mark.backends("git", "svn") |
|
121 | @pytest.mark.backends("git", "svn") | |
122 | def test_create_filesystem_repo_installs_hooks(self, tmpdir, backend): |
|
122 | def test_create_filesystem_repo_installs_hooks(self, tmpdir, backend): | |
123 | hook_methods = { |
|
123 | hook_methods = { | |
124 | 'git': 'install_git_hook', |
|
124 | 'git': 'install_git_hook', | |
125 | 'svn': 'install_svn_hooks' |
|
125 | 'svn': 'install_svn_hooks' | |
126 | } |
|
126 | } | |
127 | repo = backend.create_repo() |
|
127 | repo = backend.create_repo() | |
128 | repo_name = repo.repo_name |
|
128 | repo_name = repo.repo_name | |
129 | model = RepoModel() |
|
129 | model = RepoModel() | |
130 | repo_location = tempfile.mkdtemp() |
|
130 | repo_location = tempfile.mkdtemp() | |
131 | model.repos_path = repo_location |
|
131 | model.repos_path = repo_location | |
132 | method = hook_methods[backend.alias] |
|
132 | method = hook_methods[backend.alias] | |
133 | with mock.patch.object(ScmModel, method) as hooks_mock: |
|
133 | with mock.patch.object(ScmModel, method) as hooks_mock: | |
134 | model._create_filesystem_repo( |
|
134 | model._create_filesystem_repo( | |
135 | repo_name, backend.alias, repo_group='', clone_uri=None) |
|
135 | repo_name, backend.alias, repo_group='', clone_uri=None) | |
136 | assert hooks_mock.call_count == 1 |
|
136 | assert hooks_mock.call_count == 1 | |
137 | hook_args, hook_kwargs = hooks_mock.call_args |
|
137 | hook_args, hook_kwargs = hooks_mock.call_args | |
138 | assert hook_args[0].name == repo_name |
|
138 | assert hook_args[0].name == repo_name | |
139 |
|
139 | |||
140 | @pytest.mark.parametrize("use_global_config, repo_name_passed", [ |
|
140 | @pytest.mark.parametrize("use_global_config, repo_name_passed", [ | |
141 | (True, False), |
|
141 | (True, False), | |
142 | (False, True) |
|
142 | (False, True) | |
143 | ]) |
|
143 | ]) | |
144 | def test_per_repo_config_is_generated_during_filesystem_repo_creation( |
|
144 | def test_per_repo_config_is_generated_during_filesystem_repo_creation( | |
145 | self, tmpdir, backend, use_global_config, repo_name_passed): |
|
145 | self, tmpdir, backend, use_global_config, repo_name_passed): | |
146 | repo_name = 'test-{}-repo-{}'.format(backend.alias, use_global_config) |
|
146 | repo_name = 'test-{}-repo-{}'.format(backend.alias, use_global_config) | |
147 | config = make_db_config() |
|
147 | config = make_db_config() | |
148 | model = RepoModel() |
|
148 | model = RepoModel() | |
149 | with mock.patch('rhodecode.model.repo.make_db_config') as config_mock: |
|
149 | with mock.patch('rhodecode.model.repo.make_db_config') as config_mock: | |
150 | config_mock.return_value = config |
|
150 | config_mock.return_value = config | |
151 | model._create_filesystem_repo( |
|
151 | model._create_filesystem_repo( | |
152 | repo_name, backend.alias, repo_group='', clone_uri=None, |
|
152 | repo_name, backend.alias, repo_group='', clone_uri=None, | |
153 | use_global_config=use_global_config) |
|
153 | use_global_config=use_global_config) | |
154 | expected_repo_name = repo_name if repo_name_passed else None |
|
154 | expected_repo_name = repo_name if repo_name_passed else None | |
155 | expected_call = mock.call(clear_session=False, repo=expected_repo_name) |
|
155 | expected_call = mock.call(clear_session=False, repo=expected_repo_name) | |
156 | assert expected_call in config_mock.call_args_list |
|
156 | assert expected_call in config_mock.call_args_list | |
157 |
|
157 | |||
158 | def test_update_commit_cache_with_config(serf, backend): |
|
158 | def test_update_commit_cache_with_config(serf, backend): | |
159 | repo = backend.create_repo() |
|
159 | repo = backend.create_repo() | |
160 | with mock.patch('rhodecode.model.db.Repository.scm_instance') as scm: |
|
160 | with mock.patch('rhodecode.model.db.Repository.scm_instance') as scm: | |
161 | scm_instance = mock.Mock() |
|
161 | scm_instance = mock.Mock() | |
162 | scm_instance.get_commit.return_value = { |
|
162 | scm_instance.get_commit.return_value = { | |
163 | 'raw_id': 40*'0' |
|
163 | 'raw_id': 40*'0', | |
|
164 | 'revision': 1 | |||
164 | } |
|
165 | } | |
165 | scm.return_value = scm_instance |
|
166 | scm.return_value = scm_instance | |
166 | repo.update_commit_cache() |
|
167 | repo.update_commit_cache() | |
167 | scm.assert_called_with(cache=False, config=None) |
|
168 | scm.assert_called_with(cache=False, config=None) | |
168 | config = {'test': 'config'} |
|
169 | config = {'test': 'config'} | |
169 | repo.update_commit_cache(config=config) |
|
170 | repo.update_commit_cache(config=config) | |
170 | scm.assert_called_with( |
|
171 | scm.assert_called_with( | |
171 | cache=False, config=config) |
|
172 | cache=False, config=config) | |
172 |
|
173 | |||
173 |
|
174 | |||
174 | class TestGetUsers(object): |
|
175 | class TestGetUsers(object): | |
175 | def test_returns_active_users(self, backend, user_util): |
|
176 | def test_returns_active_users(self, backend, user_util): | |
176 | for i in range(4): |
|
177 | for i in range(4): | |
177 | is_active = i % 2 == 0 |
|
178 | is_active = i % 2 == 0 | |
178 | user_util.create_user(active=is_active, lastname='Fake user') |
|
179 | user_util.create_user(active=is_active, lastname='Fake user') | |
179 |
|
180 | |||
180 | with mock.patch('rhodecode.lib.helpers.gravatar_url'): |
|
181 | with mock.patch('rhodecode.lib.helpers.gravatar_url'): | |
181 | users = RepoModel().get_users() |
|
182 | users = RepoModel().get_users() | |
182 | fake_users = [u for u in users if u['last_name'] == 'Fake user'] |
|
183 | fake_users = [u for u in users if u['last_name'] == 'Fake user'] | |
183 | assert len(fake_users) == 2 |
|
184 | assert len(fake_users) == 2 | |
184 |
|
185 | |||
185 | expected_keys = ( |
|
186 | expected_keys = ( | |
186 | 'id', 'first_name', 'last_name', 'username', 'icon_link', |
|
187 | 'id', 'first_name', 'last_name', 'username', 'icon_link', | |
187 | 'value_display', 'value', 'value_type') |
|
188 | 'value_display', 'value', 'value_type') | |
188 | for user in users: |
|
189 | for user in users: | |
189 | assert user['value_type'] is 'user' |
|
190 | assert user['value_type'] is 'user' | |
190 | for key in expected_keys: |
|
191 | for key in expected_keys: | |
191 | assert key in user |
|
192 | assert key in user | |
192 |
|
193 | |||
193 | def test_returns_user_filtered_by_last_name(self, backend, user_util): |
|
194 | def test_returns_user_filtered_by_last_name(self, backend, user_util): | |
194 | keywords = ('aBc', u'ΓΌnicode') |
|
195 | keywords = ('aBc', u'ΓΌnicode') | |
195 | for keyword in keywords: |
|
196 | for keyword in keywords: | |
196 | for i in range(2): |
|
197 | for i in range(2): | |
197 | user_util.create_user( |
|
198 | user_util.create_user( | |
198 | active=True, lastname=u'Fake {} user'.format(keyword)) |
|
199 | active=True, lastname=u'Fake {} user'.format(keyword)) | |
199 |
|
200 | |||
200 | with mock.patch('rhodecode.lib.helpers.gravatar_url'): |
|
201 | with mock.patch('rhodecode.lib.helpers.gravatar_url'): | |
201 | keyword = keywords[1].lower() |
|
202 | keyword = keywords[1].lower() | |
202 | users = RepoModel().get_users(name_contains=keyword) |
|
203 | users = RepoModel().get_users(name_contains=keyword) | |
203 |
|
204 | |||
204 | fake_users = [u for u in users if u['last_name'].startswith('Fake')] |
|
205 | fake_users = [u for u in users if u['last_name'].startswith('Fake')] | |
205 | assert len(fake_users) == 2 |
|
206 | assert len(fake_users) == 2 | |
206 | for user in fake_users: |
|
207 | for user in fake_users: | |
207 | assert user['last_name'] == safe_unicode('Fake ΓΌnicode user') |
|
208 | assert user['last_name'] == safe_unicode('Fake ΓΌnicode user') | |
208 |
|
209 | |||
209 | def test_returns_user_filtered_by_first_name(self, backend, user_util): |
|
210 | def test_returns_user_filtered_by_first_name(self, backend, user_util): | |
210 | created_users = [] |
|
211 | created_users = [] | |
211 | keywords = ('aBc', u'ΓΌnicode') |
|
212 | keywords = ('aBc', u'ΓΌnicode') | |
212 | for keyword in keywords: |
|
213 | for keyword in keywords: | |
213 | for i in range(2): |
|
214 | for i in range(2): | |
214 | created_users.append(user_util.create_user( |
|
215 | created_users.append(user_util.create_user( | |
215 | active=True, lastname='Fake user', |
|
216 | active=True, lastname='Fake user', | |
216 | firstname=u'Fake {} user'.format(keyword))) |
|
217 | firstname=u'Fake {} user'.format(keyword))) | |
217 |
|
218 | |||
218 | keyword = keywords[1].lower() |
|
219 | keyword = keywords[1].lower() | |
219 | with mock.patch('rhodecode.lib.helpers.gravatar_url'): |
|
220 | with mock.patch('rhodecode.lib.helpers.gravatar_url'): | |
220 | users = RepoModel().get_users(name_contains=keyword) |
|
221 | users = RepoModel().get_users(name_contains=keyword) | |
221 |
|
222 | |||
222 | fake_users = [u for u in users if u['last_name'].startswith('Fake')] |
|
223 | fake_users = [u for u in users if u['last_name'].startswith('Fake')] | |
223 | assert len(fake_users) == 2 |
|
224 | assert len(fake_users) == 2 | |
224 | for user in fake_users: |
|
225 | for user in fake_users: | |
225 | assert user['first_name'] == safe_unicode('Fake ΓΌnicode user') |
|
226 | assert user['first_name'] == safe_unicode('Fake ΓΌnicode user') | |
226 |
|
227 | |||
227 | def test_returns_user_filtered_by_username(self, backend, user_util): |
|
228 | def test_returns_user_filtered_by_username(self, backend, user_util): | |
228 | created_users = [] |
|
229 | created_users = [] | |
229 | for i in range(5): |
|
230 | for i in range(5): | |
230 | created_users.append(user_util.create_user( |
|
231 | created_users.append(user_util.create_user( | |
231 | active=True, lastname='Fake user')) |
|
232 | active=True, lastname='Fake user')) | |
232 |
|
233 | |||
233 | user_filter = created_users[-1].username[-2:] |
|
234 | user_filter = created_users[-1].username[-2:] | |
234 | with mock.patch('rhodecode.lib.helpers.gravatar_url'): |
|
235 | with mock.patch('rhodecode.lib.helpers.gravatar_url'): | |
235 | users = RepoModel().get_users(name_contains=user_filter) |
|
236 | users = RepoModel().get_users(name_contains=user_filter) | |
236 |
|
237 | |||
237 | fake_users = [u for u in users if u['last_name'].startswith('Fake')] |
|
238 | fake_users = [u for u in users if u['last_name'].startswith('Fake')] | |
238 | assert len(fake_users) == 1 |
|
239 | assert len(fake_users) == 1 | |
239 | assert fake_users[0]['username'] == created_users[-1].username |
|
240 | assert fake_users[0]['username'] == created_users[-1].username | |
240 |
|
241 | |||
241 | def test_returns_limited_user_list(self, backend, user_util): |
|
242 | def test_returns_limited_user_list(self, backend, user_util): | |
242 | created_users = [] |
|
243 | created_users = [] | |
243 | for i in range(5): |
|
244 | for i in range(5): | |
244 | created_users.append(user_util.create_user( |
|
245 | created_users.append(user_util.create_user( | |
245 | active=True, lastname='Fake user')) |
|
246 | active=True, lastname='Fake user')) | |
246 |
|
247 | |||
247 | with mock.patch('rhodecode.lib.helpers.gravatar_url'): |
|
248 | with mock.patch('rhodecode.lib.helpers.gravatar_url'): | |
248 | users = RepoModel().get_users(name_contains='Fake', limit=3) |
|
249 | users = RepoModel().get_users(name_contains='Fake', limit=3) | |
249 |
|
250 | |||
250 | fake_users = [u for u in users if u['last_name'].startswith('Fake')] |
|
251 | fake_users = [u for u in users if u['last_name'].startswith('Fake')] | |
251 | assert len(fake_users) == 3 |
|
252 | assert len(fake_users) == 3 | |
252 |
|
253 | |||
253 |
|
254 | |||
254 | class TestGetUserGroups(object): |
|
255 | class TestGetUserGroups(object): | |
255 | def test_returns_filtered_list(self, backend, user_util): |
|
256 | def test_returns_filtered_list(self, backend, user_util): | |
256 | created_groups = [] |
|
257 | created_groups = [] | |
257 | for i in range(4): |
|
258 | for i in range(4): | |
258 | created_groups.append( |
|
259 | created_groups.append( | |
259 | user_util.create_user_group(users_group_active=True)) |
|
260 | user_util.create_user_group(users_group_active=True)) | |
260 |
|
261 | |||
261 | group_filter = created_groups[-1].users_group_name[-2:] |
|
262 | group_filter = created_groups[-1].users_group_name[-2:] | |
262 | with self._patch_user_group_list(): |
|
263 | with self._patch_user_group_list(): | |
263 | groups = RepoModel().get_user_groups(group_filter) |
|
264 | groups = RepoModel().get_user_groups(group_filter) | |
264 |
|
265 | |||
265 | fake_groups = [ |
|
266 | fake_groups = [ | |
266 | u for u in groups if u['value'].startswith('test_returns')] |
|
267 | u for u in groups if u['value'].startswith('test_returns')] | |
267 | assert len(fake_groups) == 1 |
|
268 | assert len(fake_groups) == 1 | |
268 | assert fake_groups[0]['value'] == created_groups[-1].users_group_name |
|
269 | assert fake_groups[0]['value'] == created_groups[-1].users_group_name | |
269 | assert fake_groups[0]['value_display'].startswith( |
|
270 | assert fake_groups[0]['value_display'].startswith( | |
270 | 'Group: test_returns') |
|
271 | 'Group: test_returns') | |
271 |
|
272 | |||
272 | def test_returns_limited_list(self, backend, user_util): |
|
273 | def test_returns_limited_list(self, backend, user_util): | |
273 | created_groups = [] |
|
274 | created_groups = [] | |
274 | for i in range(3): |
|
275 | for i in range(3): | |
275 | created_groups.append( |
|
276 | created_groups.append( | |
276 | user_util.create_user_group(users_group_active=True)) |
|
277 | user_util.create_user_group(users_group_active=True)) | |
277 |
|
278 | |||
278 | with self._patch_user_group_list(): |
|
279 | with self._patch_user_group_list(): | |
279 | groups = RepoModel().get_user_groups('test_returns') |
|
280 | groups = RepoModel().get_user_groups('test_returns') | |
280 |
|
281 | |||
281 | fake_groups = [ |
|
282 | fake_groups = [ | |
282 | u for u in groups if u['value'].startswith('test_returns')] |
|
283 | u for u in groups if u['value'].startswith('test_returns')] | |
283 | assert len(fake_groups) == 3 |
|
284 | assert len(fake_groups) == 3 | |
284 |
|
285 | |||
285 | def test_returns_active_user_groups(self, backend, user_util): |
|
286 | def test_returns_active_user_groups(self, backend, user_util): | |
286 | for i in range(4): |
|
287 | for i in range(4): | |
287 | is_active = i % 2 == 0 |
|
288 | is_active = i % 2 == 0 | |
288 | user_util.create_user_group(users_group_active=is_active) |
|
289 | user_util.create_user_group(users_group_active=is_active) | |
289 |
|
290 | |||
290 | with self._patch_user_group_list(): |
|
291 | with self._patch_user_group_list(): | |
291 | groups = RepoModel().get_user_groups() |
|
292 | groups = RepoModel().get_user_groups() | |
292 | expected = ('id', 'icon_link', 'value_display', 'value', 'value_type') |
|
293 | expected = ('id', 'icon_link', 'value_display', 'value', 'value_type') | |
293 | for group in groups: |
|
294 | for group in groups: | |
294 | assert group['value_type'] is 'user_group' |
|
295 | assert group['value_type'] is 'user_group' | |
295 | for key in expected: |
|
296 | for key in expected: | |
296 | assert key in group |
|
297 | assert key in group | |
297 |
|
298 | |||
298 | fake_groups = [ |
|
299 | fake_groups = [ | |
299 | u for u in groups if u['value'].startswith('test_returns')] |
|
300 | u for u in groups if u['value'].startswith('test_returns')] | |
300 | assert len(fake_groups) == 2 |
|
301 | assert len(fake_groups) == 2 | |
301 | for user in fake_groups: |
|
302 | for user in fake_groups: | |
302 | assert user['value_display'].startswith('Group: test_returns') |
|
303 | assert user['value_display'].startswith('Group: test_returns') | |
303 |
|
304 | |||
304 | def _patch_user_group_list(self): |
|
305 | def _patch_user_group_list(self): | |
305 | def side_effect(group_list, perm_set): |
|
306 | def side_effect(group_list, perm_set): | |
306 | return group_list |
|
307 | return group_list | |
307 | return mock.patch( |
|
308 | return mock.patch( | |
308 | 'rhodecode.model.repo.UserGroupList', side_effect=side_effect) |
|
309 | 'rhodecode.model.repo.UserGroupList', side_effect=side_effect) |
General Comments 0
You need to be logged in to leave comments.
Login now